parent
842e440bd2
commit
bb0b800fa2
@ -1,16 +1,24 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||||
|
use App\Http\Middleware\DisableCsrf;
|
||||||
use App\Http\Controllers\ApiController;
|
use App\Http\Controllers\ApiController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('pages.main');
|
return view('pages.main');
|
||||||
});
|
});
|
||||||
|
// User submitted input to scrape for artist data
|
||||||
Route::get('/artist/{artist}', [ApiController::class, 'search_artist'])->name('api.search.artist');
|
Route::get('/artist/{artist}', [ApiController::class, 'search_artist'])->name('api.search.artist');
|
||||||
|
// Return list of all artists in database
|
||||||
// Get all artists
|
|
||||||
Route::get('api/artists/', [ApiController::class, 'get_artists'])->name('api.artist');
|
Route::get('api/artists/', [ApiController::class, 'get_artists'])->name('api.artist');
|
||||||
|
// Add artist to queue
|
||||||
// Queue single artist
|
|
||||||
Route::get('api/queue/artist/{id}', [ApiController::class, 'queue_artist'])->name('api.artist.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/
|
!public/
|
||||||
|
!music/
|
||||||
!.gitignore
|
!.gitignore
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
@ -1,58 +1,39 @@
|
|||||||
import json
|
import json
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from flask import Flask, render_template
|
from flask import Flask
|
||||||
from redis import Redis
|
from redis import Redis
|
||||||
from utils.download import download_album
|
from utils.download import download_album
|
||||||
from utils.processor import process_download
|
import requests
|
||||||
|
|
||||||
|
import logging
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
redis = Redis(host='redis', port=6379)
|
redis = Redis(host='redis', port=6379)
|
||||||
|
|
||||||
|
|
||||||
def process_downloads():
|
# def process_artist_queue():
|
||||||
print('Processing Downloads..')
|
# requests.get('http://nginx/api/queue/artists/run')
|
||||||
pending_downloads = Album.search([('downloaded', '=', False), ('downloading', '=', False)])
|
# return
|
||||||
if pending_downloads:
|
|
||||||
ready_album = pending_downloads[:1]
|
def process_album_queue():
|
||||||
if ready_album:
|
print('Running Album Queue Process..')
|
||||||
album = ready_album[0]
|
print('---')
|
||||||
print('...................')
|
response = requests.get('http://nginx/api/album/queue')
|
||||||
print('Downloading Album..')
|
data = response.json()
|
||||||
print(album)
|
artist = data.get('artist')
|
||||||
Album.write(album['id'], {'downloading': True})
|
album = data.get('album')
|
||||||
download_album(album)
|
queue = data.get('queue')
|
||||||
|
if artist and album and queue:
|
||||||
|
result = download_album(album, artist)
|
||||||
cron = BackgroundScheduler({'apscheduler.job_defaults.max_instances': 2}, daemon=True)
|
requests.post('http://nginx/api/album/queue/update/%s' % queue.get('id'), json=result)
|
||||||
cron.add_job(process_downloads, 'interval', minutes=1)
|
return
|
||||||
|
|
||||||
|
cron = BackgroundScheduler({'apscheduler.job_defaults.max_instances': 1}, daemon=True)
|
||||||
|
cron.add_job(process_album_queue, 'interval', minutes=1)
|
||||||
cron.start()
|
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__":
|
if __name__ == "__main__":
|
||||||
print('Starting App...')
|
print('Starting App...')
|
||||||
app.run(host="0.0.0.0", debug=True)
|
app.run(host="0.0.0.0", debug=True)
|
||||||
|
|||||||
Loading…
Reference in new issue