codeShare commited on
Commit
1cdc39b
·
verified ·
1 Parent(s): a0bbb5d

Upload title_rewriter_drive.ipynb

Browse files
Files changed (1) hide show
  1. title_rewriter_drive.ipynb +1 -0
title_rewriter_drive.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells":[{"cell_type":"markdown","metadata":{"id":"I64oSgGJxki5"},"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."]},{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/drive')"],"metadata":{"id":"J3TdxpA2z9Kd"},"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"091b6e60"},"source":["import os\n","import re\n","\n","media_directory = '/content/drive/MyDrive/YouTube_Media'\n","\n","# Create the directory if it doesn't exist, though it's expected to contain files\n","if not os.path.exists(media_directory):\n"," print(f\"Directory '{media_directory}' does not exist. Please ensure it is created and contains your files.\")\n","else:\n"," print(f\"Searching for files to rename in '{media_directory}'...\")\n"," for filename in os.listdir(media_directory):\n"," original_filename = filename # Keep track of the original filename for comparison\n","\n"," # Step 1: Remove the YouTube ID pattern (e.g., ' - [YouTubeID]') if present\n"," # This regex ensures the .mp3 extension is preserved by capturing it in a group.\n"," # Example: 'Title - [ID].mp3' -> 'Title.mp3'\n"," temp_filename_after_id_removal = re.sub(r' - \\[[^\\]]+\\](\\.mp3$)', r'\\1', original_filename)\n","\n"," # Step 2: Remove large spaces after the numbering (e.g., '001. Title.mp3' -> '001.Title.mp3')\n"," # This regex captures the number prefix (e.g., \"001.\") and the rest of the title,\n"," # then reconstructs without the spaces in between.\n"," final_cleaned_filename = re.sub(r'(\\d+\\.)\\s+(.*)', r'\\1\\2', temp_filename_after_id_removal)\n","\n"," # Only proceed with renaming if the final cleaned filename is different from the original\n"," if final_cleaned_filename != original_filename:\n"," old_filepath = os.path.join(media_directory, original_filename)\n"," new_filepath = os.path.join(media_directory, final_cleaned_filename)\n","\n"," try:\n"," os.rename(old_filepath, new_filepath)\n"," print(f\"Renamed: '{original_filename}' to '{final_cleaned_filename}'\")\n"," except Exception as e:\n"," print(f\"Error renaming '{original_filename}': {e}\")\n"," # else:\n"," # print(f\"Skipping '{original_filename}' (no changes needed or pattern not found).\")\n"," print(\"File renaming process completed.\")"],"execution_count":null,"outputs":[]}],"metadata":{"colab":{"provenance":[{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1769359443802},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1765929505338},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1764859930834},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1763768252838},{"file_id":"1IQqB9joHm5EtmXbuQBXqydFuiBoAwiQ-","timestamp":1763755654136},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1762634251304},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1762004412712},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1761124521078},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1760628088876},{"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":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}