started work on playlist management
This commit is contained in:
parent
0ac75ff93a
commit
c2ee159dde
56
server.py
56
server.py
@ -15,11 +15,29 @@ class namespace(object): pass
|
|||||||
COLOR_BLUE = "rgb(33, 150, 243)"
|
COLOR_BLUE = "rgb(33, 150, 243)"
|
||||||
COLOR_BLUE_SHADOW = "rgba(33, 150, 243, 0.75)"
|
COLOR_BLUE_SHADOW = "rgba(33, 150, 243, 0.75)"
|
||||||
|
|
||||||
|
|
||||||
|
#todo: move this functionality to mpv_control.py or its own file, managing playlists and shit?
|
||||||
|
import youtube_dl
|
||||||
|
def get_youtube_metadata(url, ydl = youtube_dl.YoutubeDL()):
|
||||||
|
#todo: check if url is valid
|
||||||
|
|
||||||
|
#todo, stop it from doung the whole playlist
|
||||||
|
resp = ydl.extract_info(url, download=False)
|
||||||
|
#print resp.keys()
|
||||||
|
|
||||||
|
title = resp.get('title')
|
||||||
|
length = resp.get('duration')
|
||||||
|
|
||||||
|
#print( title, "%i:%.2i" % (length//60, length%60))
|
||||||
|
return title, "%i:%.2i" % (length//60, length%60)
|
||||||
|
|
||||||
|
|
||||||
class MyApp(App):
|
class MyApp(App):
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
res_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res')
|
res_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res')
|
||||||
super(MyApp, self).__init__(*args, static_paths=(res_path,))
|
super(MyApp, self).__init__(*args, static_paths=(res_path,))
|
||||||
|
|
||||||
|
|
||||||
#initalize mpv here?
|
#initalize mpv here?
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
@ -49,6 +67,8 @@ class MyApp(App):
|
|||||||
self.playlist.table.from_2d_matrix([['#', 'Name', "length"]])
|
self.playlist.table.from_2d_matrix([['#', 'Name', "length"]])
|
||||||
container.append(self.playlist.table)
|
container.append(self.playlist.table)
|
||||||
|
|
||||||
|
self.playlist.queue = []#[i] = [source, name, length]
|
||||||
|
|
||||||
#input
|
#input
|
||||||
container.append(gui.Label("Add songs:"))
|
container.append(gui.Label("Add songs:"))
|
||||||
inputContainer = gui.HBox(width=512)
|
inputContainer = gui.HBox(width=512)
|
||||||
@ -64,34 +84,48 @@ class MyApp(App):
|
|||||||
inputContainer.append(self.input.submit)
|
inputContainer.append(self.input.submit)
|
||||||
container.append(inputContainer)
|
container.append(inputContainer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#return the container
|
#return the container
|
||||||
self.mainLoop()
|
self.mainLoop()
|
||||||
return container
|
return container
|
||||||
def mainLoop(self):
|
def mainLoop(self):
|
||||||
#self.playback.slider.get_value()
|
#self.playback.slider.get_value()
|
||||||
self.playback.slider.set_value(int(random.random()*100))
|
|
||||||
|
|
||||||
self.playlist.table.from_2d_matrix([['#', 'Name', "length"],
|
self.playback_update()
|
||||||
['1', 'Awesome song', "5:23"],
|
|
||||||
['2', 'min kuk er saa hard', "2:56"],
|
self.playlist.table.from_2d_matrix(self.playlist_update())
|
||||||
['3', 'spis meg', "90:01"],
|
|
||||||
['3', "Slidervalue: %s" % self.playback.slider.get_value(), "0:00"]])
|
|
||||||
|
|
||||||
Timer(1, self.mainLoop).start()
|
Timer(1, self.mainLoop).start()
|
||||||
def playback_play(self): pass
|
def playback_play(self): pass
|
||||||
def playback_pause(self): pass
|
def playback_pause(self): pass
|
||||||
def playback_next(self): pass
|
def playback_next(self):
|
||||||
|
source, name, length = self.playlist.queue.pop(0)
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
def input_submit(self, value=None):
|
def input_submit(self, value=None):
|
||||||
if not value:
|
if not value:
|
||||||
value = self.input.field.get_text()
|
value = self.input.field.get_text()
|
||||||
|
|
||||||
|
title, length = get_youtube_metadata(value)
|
||||||
|
|
||||||
self.input.field.set_text("")
|
self.input.field.set_text("")
|
||||||
if mpv.play(value):
|
#playback steps:
|
||||||
pass
|
def playback_update(self):
|
||||||
|
#talk to mpv, see wether the song is being played still
|
||||||
|
if 0:#if done:
|
||||||
|
self.playback_next()
|
||||||
|
self.playback.slider.set_value(0)
|
||||||
|
else:
|
||||||
|
self.playback.slider.set_value(100)
|
||||||
|
|
||||||
|
return
|
||||||
|
def playlist_update(self):
|
||||||
|
out = [['#', 'Name', "length"]]
|
||||||
|
|
||||||
|
for i, (source, name, length) in enumerate(self.playlist.queue):
|
||||||
|
out.append([str(i+1), name, length])
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not os.path.exists("config.ini"):
|
if not os.path.exists("config.ini"):
|
||||||
|
Loading…
Reference in New Issue
Block a user