diff --git a/.drone.yml b/.drone.yml index 3a5e54f..15dd0b2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -41,6 +41,7 @@ steps: commands: - curl -d "La pipeline a réussi" $NOTIFY_URL when: + branch: main status: [ success ] - name: notify_failure @@ -51,4 +52,42 @@ steps: commands: - curl -d "La pipeline a échoué" $NOTIFY_URL when: + branch: main + status: [failure] + +- name: docker_gitea + image: plugins/docker + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: git.netpowa.fr/guillaume/spotdlweb + # auto_tag: true + registry: git.netpowa.fr + tags: + - beta + when: + branch: dev + +- name: notify_success + image: curlimages/curl + environment: + NOTIFY_URL: + from_secret: ntfy_url + commands: + - curl -d "La pipeline dev a réussi" $NOTIFY_URL + when: + branch: dev + status: [ success ] + +- name: notify_failure + image: curlimages/curl + environment: + NOTIFY_URL: + from_secret: ntfy_url + commands: + - curl -d "La pipeline dev a échoué" $NOTIFY_URL + when: + branch: dev status: [failure] \ No newline at end of file diff --git a/app.py b/app.py index bf603f1..1c21559 100644 --- a/app.py +++ b/app.py @@ -28,6 +28,27 @@ def process_file(urls): os.chdir('../') +def process_file_local(urls): + download_param_album = '{artist}/{album}/{artist} - {title}' + download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}' + download_param_track = '{artist}/{album}/{artist} - {title}' + + os.chdir('temp') + os.system(f'rm -rf *') + + for url in urls: + if url: + if "album" in url: + run(['python3', '-m', 'spotdl', url, '--output', download_param_album]) + elif "playlist" in url: + run(['python3', '-m', 'spotdl', url, '--output', download_param_playlist]) + elif "track" in url: + run(['python3', '-m', 'spotdl', url, '--output', download_param_track]) + + run(['zip', '-r', 'musics.zip', '.']) + os.chdir('../') + + @app.route('/', methods=['GET', 'POST']) def upload_form(): return render_template('index.html') @@ -41,34 +62,43 @@ def upload_form(): @app.route('/download', methods=['POST']) def download_file(): - # votre code de téléchargement ici - # now = datetime.now() - # date_time = now.strftime("%Y-%m-%d %H-%M-%S") - # with open(f"file.txt", "w") as file: - # file.write(date_time) if request.method == 'POST': + action = request.form.get('action') url1 = request.form['url1'] url2 = request.form['url2'] url3 = request.form['url3'] - url4 = request.form['url4'] - url5 = request.form['url5'] - urls = [url1, url2, url3, url4, url5] + urls = [url1, url2, url3] # Vérifier si au moins un champ est vide - if not url1 and not url2 and not url3 and not url4 and not url5: + if not url1 and not url2 and not url3 : return render_template('erreur.html') + if action == 'download': # Créer le dossier 'downloads' s'il n'existe pas - if not os.path.exists('downloads'): - os.makedirs('downloads') + if not os.path.exists('downloads'): + os.makedirs('downloads') - process_file(urls) + process_file(urls) - # path = "downloads/musics.zip" - # return send_file(path, as_attachment=True) - return render_template('finish.html') + # path = "downloads/musics.zip" + # return send_file(path, as_attachment=True) + return render_template('finish_server.html') + + if action == 'downloadlocal': + # Créer le dossier 'downloads' s'il n'existe pas + if not os.path.exists('temp'): + os.makedirs('temp') + + process_file_local(urls) + + return render_template('finish_local.html') + +@app.route('/zip', methods=['GET', 'POST']) +def zip(): + path = "temp/musics.zip" + return send_file(path, as_attachment=True) @app.errorhandler(404) def page_not_found(error): # error est necessaire diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..3c965b8 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,11 @@ +version: '3.3' +services: + spotdlweb: + image: gu1llaum3/spotdlweb:latest + container_name: spotdlweb + hostname: spotdlweb + ports: + - 3000:3000 + volumes: + - ./musics:/app/downloads + restart: unless-stopped \ No newline at end of file diff --git a/static/js/script.js b/static/js/script.js index c2d5ff0..01d0a7d 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -1,6 +1,9 @@ function startDownload() { document.getElementById('download-button').innerHTML = 'Téléchargement en cours...'; } +function startLocalDownload() { + document.getElementById('downloadlocal-button').innerHTML = 'Téléchargement en cours...'; + } function refreshPage() { window.location.reload(); } \ No newline at end of file diff --git a/templates/finish_local.html b/templates/finish_local.html new file mode 100644 index 0000000..ff989f6 --- /dev/null +++ b/templates/finish_local.html @@ -0,0 +1,19 @@ +{% extends 'layout.html' %} + +{% block body %} + +
+{{ message }}
+ {% endif %} +