Created
September 3, 2023 11:35
-
-
Save ehzawad/fc3d7170c535f188bf7bc446b19b157a to your computer and use it in GitHub Desktop.
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
from ytmusicapi import YTMusic | |
# Initialize YTMusic using your OAuth credentials | |
ytmusic = YTMusic("oauth.json") | |
# Search for a song | |
search_results = ytmusic.search('Blank Space By Taylor Swift') | |
# Check if search results are empty | |
if not search_results: | |
print("No results found for the search query.") | |
else: | |
# 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) | |
else: | |
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