Created
July 24, 2022 11:53
-
-
Save impshum/061787db9b33d7af412a419bd3461490 to your computer and use it in GitHub Desktop.
Create Youtube Playlist From Urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def create_youtube_playlist(playlist_title, youtube_urls): | |
playlist_url = 'https://www.youtube.com/watch_videos?video_ids=' | |
for youtube_url in youtube_urls: | |
regex = re.compile( | |
r'(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?(?P<id>[A-Za-z0-9\-=_]{11})') | |
match = regex.match(youtube_url) | |
if not match: | |
print(f'no id found: {youtube_url}') | |
else: | |
id = match.group('id') | |
playlist_url += f'{id},' | |
playlist_url = playlist_url.rstrip(',') | |
playlist_url += f'&title={playlist_title}' | |
return playlist_url | |
def main(): | |
playlist_title = 'Zoha' | |
youtube_urls = ['https://youtu.be/64CACoHNBEI', | |
'https://youtu.be/HPbD6o5emNc', | |
'https://youtu.be/PYefVGPHAE8', | |
'https://youtu.be/2DLnhdnSUVs', | |
'https://youtu.be/r1PwZxlQxcU'] | |
url = create_youtube_playlist(playlist_title, youtube_urls) | |
print(url) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment