parent
842e440bd2
commit
bb0b800fa2
@ -1,16 +1,24 @@
|
||||
<?php
|
||||
|
||||
use \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
use App\Http\Middleware\DisableCsrf;
|
||||
use App\Http\Controllers\ApiController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('pages.main');
|
||||
});
|
||||
|
||||
// User submitted input to scrape for artist data
|
||||
Route::get('/artist/{artist}', [ApiController::class, 'search_artist'])->name('api.search.artist');
|
||||
|
||||
// Get all artists
|
||||
// Return list of all artists in database
|
||||
Route::get('api/artists/', [ApiController::class, 'get_artists'])->name('api.artist');
|
||||
|
||||
// Queue single artist
|
||||
// Add artist to queue
|
||||
Route::get('api/queue/artist/{id}', [ApiController::class, 'queue_artist'])->name('api.artist.queue');
|
||||
// Returns a single album that is ready for download
|
||||
Route::get('api/album/queue', [ApiController::class, 'queue_waiting'])->name('api.queue.waiting');
|
||||
// Update the queue from handler
|
||||
Route::post('api/album/queue/update/{id}', [ApiController::class, 'queue_update'])->name('api.queue.update')->withoutMiddleware(VerifyCsrfToken::class);
|
||||
// Prompt the artist queue remotely
|
||||
Route::get('api/queue/artists/run', [ApiController::class, 'queue_artist_run'])->name('api.queue.run');
|
||||
// Client side queue data
|
||||
Route::get('/api/queue/albums', [ApiController::class, 'get_album_queue'])->name('api.queue.albums');
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
*
|
||||
!public/
|
||||
!music/
|
||||
!.gitignore
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@ -1,58 +1,39 @@
|
||||
import json
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask
|
||||
from redis import Redis
|
||||
from utils.download import download_album
|
||||
from utils.processor import process_download
|
||||
import requests
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
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)
|
||||
# def process_artist_queue():
|
||||
# requests.get('http://nginx/api/queue/artists/run')
|
||||
# return
|
||||
|
||||
def process_album_queue():
|
||||
print('Running Album Queue Process..')
|
||||
print('---')
|
||||
response = requests.get('http://nginx/api/album/queue')
|
||||
data = response.json()
|
||||
artist = data.get('artist')
|
||||
album = data.get('album')
|
||||
queue = data.get('queue')
|
||||
if artist and album and queue:
|
||||
result = download_album(album, artist)
|
||||
requests.post('http://nginx/api/album/queue/update/%s' % queue.get('id'), json=result)
|
||||
return
|
||||
|
||||
cron = BackgroundScheduler({'apscheduler.job_defaults.max_instances': 1}, daemon=True)
|
||||
cron.add_job(process_album_queue, '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)
|
||||
|
||||
Loading…
Reference in new issue