{ "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": [] } ] }