mirror of
https://github.com/buzz-lightsnack-2007/DownYouNow.git
synced 2024-08-14 23:55:22 +00:00
Created using Colaboratory
This commit is contained in:
parent
6b03e112ff
commit
010409d8f4
1 changed files with 208 additions and 0 deletions
208
DownYouNow.ipynb
Normal file
208
DownYouNow.ipynb
Normal file
|
@ -0,0 +1,208 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "9fxoFeA70liP"
|
||||
},
|
||||
"source": [
|
||||
"# DownYouNow\n",
|
||||
"\n",
|
||||
"**A 100% free YouTube video downloader.** \n",
|
||||
"\n",
|
||||
"_Powered by `yt_dlp` and `youtube_dl`._"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "tgACi8lLVS6Y",
|
||||
"cellView": "form"
|
||||
},
|
||||
"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 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",
|
||||
" info.status('Installing ' + what + '…')\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: clear(); info.title(); raise SystemError('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",
|
||||
" info.success('Installed '+ what + '.'); return False\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",
|
||||
" for program in ['apt-fast', 'yt-dlp', 'youtube-dl', 'libboost-all-dev']: \n",
|
||||
" clear()\n",
|
||||
" info.title(); info.status('Please wait.')\n",
|
||||
" install(program)\n",
|
||||
" clear()\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): raise\n",
|
||||
" else: \n",
|
||||
" if os.system('yt-dlp -x \"' + user.video_link + '\" --compat-options no-youtube-unavailable-videos --audio-format ' + user.audio_format): raise\n",
|
||||
" except: \n",
|
||||
" clear(); info.title(); raise UnboundLocalError(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",
|
||||
"check_compatibility()\n",
|
||||
"cleanup()\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 = \"mp4\" #@param [\"mp4\", \"mkv\", \"webm\"]\n",
|
||||
" else: \n",
|
||||
" video_format = False\n",
|
||||
" \n",
|
||||
" audio_format = 'm4a' #@param ['mp3', 'm4a', 'wav']\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",
|
||||
"install_required()\n",
|
||||
"save_video()\n",
|
||||
"download_video()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"collapsed_sections": [],
|
||||
"name": "Untitled0.ipynb",
|
||||
"private_outputs": true,
|
||||
"provenance": []
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
Loading…
Reference in a new issue