Exemple #1
0
def poll(auto=True):
    control = Control()
    control.play()
    infos = player.infos
    name = infos.name
    if name and name != 'current_node_name':
        media = Media(name=name)
        rest = infos.length - infos.time
        if infos.state == 'stop':
            if auto or rest < 120:
                log.debug('Media ended')
                if media.times:
                    times = media.times.as_int() + 1
                else:
                    times = 1
                media.data.update(times=times, time=0)
            control.refresh = '/browser'
        elif infos.state == 'playing':
            media.data.update(infos)
            delay = 30
            if rest < 180:
                delay = 3
            control.play(poll=delay)
        log.debug('Saving %r', media)
        media.write()
    else:
        control.refresh = '/browser'
    return locals()
Exemple #2
0
def poll(auto=True):
    control = Control()
    control.play()
    infos = player.infos
    name = infos.name
    if name and name != 'current_node_name':
        media = Media(name=name)
        rest = infos.length - infos.time
        if infos.state == 'stop':
            if auto or rest < 120:
                log.debug('Media ended')
                if media.times:
                    times = media.times.as_int() + 1
                else:
                    times = 1
                media.data.update(times=times, time=0)
            control.refresh = '/browser'
        elif infos.state == 'playing':
            media.data.update(infos)
            delay = 30
            if rest < 180:
                delay = 3
            control.play(poll=delay)
        log.debug('Saving %r', media)
        media.write()
    else:
        control.refresh = '/browser'
    return locals()
Exemple #3
0
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()
Exemple #4
0
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()
Exemple #5
0
def play(name):
    media = Media(name=name)
    if media.file and os.path.isfile(media.file):
        control = Control()
        control.play(poll=2)
        filename = media.file
        player.params.location = os.path.dirname(filename)
        player.params.latest = filename
        history = config.history.filenames.as_list('\n')
        history = history[-player.params.history_length.as_int():]
        if filename not in history:
            history.append(filename)
            config.history.filenames = history
            config.write()
        seek = media.play()
        if seek:
            for i in range(20):
                if not player.infos:
                    sleep(.2)
            control.refresh = (0, '/cmds/seek/%s' % seek)
        return locals()
    return index()
Exemple #6
0
def play(name):
    media = Media(name=name)
    if media.file and os.path.isfile(media.file):
        control = Control()
        control.play(poll=2)
        filename = media.file
        player.params.location = os.path.dirname(filename)
        player.params.latest = filename
        history = config.history.filenames.as_list('\n')
        history = history[-player.params.history_length.as_int():]
        if filename not in history:
            history.append(filename)
            config.history.filenames = history
            config.write()
        seek = media.play()
        if seek:
            for i in range(20):
                if not player.infos:
                    sleep(.2)
            control.refresh = (0, '/cmds/seek/%s' % seek)
        return locals()
    return index()