You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

import json
from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask, render_template
from redis import Redis
from utils.download import download_album
from utils.processor import process_download
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
def process_downloads():
print('Processing Downloads..')
pending_downloads = Album.search([('downloaded', '=', False), ('downloading', '=', False)])
if pending_downloads:
ready_album = pending_downloads[:1]
if ready_album:
album = ready_album[0]
print('...................')
print('Downloading Album..')
print(album)
Album.write(album['id'], {'downloading': True})
download_album(album)
cron = BackgroundScheduler({'apscheduler.job_defaults.max_instances': 2}, daemon=True)
cron.add_job(process_downloads, 'interval', minutes=1)
cron.start()
@app.route('/api/v1/process/album')
def get_artist(path):
"""
Process for the requested Album
:param path: The Artist to get files for
:return: a status
"""
if path:
res = process_download(path)
else:
res = {'status': 501, 'message': 'Could not process download..'}
return res
@app.route('/api/v1/get/queue')
def get_queue():
album_ids = Album.search([('downloaded', '=', False)])
data = {}
if album_ids:
data.update({'album_ids': album_ids})
return render_template('download_queue.html', **data)
if __name__ == "__main__":
print('Starting App...')
app.run(host="0.0.0.0", debug=True)