Skip to content

Instantly share code, notes, and snippets.

@AhmedFathyDev
Created December 24, 2023 18:56
Show Gist options
  • Save AhmedFathyDev/b6d304d6ca15b7ec76fc1d7bb90ac9ae to your computer and use it in GitHub Desktop.
Save AhmedFathyDev/b6d304d6ca15b7ec76fc1d7bb90ac9ae to your computer and use it in GitHub Desktop.
# pip install pytube
from pytube import Playlist
import os
dir = 'DIR_PATH'
current_names = os.listdir(dir)
for i, name in enumerate(current_names):
current_names[i] = dir + current_names[i]
playlist_url = 'PLAYLIST_URL'
playlist = Playlist(playlist_url)
youtube_names = []
for video in playlist.videos:
youtube_names.append(os.path.splitext(video.title)[0])
for i, (youtube_name, current_name) in enumerate(zip(youtube_names, current_names)):
try:
os.rename(current_name, f'{dir}{i + 1}.{youtube_name}.mp4')
except Exception as e:
print(f'Error renaming {current_name}: {str(e)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment