{ "cells": [ { "cell_type": "markdown", "id": "fc78c4b6", "metadata": {}, "source": [ "# One Million Arab Coders (OMAC) \n", " \n", "## Project: Downloading Videos Direct from YouTube \n", " \n", "## Mohamed Ahmed Makki\n", "\n", "#### This project allows us to download any video from YouTube site,\n", "#### first will prompt us to enter the link of the required video on the YouTube (full web address)\n", "#### then the code will allow us to download the video with all necessary corresponding information such as:\n", "#### Title of the video, Time-Length (Duration), Counts of Views, Brief Description and Ratings." ] }, { "cell_type": "code", "execution_count": 120, "id": "af862a42", "metadata": {}, "outputs": [], "source": [ "# importing the required modules from libraries\n", "from pytube import YouTube\n", "import datetime" ] }, { "cell_type": "code", "execution_count": 121, "id": "e1d49845", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Input The Youtube Video URL Address: https://www.youtube.com/watch?v=TENU9b9RZCU\n" ] } ], "source": [ "# entering the desired Youtube Video link to be downloaded\n", "url = input(\"Input The Youtube Video URL Address: \")\n", "tube = YouTube(url)" ] }, { "cell_type": "code", "execution_count": 122, "id": "0657d5c9", "metadata": {}, "outputs": [], "source": [ "# converting the duration of video from seconds to hour:minutes:seconds Format.\n", "\n", "n=tube.length \n", "def convert(n):\n", " return str(datetime.timedelta(seconds = n))" ] }, { "cell_type": "code", "execution_count": 137, "id": "7bd4ed6a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Full Title : BEST PAVILIONS AT DUBAI EXPO 2020 (Top 30)\n", "Duration : 0:30:22\n", "Views : 114080\n", "Description : Video exploring around , United Arab Emirates\n", "Ratings : 4.6622515\n" ] } ], "source": [ "# printing all necessary information about the downloaded video.\n", "\n", "# print the title of the downloaded video.\n", "print(\"Full Title :\", tube.title)\n", "\n", "# print the Duration of the downloaded video.\n", "print(\"Duration :\", str(datetime.timedelta(seconds = n)))\n", "\n", "# print the number of views for this Video.\n", "print(\"Views :\", tube.views)\n", "\n", "# print the first line of the Description\n", "print(\"Description :\", tube.description[:45])\n", "\n", "# print the Ratings for the Video\n", "print(\"Ratings :\", tube.rating)\n", "\n", " " ] }, { "cell_type": "code", "execution_count": 124, "id": "2d989413", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done!! . . . Fun Watching\n" ] } ], "source": [ "# start the downloading process to the specific folder in the computer.\n", "\n", "stream = tube.streams.get_highest_resolution()\n", "stream.download('C:\\\\Users\\mak\\Downloads')\n", "\n", "# print a download-completion note\n", "print(\"Done!! . . . Fun Watching\")" ] }, { "cell_type": "markdown", "id": "ec2be448", "metadata": {}, "source": [ "### Notes:\n", "\n", "#### - This program's default folder for downloading videos is (C:\\\\Users\\user_name)\n", "#### if you use the stream.download( ) code with empty parentheses, \n", "#### however, you may choose any other folder to download the video to, I chose the downloads folder \n", "#### 'C:\\\\Users\\mak\\Downloads').\n", "#### - Because the Description item (sometimes) contains a lot of information, the code here only allows one line for it. \n", "#### for a very brief description; it can be set to the default setting (by coding), which displays all full information for\n", "#### the Description Item.\n", "#### - The purpose of importing the datetime modules is to convert the (meaningless) huge time duration in seconds \n", "#### to a comprehensible format of hours:minutes:seconds\n" ] }, { "cell_type": "markdown", "id": "e612000c", "metadata": {}, "source": [ "### Development: \n", "\n", "### - This program could be developed into a standalone website tool that allows\n", "### users to download YouTube videos by merely inputting the video url link. \n", "\n", "### - It can also be developed to download videos from other websites; besides \n", "### downloading files in various formats such as txt, pdf, and photos with\n", "### different file extensions.\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "f9639e40", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }