You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on a script to get all official music videos from YTM.
I currently have the following issue: If I use "UCVm4YdI3hobkwsHTTOMVJKg" as first parameter result = yt_music.get_artist(channel_id) if result is not None: browseId = result.get('videos', {}).get('browseId', None) sets the browseId corretly and everything works. If I search for "search_youtube.py "@acdc" "AC/DC"", the script does find the browseId UCVm4YdI3hobkwsHTTOMVJKg.
but then I get
When reaching all_videos = yt_music.get_playlist(browseId) I get Exception: Server returned HTTP 404: Not Found. Requested entity was not found.`as an error with the same id as before.
Anyone any ideas?
/EDIT: I think the issue is the initially failed scrape, which I've put in the try-except part. Is there a way to call the function get_artist(channel_id) without breaking the script in case of 404/not found?
importosfromytmusicapi.ytmusicimportYTMusicfromgoogleapiclient.discoveryimportbuildimportyt_dlpimporttime# Initialize a YTMusic instance with authenticationyt_music=YTMusic("oauth.json")
if__name__=="__main__":
importsysiflen(sys.argv) !=3:
print("Usage: python search_channel.py <channel_id_or_artist_name>")
sys.exit(1)
# Get the artist's or channel's ID using yt-dlp or check if it's already a valid channel IDchannel_id=sys.argv[1]
artist_name=sys.argv[2]
result=NonebrowseId=None# Try to use the provided channel IDifchannel_id:
try:
result=yt_music.get_artist(channel_id)
ifresultisnotNone:
browseId=result.get('videos', {}).get('browseId', None)
exceptExceptionase:
# Handle any exceptions that may occur when using the provided channel IDpass# If browseId is still not found, search for the artistifbrowseIdisNone:
print("Now looking for the artist.")
result=yt_music.search(artist_name, "artists")
# Iterate through the search resultsforiteminresult:
if"artist"initemanditem["artist"].lower() ==artist_name.lower():
browseId=item["browseId"]
print("Found browseId:", browseId)
breakifbrowseIdisnotNone:
all_videos=yt_music.get_playlist(browseId)
print("Overview of All Videos:")
forindex, videoinenumerate(all_videos["tracks"], start=1):
title=video.get("title", "N/A")
video_id=video.get("videoId", "N/A")
views=video.get("views", "N/A")
print(f"Video {index}:")
#print(f"Video Type: {videoType}")print(f"Title: {title}")
print(f"Video ID: {video_id}")
print(f"Views: {views}")
print("-------------------------")
# Proceed with the rest of your code using 'all_videos'else:
print("Unable to find browseId for the provided channel ID or artist.")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm currently working on a script to get all official music videos from YTM.
I currently have the following issue: If I use "UCVm4YdI3hobkwsHTTOMVJKg" as first parameter
result = yt_music.get_artist(channel_id) if result is not None: browseId = result.get('videos', {}).get('browseId', None)
sets the browseId corretly and everything works. If I search for "search_youtube.py "@acdc" "AC/DC"", the script does find the browseId UCVm4YdI3hobkwsHTTOMVJKg.but then I get
When reaching
all_videos = yt_music.get_playlist(browseId)
I get Exception: Server returned HTTP 404: Not Found. Requested entity was not found.`as an error with the same id as before.Anyone any ideas?
/EDIT: I think the issue is the initially failed scrape, which I've put in the try-except part. Is there a way to call the function get_artist(channel_id) without breaking the script in case of 404/not found?
Beta Was this translation helpful? Give feedback.
All reactions