Added check_link feature.

- check_link feature ensures that the video is in a YouTube domain.
This commit is contained in:
Hansly Saw 2022-05-12 12:21:13 +08:00
parent 7ead6d173a
commit 524206104c

View file

@ -27,8 +27,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"id": "tgACi8lLVS6Y", "id": "tgACi8lLVS6Y"
"cellView": "form"
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -131,8 +130,15 @@
" \n", " \n",
" check_installDone('write')\n", " check_installDone('write')\n",
"\n", "\n",
"def save_video(): \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", "\n",
"def save_video(): \n",
" import google;\n", " import google;\n",
"\n", "\n",
" try:\n", " try:\n",
@ -171,47 +177,51 @@
" start_download((video.video_title + '.' + user.audio_format))\n", " start_download((video.video_title + '.' + user.audio_format))\n",
"\n", "\n",
"# Main. \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 = \"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", "try: \n",
" import yt_dlp;\n", " check_compatibility()\n",
" with yt_dlp.YoutubeDL({}) as ydl:\n", " cleanup()\n",
" class video: \n", " check_link()\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", "\n",
"save_video()\n", " class user: \n",
"download_video()" " 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. ')"
] ]
} }
], ],