Hi, im trying to set a radio and youtube playlist player
my code works with radio and single youtube link but with playlist it says that the link is unrecognized, can somoene help?
import os
from os import path
from random import randrange
from tkinter.ttk import Combobox
import pafy
import requests
import vlc
import time
from tkinter import *
from tkinter import messagebox,PhotoImage
from bs4 import BeautifulSoup
root = Tk()
global phplay,phpause,phstop
global pausevar
pausevar = ""
phplay = PhotoImage(file=r'img/play.png')
phpause = PhotoImage(file=r'img/pause.png')
phstop = PhotoImage(file=r'img/stop.png')
frmradio = LabelFrame(root, text="Radio Player", padx=5, pady=5, highlightbackground="black", highlightthickness=2)
frmradio.grid(row=0, column=0, sticky=NW, pady=2)
def getradiolist():
var1 = open("Confs/lstradios.txt", "r").readlines()
data = []
for line in var1:
if len(line) > 1:
estacao, url, = line.split('<=>')
data.append(estacao)
return data
valradio = StringVar()
imp_radio = Combobox(frmradio, textvariable=valradio, height=10, width=47)
imp_radio['values'] = getradiolist()
imp_radio['state'] = 'readonly'
imp_radio.grid(row=1, column=0,columnspan=5, pady=2, sticky="ew")
# define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
# Define VLC player
player = instance.media_player_new()
instance.log_unset()
def startplayer(pausevar):
if pausevar == "sim":
pausevar=""
player.pause()
player.stop()
esta = imp_radio.get()
if len(esta)>1:
var1 = open("Confs/lstradios.txt", "r").readlines()
for line in var1:
if len(line) > 1:
if esta in line:
estacao, url, = line.split('<=>')
break
if "youtube" in estacao:
print(url)
playlist = pafy.get_playlist2(url.strip())
items = playlist["items"]# getting playlist items
def loop_play():
item = items[randrange(len(items))]
i_pafy = item['pafy']
y_url = i_pafy.watchv_url
video = pafy.new(y_url)
best = video.getbest()
media = instance.media_new(best.y_url.strip())
player.set_media(media)
frmradio.config(text=str(item["title"]))
player.play()
loop_play()
else:
media = instance.media_new(url.strip())
player.set_media(media)
player.play()
frmradio.config(text=str("Radio Player : Playing: " + estacao))
def stopplauyer():
player.stop()
frmradio.config(text=str("Radio Player"))
def pauseplauyer():
global pausevar
pausevar = "sim"
player.pause()
frmradio.config(text=str("Radio Player : Pause!"))
Button(frmradio, width="150",height="28", text="Play", image=phplay, command=lambda pausevar=pausevar: startplayer(pausevar)).grid(row=0, column=0, sticky=N + S + E + W)
Button(frmradio, width="100",height="28", text="Pause", image=phpause, command=lambda: pauseplauyer()).grid(row=0, column=1, sticky=N + S + E + W)
Button(frmradio, width="100",height="28", text="Stop", image=phstop,command=lambda: stopplauyer()).grid(row=0, column=2, sticky=N + S + E + W)
if __name__ == '__main__':
root.mainloop()
Listaradios.txt is
youtube <=> https://www.youtube.com/playlist?list=PLr5JVJSLVg79UpgS6gdrcINWt86npzXkz
Mega Hits <=> http://19553.live.streamtheworld.com:80/MEGA_HITS_SC
Im getting the error in playlist2
pafy.util.GdataError: Youtube Error 403: The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.
I have also tryied with playlist and playlist2