Skip to content

Instantly share code, notes, and snippets.

Created September 3, 2023 11:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
from ytmusicapi import YTMusic
# Initialize YTMusic using your OAuth credentials
ytmusic = YTMusic("oauth.json")
# Search for a song
search_results ='Blank Space By Taylor Swift')
# Check if search results are empty
if not search_results:
print("No results found for the search query.")
# Find the first result with 'resultType' set to 'song'
song_result = next((item for item in search_results if item['resultType'] == 'song'), None)
if song_result:
print("Found song:", song_result)
# Fetch and print the song's metadata using the 'videoId'
song_metadata = ytmusic.get_song(song_result['videoId'])
print("Song metadata:", song_metadata)
print("No song found in the search results.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment