Upload YT-playlist-to-mp3.ipynb
Browse files- YT-playlist-to-mp3.ipynb +1 -1
YT-playlist-to-mp3.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1747490904984},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1740037333374},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1736477078136},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1725365086834}]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["This Notebook will take a Youtube Playlist and convert all videos to MP3:s , which will be stored on a folder on your Google Drive."],"metadata":{"id":"I64oSgGJxki5"}},{"cell_type":"code","execution_count":1,"metadata":{"id":"KXsmL_npl5Zf","executionInfo":{"status":"ok","timestamp":
|
|
|
1 |
+
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1756712618300},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1747490904984},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1740037333374},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1736477078136},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1725365086834}]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["This Notebook will take a Youtube Playlist and convert all videos to MP3:s , which will be stored on a folder on your Google Drive."],"metadata":{"id":"I64oSgGJxki5"}},{"cell_type":"code","execution_count":1,"metadata":{"id":"KXsmL_npl5Zf","executionInfo":{"status":"ok","timestamp":1756712516347,"user_tz":-120,"elapsed":5,"user":{"displayName":"","userId":""}}},"outputs":[],"source":["#Initialize\n","import os\n","def my_mkdirs(folder):\n"," if os.path.exists(folder)==False:\n"," os.makedirs(folder)\n","my_mkdirs('/content/tmp/')"]},{"cell_type":"code","source":["#NOTE: you need to download cookies from youtube to your drive folder because of recent Youtubr BS restrictions\n","#Reinstall youtube_dl because the version on Colab is outdated\n","!python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz\n","import yt_dlp as youtube_dl\n"],"metadata":{"id":"CT8O2CJYl-Cb"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["#Mount Google Drive\n","from google.colab import drive\n","drive.mount('/content/drive')"],"metadata":{"id":"vxae5FCml-0A"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# @markdown download video or playlist as audio file mp3\n","youtube_link = '' # @param {type:'string'}\n","playlist_start = 1\n","## @param {type:'number'}\n","playlist_end = 9999\n","## @param {type:'number'}\n","\n","#Extract all videos in YT playlist mp3 files\n","#Aborting this code is fine if list is latge ( You will keep downloaded mp3:s)\n","%cd /content/tmp\n","for playlist_URL in youtube_link.split(','):\n"," !yt-dlp --cookies /content/drive/MyDrive/ytcookies.txt --playlist-end {playlist_end} --playlist-start {playlist_start} --extract-audio --audio-format mp3 -o \"%(title)s.%(ext)s\" {playlist_URL}"],"metadata":{"id":"0K9n3HM6l-7x"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["\n","# @markdown Download video or playlist as highest video quality mp4\n","youtube_link = 'https://youtu.be/qxzbh6vPRZg?si=Ov2zBKly95fn-xGr' # @param {type:'string'}\n","playlist_start = 1\n","## @param {type:'number'}\n","playlist_end = 9999\n","## @param {type:'number'}\n","\n","#Extract all videos in YT playlist mp3 files\n","#Aborting this code is fine if list is latge ( You will keep downloaded mp3:s)\n","%cd /content/drive/MyDrive/Saved from Chrome/\n","for playlist_URL in youtube_link.split(','):\n"," !yt-dlp --cookies /content/drive/MyDrive/ytcookies.txt --playlist-end {playlist_end} --playlist-start {playlist_start} --merge-output-format mp4 -f \"bestvideo+bestaudio[ext=m4a]/best\" -o \"%(title)s.%(ext)s\" {playlist_URL}"],"metadata":{"id":"EWZ4sO7NfdA6"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"wTbO9mWbDXNr"},"outputs":[],"source":["\n","# @markdown 🌊 Rapid keyframe processing\n","# @markdown <br> ------ <br> Extract Keyframes from ALL mp4 / webm videos found on Google Drive\n","# @markdown <br> Be mindful of Google Drive Terms of Service\n","# @markdown <br> This cell will process all mp4 videos found under\n","# @markdown <br> /content/drive/MyDrive/Saved from Chrome/\n","delete_mp4_when_done = True # @param {type:'boolean'}\n","# @markdown <br> deleted mp4/webm files will be found under 'trash' in your Google drive\n","# @markdown <br> -------\n","# @markdown <br> (Optional) Add a direct video link to below field.\n","# @markdown <br> Multiple links can be written in this field\n","# @markdown <br> separated by comma. Like this: <br> ' https:\\\\\\my_video.mp4 , https:\\\\\\second_video.webm , .... '\n","import os\n","import shutil\n","!pip install video-kf\n","!pip install ffmpeg-python\n","!pip install wget\n","!pip install moviepy\n","import wget\n","import videokf as vf\n","import time\n","proc_keyframes=True # @param {type:'boolean'}\n","proc_audio=False # @param {type:'boolean'}\n","#def mkdirs(folder):\n","# if not os.path.exists(folder):os.makedirs(folder)\n","#----#\n","direct_link = '' # @param {type:'string'}\n","# @markdown The linked videos will be downloaded to the Google drive prior to running the script.\n","# @markdown <br> This feature is useful for direct processing .webm from 4chan threads into keyframes\n","use_link = False # @param {type:'boolean'}\n","if direct_link.find('http')>-1: use_link = True\n","if use_link:\n"," %cd '/content/drive/MyDrive/Saved from Chrome/'\n"," for link in direct_link.split(','):\n"," if not link.find('http')>-1:continue\n"," wget.download(link.strip())\n"," time.sleep(5)\n"," %cd '/content/'\n","#-----#\n","filenames = []\n","srcpath = '/content/drive/MyDrive/Saved from Chrome/'\n","destpath = '/content/drive/MyDrive/'\n","localpath = '/content/'\n","converted = ''\n","for filename in os.listdir(f'{srcpath}'):\n"," if filename.find('.zip')>-1:\n"," %cd {srcpath}\n"," !unzip {filename}\n"," os.remove(filename)\n"," filename = filename.replace('.zip','')\n"," for suffix in ['.mp4','.webm']:\n"," if filename.find(f'{suffix}')>-1: filenames.append(filename)\n","#Rename the downloaded video to 'tgt0' before running this cell\n","def my_mkdirs(folder):\n"," if os.path.exists(folder):shutil.rmtree(folder)\n"," os.makedirs(folder)\n","#----#\n","# @markdown Write a funny name for the folder(s) containing the keyframes\n","name_keyframes_as='' # @param {type:'string'}\n","# @markdown Created .zip files will not be overwritten\n","#NUM_ITEMS = 1 # @param {type:'slider', min:1 , max:20,step:1}\n","if name_keyframes_as.strip()=='': name_keyframes_as='keyframes'\n","num = 0\n","savepath = ''\n","%cd {localpath}\n","for filename in filenames:\n"," tgt_folder = f'/content/tmp'\n"," my_mkdirs(f'{tgt_folder}')\n"," print(f'Now processing video {filename}...')\n"," if proc_keyframes:\n"," vf.extract_keyframes(f'{srcpath}{filename}',output_dir_keyframes=f'{tgt_folder}')\n"," savepath = f'{destpath}{name_keyframes_as}_v{num}_kf'\n"," #---#\n"," while os.path.exists(f'{savepath}.zip'):\n"," #print(f'{savepath}.zip already exists...')\n"," num = num+1\n"," savepath = f'{destpath}{name_keyframes_as}_v{num}_kf'\n"," #---#\n"," shutil.make_archive(savepath,'zip' , f'{tgt_folder}')\n"," #from moviepy.editor import VideoFileClip\n"," if proc_audio:\n"," from moviepy.editor import VideoFileClip\n"," # Load the WebM file\n"," video = VideoFileClip(f\"{srcpath}{filename}\")\n","\n"," # Extract audio and save as MP3 (or WAV, etc.)\n"," audio = video.audio\n"," savepath = f\"{destpath}_audio_v{num}.mp3\"\n","\n"," while os.path.exists(savepath):\n"," num = num+1\n"," savepath= f\"{destpath}_audio_v{num}.mp3\"\n"," #----#\n"," if audio:\n"," audio.write_audiofile(f'{savepath}')\n"," # Close the files to free resources\n"," audio.close()\n"," video.close()\n"," #----#\n"," if delete_mp4_when_done: os.remove(f'{srcpath}{filename}')\n"," num = num+1\n"]},{"cell_type":"code","source":["\n","drive_folder_name = 'my_zip_folder' # @param {type:'string'}\n","\n","%cd /content/\n","!zip -r /content/drive/MyDrive/{drive_folder_name}.zip /content/tmp"],"metadata":{"id":"D04FssOTma-2"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["from google.colab import runtime\n","#runtime.unassign()\n","\n","\n"],"metadata":{"id":"1JlaBNIKODCT"},"execution_count":null,"outputs":[]}]}
|