diff --git a/Youtube_To_Google_Drive.ipynb b/Youtube_To_Google_Drive.ipynb index 07bcccd..4f39144 100644 --- a/Youtube_To_Google_Drive.ipynb +++ b/Youtube_To_Google_Drive.ipynb @@ -1,26 +1,11 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [], - "authorship_tag": "ABX9TyNTtIBj43BGvfXJiHDIOgaW", - "include_colab_link": true - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "view-in-github", - "colab_type": "text" + "colab_type": "text", + "id": "view-in-github" }, "source": [ "\"Open" @@ -39,6 +24,11 @@ }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "s6L01xuGIhMn" + }, + "outputs": [], "source": [ "from tqdm import tqdm\n", "import requests\n", @@ -48,6 +38,7 @@ "import os.path\n", "import sys\n", "import pytube\n", + "from textwrap import dedent\n", "\n", "drive.mount('/content/drive')\n", "\n", @@ -58,11 +49,43 @@ "if not os.path.exists(destination_folder):\n", " os.makedirs(destination_folder)\n", "\n", - "# Function to download YouTube video\n", + "# Function to download YouTube video with options\n", "def download_youtube_video(url, destination_folder):\n", " try:\n", " youtube = pytube.YouTube(url)\n", - " video = youtube.streams.first()\n", + "\n", + " # Collect available quality options\n", + " quality_options = []\n", + " for i, stream in enumerate(youtube.streams, start=1):\n", + " quality_options.append((i, stream.resolution, stream.mime_type))\n", + "\n", + " # Format quality options in a text box\n", + " quality_options_text = dedent('''\n", + " Available quality options:\n", + " -----------------------------------\n", + " | Option | Resolution | Format |\n", + " -----------------------------------''')\n", + " for option in quality_options:\n", + " option_text = f\"| {option[0]} | {option[1]} | {option[2]} |\\n\"\n", + " quality_options_text += option_text\n", + " quality_options_text += '-----------------------------------\\n'\n", + "\n", + " # Display quality options\n", + " print(quality_options_text)\n", + "\n", + " # Prompt the user to select the quality option\n", + " selected_option = input(\"Enter the number of the desired quality option (or 'max' for maximum quality): \")\n", + " if selected_option.lower() == 'max':\n", + " video = youtube.streams.get_highest_resolution()\n", + " else:\n", + " selected_option = int(selected_option)\n", + " video = list(youtube.streams)[selected_option - 1]\n", + "\n", + " video_quality = video.resolution if video.resolution else 'Audio'\n", + " file_extension = video.url.split('.')[-1]\n", + " file_name = video.title + f\" ({video_quality})\" + '.' + file_extension\n", + " file_path = os.path.join(destination_folder, file_name)\n", + "\n", " video.download(destination_folder)\n", " print(f\"Video '{video.title}' downloaded successfully to '{destination_folder}'.\\n\")\n", " except Exception as e:\n", @@ -121,15 +144,24 @@ "\n", "except Exception as e:\n", " print(f\"An error occurred: {str(e)}\")\n", - " print(\"Exiting the program.\")\n", - "\n", - "print(\"Exiting the program.\")\n" - ], - "metadata": { - "id": "s6L01xuGIhMn" - }, - "execution_count": null, - "outputs": [] + " print(\"Exiting the program.\")\n" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyNTtIBj43BGvfXJiHDIOgaW", + "include_colab_link": true, + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" } - ] -} \ No newline at end of file + }, + "nbformat": 4, + "nbformat_minor": 0 +}