File size: 2,873 Bytes
3d8b836 5c33714 6d7da8d 3d8b836 6d7da8d 3d8b836 85700dc 3d8b836 181a931 3d8b836 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [
{
"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": null,
"metadata": {
"id": "KXsmL_npl5Zf"
},
"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": [
"#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": [
"\n",
"playlist_URL = '' # @param {type:'string'}\n",
"playlist_start = 1 # @param {type:'number'}\n",
"playlist_end = 9999 # @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",
"!yt-dlp --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",
"drive_folder_name = 'AudiosP1' # @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": []
}
]
} |