Ejemplo n.º 1
0
 def add_workers(self, revive=None, count=None):
     from api.models import DownloadThread
     if revive == None:
         for i in range(cc.workers):
             download_worker = DownloadThread(self.queue, create_services())
             download_worker.start()
             self.download_workers.append(download_worker)
Ejemplo n.º 2
0
def status_wrapper():
    job_ids = [int(x) for x in (request.args.get('job_ids').split(','))]
    valid_ids = DownloadThread.parse_job_ids(job_ids)
    result = {'track': [], 'album': [], 'playlist': []}
    func = {
        'track': DownloadThread.to_json_track,
        'album': DownloadThread.to_json_album,
        'playlist': DownloadThread.to_json_playlist,
        'discography': DownloadThread.to_json_discography
    }
    for job_type, ids in valid_ids.items():
        for job_id in ids:
            progress = DownloadThread.wrapper(job_id, job_type, func[job_type])
            result[job_type].append(progress)
    return jsonify(result)
Ejemplo n.º 3
0
def health():
    """various informations about service health"""
    worker_status = [w.get_health() for w in ci.download_workers]
    store_size = DownloadThread.store_size()

    return jsonify({
        'workers': worker_status,
        'store': store_size,
        'queue': ci.queue.qsize()
    })
Ejemplo n.º 4
0
def discography(args):
    service = ci.services[args['service']]
    discography = chimera.discography.get_discography(args['id'], service)
    discography.check()
    discography_task = chimera.concurrency.blackhole(discography,
                                                     'discography')

    status = DownloadThread.wrapper(discography_task.job_id, 'discography',
                                    DownloadThread.to_json_discography)
    status['progress'] = float()
    return jsonify(status)
Ejemplo n.º 5
0
def playlist():
    playlist_id = request.form.get('id', None)
    service = request.form.get('service', None)

    if not playlist_id or not service:
        return jsonify(error='Missing argument',
                       args={
                           'id': playlist_id,
                           'service': service
                       }), 400

    playlist = ci.services[service].get_playlist(playlist_id)
    playlist_task = chimera.concurrency.blackhole(playlist, 'playlist')

    status = DownloadThread.wrapper(playlist_task.job_id, 'playlist',
                                    DownloadThread.to_json_playlist)
    status['progress'] = float()
    return jsonify(status)
Ejemplo n.º 6
0
def album():
    # carefull, do not int(album_id) qobuz has leading zeros in some
    # album ids
    album_id = request.form.get('id', None)
    service = request.form.get('service', None)
    if not album_id or not service:
        return jsonify(error='Missing argument',
                       args={
                           'id': album_id,
                           'service': service
                       }), 400

    album = ci.services[service].get_album(album_id)
    album_task = chimera.concurrency.blackhole(album, 'album')

    # create json dump
    status = DownloadThread.wrapper(album_task.job_id, 'album',
                                    DownloadThread.to_json_album)
    status['progress'] = float()
    return jsonify(status)
Ejemplo n.º 7
0
def track():
    if request.is_json:
        data = request.get_json()
        track_id = data.get('id', None)
        service = data.get('service', None)
    else:
        track_id = request.form.get('id', None)
        service = request.form.get('service', None)
    if not track_id or not service:
        return jsonify(error='Missing argument',
                       args={
                           'id': track_id,
                           'service': service
                       }), 400

    track = ci.services[service].get_track(track_id)
    task = chimera.concurrency.blackhole(track, 'track')
    if task.track:
        return jsonify(DownloadThread.to_json_track(task))
    else:
        return jsonify(error='Error grabbing track.'), 404
Ejemplo n.º 8
0
def grab_video(args):
    video = ci.tidal.get_video(args['id'])
    video_task = chimera.concurrency.blackhole(video, 'video')
    status = DownloadThread.wrapper(video_task.job_id, 'video',
                                    DownloadThread.to_json_video)
    return jsonify(status)
Ejemplo n.º 9
0
def is_alive():
    return jsonify(status=DownloadThread.is_alive())
Ejemplo n.º 10
0
def video():
    job_id = int(request.args.get('job_id'))
    status = DownloadThread.wrapper(job_id, 'video',
                                    DownloadThread.to_json_video)
    return jsonify(status)
Ejemplo n.º 11
0
def discography():
    job_id = int(request.args.get('job_id'))
    status = DownloadThread.wrapper(job_id, 'discography',
                                    DownloadThread.to_json_discography)
    return jsonify(status)
Ejemplo n.º 12
0
def playlist():
    job_id = int(request.args.get('job_id'))
    status = DownloadThread.wrapper(job_id, 'playlist',
                                    DownloadThread.to_json_playlist)
    return jsonify(status)
Ejemplo n.º 13
0
def album():
    job_id = int(request.args.get('job_id'))
    status = DownloadThread.wrapper(job_id, 'album',
                                    DownloadThread.to_json_album)
    return jsonify(status)
Ejemplo n.º 14
0
def track():
    job_id = int(request.args.get('job_id'))
    status = DownloadThread.wrapper(job_id, 'track',
                                    DownloadThread.to_json_track)
    return jsonify(status)