ich habe heute angefangen mit dem YoutubeAPI zu programmieren und ich wollte ein Programm schreiben das mir die ID von einem Channel oder Video anzeigt mit custom User input.
Probelm:
Wenn ich ein Video suchen will, denkt das Programm aus irgend einem Grund das ich "channel" oder "Channel" eingegeben habe und Ich weis echt nicht wieso.
Hier ist mein Code:
Code: Alles auswählen
from apiclient.discovery import build
from time import sleep
api_key = "zensiert"
youtube = build("youtube", "v3", developerKey=api_key)
def search_channel(q):
rq = youtube.search().list(q="GommeHD", part="snippet", type="channel", maxResults=1)
rs = rq.execute()
for item in rs["items"]:
print("ChannelID: " + item["snippet"]["channelId"])
def search_video(q, maxResults):
rq_2 = youtube.search().list(q="", part="snippet", type="video", maxResults=1)
rs_2 = rq_2.execute()
for item in rs_2["items"]:
print("VideoID: " + item["snippet"]["videoId"])
answer = input("Do you want to find the ID of a [video] or of a [channel]: ")
if answer == "channel" or "Channel":
sleep(1)
q = input("Channel you want to search up: ")
sleep(1)
print("Searching...")
sleep(1)
search_channel(q)
elif answer == "video" or "video":
sleep(1)
q = input("Video you want to search up (exact title): ")
sleep(1)
maxresults = input("The max. results: ")
sleep(1)
print("Searching...")
search_video(q, maxResults)
sleep(1)
else:
print("no existing option called: " + str(answer))