mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-13 21:52:18 +00:00
Jukebox status: report (simulated) position
This commit is contained in:
parent
9de96bb530
commit
ee2efec59a
@ -78,7 +78,12 @@ def jukebox_control():
|
|||||||
except DaemonUnavailableError:
|
except DaemonUnavailableError:
|
||||||
raise GenericError("Jukebox unavaliable")
|
raise GenericError("Jukebox unavaliable")
|
||||||
|
|
||||||
rv = dict(currentIndex=status.index, playing=status.playing, gain=status.gain)
|
rv = dict(
|
||||||
|
currentIndex=status.index,
|
||||||
|
playing=status.playing,
|
||||||
|
gain=status.gain,
|
||||||
|
position=status.position,
|
||||||
|
)
|
||||||
if action == "get":
|
if action == "get":
|
||||||
playlist = []
|
playlist = []
|
||||||
for path in status.playlist:
|
for path in status.playlist:
|
||||||
|
@ -115,10 +115,12 @@ class JukeboxResult(DaemonCommandResult):
|
|||||||
self.playing = False
|
self.playing = False
|
||||||
self.index = -1
|
self.index = -1
|
||||||
self.gain = 1.0
|
self.gain = 1.0
|
||||||
|
self.position = 0
|
||||||
else:
|
else:
|
||||||
self.playing = jukebox.playing
|
self.playing = jukebox.playing
|
||||||
self.index = jukebox.index
|
self.index = jukebox.index
|
||||||
self.gain = jukebox.gain
|
self.gain = jukebox.gain
|
||||||
|
self.position = jukebox.position
|
||||||
self.playlist = ()
|
self.playlist = ()
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import os
|
|||||||
import shlex
|
import shlex
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from pony.orm import db_session, ObjectNotFound
|
from pony.orm import db_session, ObjectNotFound
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
@ -27,6 +28,7 @@ class Jukebox(object):
|
|||||||
self.__cmd = shlex.split(cmd)
|
self.__cmd = shlex.split(cmd)
|
||||||
self.__playlist = []
|
self.__playlist = []
|
||||||
self.__index = 0
|
self.__index = 0
|
||||||
|
self.__start = None
|
||||||
|
|
||||||
self.__devnull = None
|
self.__devnull = None
|
||||||
|
|
||||||
@ -42,6 +44,12 @@ class Jukebox(object):
|
|||||||
gain = property(lambda self: 1.0)
|
gain = property(lambda self: 1.0)
|
||||||
playlist = property(lambda self: list(self.__playlist))
|
playlist = property(lambda self: list(self.__playlist))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def position(self):
|
||||||
|
if self.__start is None:
|
||||||
|
return 0
|
||||||
|
return int((datetime.utcnow() - self.__start).total_seconds())
|
||||||
|
|
||||||
# subprocess.DEVNULL doesn't exist on Python 2.7
|
# subprocess.DEVNULL doesn't exist on Python 2.7
|
||||||
def _get_devnull(self):
|
def _get_devnull(self):
|
||||||
if self.__devnull is None:
|
if self.__devnull is None:
|
||||||
@ -79,6 +87,7 @@ class Jukebox(object):
|
|||||||
|
|
||||||
with self.__lock:
|
with self.__lock:
|
||||||
self.__index = index
|
self.__index = index
|
||||||
|
self.__start = None
|
||||||
self.__skip.set()
|
self.__skip.set()
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
@ -131,6 +140,7 @@ class Jukebox(object):
|
|||||||
proc = self.__play_file()
|
proc = self.__play_file()
|
||||||
elif proc.poll() is not None:
|
elif proc.poll() is not None:
|
||||||
with self.__lock:
|
with self.__lock:
|
||||||
|
self.__start = None
|
||||||
self.__index += 1
|
self.__index += 1
|
||||||
if self.__index >= len(self.__playlist):
|
if self.__index >= len(self.__playlist):
|
||||||
break
|
break
|
||||||
@ -142,6 +152,7 @@ class Jukebox(object):
|
|||||||
proc.terminate()
|
proc.terminate()
|
||||||
proc.wait()
|
proc.wait()
|
||||||
self._close_devnull()
|
self._close_devnull()
|
||||||
|
self.__start = None
|
||||||
|
|
||||||
def __play_file(self):
|
def __play_file(self):
|
||||||
path = self.__playlist[self.__index]
|
path = self.__playlist[self.__index]
|
||||||
@ -149,6 +160,7 @@ class Jukebox(object):
|
|||||||
|
|
||||||
logger.debug("Start playing with command %s", args)
|
logger.debug("Start playing with command %s", args)
|
||||||
try:
|
try:
|
||||||
|
self.__start = datetime.utcnow()
|
||||||
return Popen(
|
return Popen(
|
||||||
args,
|
args,
|
||||||
stdin=self._get_devnull(),
|
stdin=self._get_devnull(),
|
||||||
|
Loading…
Reference in New Issue
Block a user