{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "9fxoFeA70liP" }, "source": [ "# DownYouNow\n", "\n", "**A 100% free YouTube video downloader.** \n", "\n", "_Powered by [`YouTube-DL`](https://urlzs.com/AqDFN) and [`yt_dlp`](https://urlzs.com/rkBHD). ._" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "tgACi8lLVS6Y" }, "outputs": [], "source": [ "# DownYouNow\n", "# 100% free YouTube video downloader\n", "\n", "import os, sys\n", "\n", "class app: \n", " supported_formats = [\"mp3\", 'm4a', 'wav', \"mp4\", \"mkv\", \"webm\"]\n", "\n", "# Set-up. \n", "\n", "class formatting:\n", " clear = '\\033[0m'\n", " class color: \n", " purple = '\\033[95m'\n", " cyan = '\\033[96m'\n", " cyan_dark = '\\033[36m'\n", " blue = '\\033[94m'\n", " green = '\\033[92m'\n", " yellow = '\\033[93m'\n", " red = '\\033[91m'\n", " class font:\n", " bold = '\\033[1m'\n", " underline = '\\033[4m'\n", "\n", "## Define screen functions. \n", "def clear(): from IPython.display import clear_output; return clear_output()\n", "\n", "class info: # screen messages\n", " def title(): \n", " print_text = ''\n", " try: \n", " if video.video_title: \n", " print_text = (formatting.font.bold + formatting.font.underline + video.video_title + formatting.clear + formatting.clear)\n", " else: \n", " raise\n", " except: print_text = (formatting.font.bold + formatting.font.underline + user.video_link + formatting.clear + formatting.clear)\n", "\n", " print(print_text)\n", " return(print_text)\n", " def status(message): print(formatting.font.bold + 'Status: \\t' + formatting.clear + message)\n", " def err(message): print(formatting.font.bold + formatting.color.red + 'Error: \\t' + formatting.clear + formatting.clear + message)\n", " def warning(message): print(formatting.font.bold + formatting.color.yellow + 'Warning: \\t' + formatting.clear + formatting.clear + message)\n", " def success(message): print(formatting.font.bold + formatting.color.green + 'Finished: \\t' + formatting.clear + formatting.clear + message)\n", "\n", "def check_compatibility(): \n", " try: from google.colab import files\n", " except: raise TypeError(\"No! Please run this in \" + formatting.font.bold + 'Google CoLab' + formatting.clear + '. ')\n", "\n", "def fail(message = ''): \n", " # When the program fails, run this. \n", " clear(); info.title(); info.err(message); os.kill(os.getpid, 1);\n", "\n", "def getExtension(fileName): \n", " import os\n", " fileName_split = os.path.splitext(fileName)\n", "\n", " return fileName_split[1].lower()\n", "\n", "def cleanup(): return os.system('rm -rf /content/*')\n", "\n", "def install(what, where = 'apt', isCritical = False):\n", " os.system('add-apt-repository ppa:apt-fast/stable -y && apt-get update')\n", "\n", " try:\n", " if (where == 'apt' or where == 'apt-get' or where == 'apt-fast' or where == 'aptitude'):\n", " if os.system('DEBIAN_FRONTEND=noninteractive apt-fast install ' + what + ' -y'): \n", " if os.system('DEBIAN_FRONTEND=noninteractive apt install ' + what + ' -y'): \n", " if os.system('DEBIAN_FRONTEND=noninteractive apt-get install ' + what + ' -y'): \n", " if os.system('DEBIAN_FRONTEND=noninteractive apt-fast install --fix-broken ' + what + ' -y'):\n", " if os.system('DEBIAN_FRONTEND=noninteractive apt install --fix-broken ' + what + ' -y'): raise\n", " else: \n", " if os.system('DEBIAN_FRONTEND=noninteractive ' + where + ' install ' + what): raise\n", " except:\n", " errorMsg = (what + ' could not get installed. ')\n", " if isCritical: fail('Critical component ' + errorMsg)\n", " else: info.err(errorMsg); return True\n", " else: \n", " if os.system('apt-fast clean && apt-fast autoremove -y') > 0: os.system('apt clean && apt autoremove -y') > 0\n", "\n", "def install_required(): \n", " def check_installDone(method='check'): \n", " if method == 'write': return os.system('touch .config/installDone')\n", " else: return not(os.system('cat .config/installDone'))\n", "\n", " if not(check_installDone()): \n", " # Install programs here using apt.\n", " for program in ['apt-fast', 'youtube-dl', 'libboost-all-dev']: \n", " clear()\n", " info.title(); info.status('Please wait.')\n", " install(program)\n", " clear()\n", " # install programs here using pip\n", " for program in ['yt-dlp']: \n", " info.title(); info.status('Please wait.')\n", " install(program, 'pip')\n", " clear()\n", " \n", " check_installDone('write')\n", "\n", "def check_link(): \n", " # Check the link if it is in YouTube. \n", " if ('.youtube.co' in user.video_link) or ('youtu.be' in user.video_link): \n", " return True\n", " else: \n", " fail(formatting.font.bold + 'The link is not YouTube. ' + formatting.clear)\n", " return False\n", "\n", "def save_video(): \n", " import google;\n", "\n", " try:\n", " info.title() \n", " if not(user.audio_only):\n", " if os.system('yt-dlp \"' + user.video_link + '\" --compat-options no-youtube-unavailable-videos --merge-output-format ' + user.video_format + ' --audio-format ' + user.audio_format): \n", " cleanup()\n", " if os.system('youtube-dl \"' + user.video_link + '\" --compat-options no-youtube-unavailable-videos --merge-output-format ' + user.video_format + ' --audio-format ' + user.audio_format): raise\n", " else: \n", " if os.system('yt-dlp -x \"' + user.video_link + '\" --compat-options no-youtube-unavailable-videos --audio-format ' + user.audio_format): \n", " cleanup()\n", " if os.system('youtube-dl -x \"' + user.video_link + '\" --compat-options no-youtube-unavailable-videos --audio-format ' + user.audio_format): raise\n", " except: \n", " clear(); fail(formatting.font.bold + 'The YouTube video could not be downloaded. ' + formatting.clear + 'Please try again. ')\n", " else: \n", " info.success('Video cached. ')\n", "\n", "def download_video(): \n", " def start_download(fileName): \n", " from google.colab import files;\n", " clear(); info.title(); \n", " try: \n", " files.download(fileName)\n", " except: \n", " info.warning(formatting.font.bold + 'Could not automatically download video. ' + formatting.clear + 'The video could be downloaded from the sidebar. ')\n", " else: \n", " info.success('Complete. ')\n", " \n", " import os\n", "\n", " if not(user.audio_only): \n", " os.system('mv *.' + user.video_format + ' \"' + (video.video_title + '.' + user.video_format) + '\" -v')\n", " start_download((video.video_title + '.' + user.video_format))\n", " else: \n", " os.system('mv *.' + user.audio_format + ' \"' + (video.video_title + '.' + user.audio_format) + '\" -v')\n", " start_download((video.video_title + '.' + user.audio_format))\n", "\n", "# Main. \n", "try: \n", " check_compatibility()\n", " cleanup()\n", " check_link()\n", "\n", " class user: \n", " video_link = \"\" #@param {type:\"string\"}\n", " video_link = video_link.strip()\n", "\n", " #@markdown ## Output\n", " audio_only = 0 #@param {type:\"slider\", min:0, max:1, step:1}\n", "\n", " if not(audio_only): \n", " video_format = \"mkv\" #@param [\"mkv\", \"webm\"]\n", " else: \n", " video_format = False\n", " \n", " audio_format = 'm4a' #@param ['m4a']\n", "\n", "\n", " install_required()\n", "\n", " try: \n", " import yt_dlp;\n", " with yt_dlp.YoutubeDL({}) as ydl:\n", " class video: \n", " info_dict = ydl.extract_info(user.video_link, download=False)\n", " video_url = info_dict.get(\"url\", None)\n", " video_id = info_dict.get(\"id\", None)\n", " video_title = info_dict.get('title', None)\n", " output_format = '';\n", " except: \n", " import youtube_dl;\n", " with youtube_dl.YoutubeDL({}) as ydl:\n", " class video: \n", " info_dict = ydl.extract_info(user.video_link, download=False)\n", " video_url = info_dict.get(\"url\", None)\n", " video_id = info_dict.get(\"id\", None)\n", " video_title = info_dict.get('title', None)\n", " output_format = '';\n", "\n", " save_video()\n", " download_video()\n", "except: \n", " info.fail(formatting.font.bold + 'An error has ocurred, ' formatting.clear + 'we apologize for the inconvenience. Please check the log for full details. ')" ] } ], "metadata": { "colab": { "collapsed_sections": [], "name": "Untitled0.ipynb", "private_outputs": true, "provenance": [], "include_colab_link": true }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }