Skip to content

Instantly share code, notes, and snippets.

@RomeoV
Created October 4, 2019 23:45
Show Gist options
  • Save RomeoV/cc8fa43933688af172791f378aeb7d45 to your computer and use it in GitHub Desktop.
Save RomeoV/cc8fa43933688af172791f378aeb7d45 to your computer and use it in GitHub Desktop.
A tool that queries youtube for a video name/topic and then tries to extract the song name(s) from the description. Afterwards, they can be pasted in some online service and exported as a spotify playlist.
from googleapiclient.discovery import build
import re
youtube = build('youtube','v3',developerKey=...)
video_ids = []
for run_nbr in range(30):
search_response = youtube.search().list(q='tf2 JOTW ' + str(run_nbr),part='id',type='video',maxResults=1).execute()
for search_result in search_response.get('items',[]):
video_ids.append(search_result['id']['videoId'])
music_lines = []
for id in video_ids:
video_content = youtube.videos().list(
id=id,
part='snippet,localizations'
).execute()
video = video_content['items'][0]
description = video['snippet']['description']
music_lines_in_description = [line for line in description.split('\n\n') if 'Music' in line or 'Song' in line]
if len(music_lines_in_description) > 0:
music_lines.append(music_lines_in_description[0])
else:
print(description)
for block in music_lines:
lines = block.split('\n')
for l in lines:
match = re.search(r'(\w[\w\s]+-.*$)',l)
if match:
print(match.group(0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment