def control(type='info'): control = Control() control.play(poll=None) for k in ('star', type): control[k] = '/poll' infos = player.infos name = infos.name if name == 'current_node_name': return index() if type == 'info': media = Media(name=name) length = infos.length if 'seek' in request.GET: if length: pos = int(float(request.GET['seek']) * length / 100) player.call('seek', str(pos)) infos = player.infos if length: time = infos.time pos = int(float(time) / length * 100) else: pos = 0 length = '%smn' % (length / 60) if 'sub_delay' in request.GET: sub_delay = request.GET['sub_delay'] if sub_delay != (media.sub_delay or '0'): time = infos.time > 100 and infos.time or 0 media.data.update(infos, sub_delay=sub_delay, time=time) media.write() control.refresh = '/play/%s' % media.name else: sub_delay = media.sub_delay or '0' return locals()
def index(action=None): quote = urllib.quote basename = os.path.basename root = request.GET.get('root', player.params.location) root = os.path.realpath(root) player.params.location = root title = '%s/' % os.path.basename(root) msg = '' dirnames = [] filenames = [] for root, dirnames, filenames in os.walk(root): break dirnames = [os.path.join(root, d) for d in dirnames \ if not d.startswith('.')] filenames = [os.path.join(root, d) for d in sorted(filenames) \ if not d.startswith('.') and d.lower()[-4:] in exts] if action == 'favorite': items = config.lists.favorites.as_list('\n') name = os.path.basename(root) if root not in items: items.append(root) msg = '%s added to favorites' % name else: items = [i for i in items if i != root] msg = '%s removed from favorites' % name config.lists.favorites = items config.write() if action == 'mark_as_unread': for f in filenames: m = Media(filename=f) m.data.update(times=0, time=0) m.write() if action == 'mark_as_read': infos = player.infos if infos.state == 'playing': player.call('stop') m = Media(filename=player.params.latest) m.data.update(times=1, time=0) m.write() control = Control() control.star = '/browser?root=%s' % quote(os.path.dirname(root)) control.rec = '/browser/mark_as_unread' control.red = '/browser/favorite' control.pip = '/lists/favorites' page = batch(control, dirnames + filenames) filenames = [] for p in page.items: if os.path.isdir(p): filenames.append(Dir(p)) elif os.path.isfile(p): filenames.append(Media(p)) return dict(locals(), title=title, msg=msg, basename=basename)
def call(cmd, arg=None): if arg: player.call(cmd, arg) else: player.call(cmd) if cmd == 'stop': poll(auto=False) return index() return poll()