Пример #1
0
    def shuffle(self):
        user_id = cherrypy.request.user.id

        current_index = (get_database().query(Queue.index)
                                       .filter(Queue.user_id == user_id, Queue.current)
                                       .scalar())

        query = get_database().query(Queue).filter(Queue.user_id == user_id)

        if current_index is None:
            current_index = 0
        else:
            query = query.filter(Queue.index > current_index)

        queue_count = query.count()

        indexes = list(range(queue_count))

        random.shuffle(indexes)

        for index, queue in enumerate(query.all()):
            queue.index = current_index + 1 + indexes[index]

        get_database().commit()

        ws.emit('queue.update')
Пример #2
0
    def add_tracks(self, track_ids):
        user_id = cherrypy.request.user.id

        queues = []

        for track_id in track_ids:
            if track_id == "":
                continue

            index = self.get_new_pos(user_id)

            queue = Queue(index)
            queue.track_id = track_id
            queue.user_id = user_id

            get_database().add(queue)

            queues.append(queue)

        get_database().commit()

        for queue in queues:
            # always update seen, True means now
            if queue.track.album is not None:
                queue.track.album.seen = True

        ws.emit('queue.update')
Пример #3
0
    def update_queues(self, queues):
        for id, args in queues:
            get_database().query(Queue).filter_by(id=id).update(args)

        get_database().commit()

        ws.emit('queue.update')
Пример #4
0
    def transcoding_end(self, track, transcoder):
        if hasattr(cherrypy.request, 'queue_current_id') and cherrypy.request.queue_current_id is not None:
            queue_current = queue_dao.get_queue(cherrypy.request.queue_current_id)

            if queue_current is not None:
                queue_dao.update_queue(queue_current.id, playing=False)

            if queue_current is not None and queue_current.current:
                if (hasattr(cherrypy.request, 'queue_progress') and cherrypy.request.queue_progress is not None and
                        not hasattr(cherrypy.request, 'queues_done') or not cherrypy.request.queues_done):
                    progress = cherrypy.request.queue_progress
                    current_seconds = math.floor(progress['seconds'] - progress['seconds_ahead'])
                else:
                    current_seconds = None

                if transcoder.success:
                    error = None
                else:
                    error = transcoder.error

                queue_dao.update_queue(queue_current.id, current_seconds=current_seconds, error=error)

            ws.emit('queue.update')

        track = self.serialize_track(track)

        user_agent = cherrypy.request.headers['User-Agent']

        ws.emit('queue.end', track, user_agent)
Пример #5
0
    def end(self):
        _database_events = cherrypy.request._database_events
        cherrypy.request._database_events = None

        for key, values in _database_events.items():
            type, entity, id = key
            columns, new_values = values
            ws.emit('database_events.%s.%s' % (entity.lower(), type), id, columns, new_values)
Пример #6
0
    def queue_open(self, ws_user):
        track = cache.get('queue.current_track_%d' % ws_user.id)
        progress = cache.get('queue.current_progress_%d' % ws_user.id)

        if track is not None:
            ws.emit('queue.current_track_%d' % ws_user.id, track, ws_user=ws_user)

        if progress is not None:
            ws.emit('queue.current_progress_%d' % ws_user.id, progress, ws_user=ws_user)
Пример #7
0
    def clear(self):
        user_id = cherrypy.request.user.id

        get_database().query(Queue).filter(Queue.user_id == user_id).delete(synchronize_session='fetch')

        get_database().commit()

        self._reset_current()

        ws.emit('queue.update')
Пример #8
0
    def reset_current(self):
        user_id = cherrypy.request.user.id

        (get_database().query(Queue)
         .filter(and_(Queue.user_id == user_id, Queue.current))
         .update({'current': False, 'current_seconds': None}, synchronize_session='fetch'))

        get_database().commit()

        self._reset_current()

        ws.emit('queue.update')
Пример #9
0
    def transcoding_progress(self, progress, transcoder, track):
        ws_user = ws.get_ws_user()

        if ws_user is not None:
            cache.set('queue.current_progress_%d' % ws_user.id, progress)

        if 'User-Agent' in cherrypy.request.headers:
            user_agent = cherrypy.request.headers['User-Agent']
        else:
            user_agent = None

        format = transcoder.__class__.outputs()

        ws.emit('queue.progress', progress, self.serialize_track(track), user_agent, format)

        cherrypy.request.queue_progress = progress
Пример #10
0
    def remove(self, ids):
        user_id = cherrypy.request.user.id

        query = get_database().query(Queue).filter(and_(Queue.user_id == user_id, Queue.id.in_(ids)))

        try:
            query.filter("current").one()

            self._reset_current()
        except NoResultFound:
            pass

        query.delete(synchronize_session='fetch')

        get_database().commit()

        ws.emit('queue.update')
Пример #11
0
    def transcoding_start(self, transcoder, track):
        if hasattr(cherrypy.request, 'queue_current_id') and cherrypy.request.queue_current_id is not None:
            queue_current_id = cherrypy.request.queue_current_id
            queue_dao.update_queue(queue_current_id, current_seconds=None, playing=True)

        track = self.serialize_track(track)

        if 'User-Agent' in cherrypy.request.headers:
            user_agent = cherrypy.request.headers['User-Agent']
        else:
            user_agent = None

        format = transcoder.__class__.outputs()

        ws_user = ws.get_ws_user()

        if ws_user is not None:
            cache.set('queue.current_track_%d' % ws_user.id, track)

        ws.emit('queue.start', track, user_agent, format)
Пример #12
0
 def queue_next(self, next):
     if next is None:
         ws.emit('queue.next.none')
Пример #13
0
    def _reset_current(self):
        ws_user = ws.get_ws_user()
        cache.set('queue.current_track_%d' % ws_user.id, None)
        cache.set('queue.current_progress_%d' % ws_user.id, None)

        ws.emit('queue.reset')
Пример #14
0
 def clear_played(self):
     user_id = cherrypy.request.user.id
     get_database().query(Queue).filter(and_(Queue.user_id == user_id, Queue.played,
                                        "not current")).delete(synchronize_session='fetch')
     get_database().commit()
     ws.emit('queue.update')