Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()