fix profile songs in localhost

pull/124/head
Aevann 2023-02-17 17:20:51 +02:00
parent 44e9085d8d
commit 92b77735ae
1 changed files with 11 additions and 10 deletions

View File

@ -800,19 +800,20 @@ def settings_song_change(v):
return redirect("/settings/personal?msg=Profile Anthem successfully updated!")
req = requests.get(f"https://www.googleapis.com/youtube/v3/videos?id={id}&key={YOUTUBE_KEY}&part=contentDetails", timeout=5).json()
duration = req['items'][0]['contentDetails']['duration']
if duration == 'P0D':
return redirect("/settings/personal?error=Can't use a live youtube video!"), 400
if YOUTUBE_KEY != DEFAULT_CONFIG_VALUE:
req = requests.get(f"https://www.googleapis.com/youtube/v3/videos?id={id}&key={YOUTUBE_KEY}&part=contentDetails", timeout=5).json()
duration = req['items'][0]['contentDetails']['duration']
if duration == 'P0D':
return redirect("/settings/personal?error=Can't use a live youtube video!"), 400
if "H" in duration:
return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!"), 400
if "M" in duration:
duration = int(duration.split("PT")[1].split("M")[0])
if duration > 15:
if "H" in duration:
return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!"), 400
if "M" in duration:
duration = int(duration.split("PT")[1].split("M")[0])
if duration > 15:
return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!"), 400
gevent.spawn(_change_song_youtube, v.id, id)
return redirect("/settings/personal?msg=Profile Anthem successfully updated. Wait 5 minutes for the change to take effect.")