Modifications
This commit is contained in:
parent
fab1815e7f
commit
433e219e62
63
app.py
63
app.py
@ -1,43 +1,18 @@
|
|||||||
from flask import Flask, request, redirect, url_for, send_file, render_template, send_from_directory
|
from flask import Flask, request, redirect, url_for, send_file, render_template, send_from_directory, jsonify
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os, logging, json
|
import os, logging, json, secrets
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.secret_key = secrets.token_hex(16)
|
||||||
|
|
||||||
#Page d'identification en cours de développement
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
# with open("identifiants.json") as f:
|
def download_file():
|
||||||
# identifiants = json.load(f)
|
session_id = secrets.token_hex(16)
|
||||||
|
|
||||||
def process_file(urls):
|
|
||||||
download_param_album = '{artist}/{album}/{artist} - {title}'
|
download_param_album = '{artist}/{album}/{artist} - {title}'
|
||||||
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
||||||
|
|
||||||
# Créer le dossier 'downloads' s'il n'existe pas
|
if request.method == 'POST':
|
||||||
if not os.path.exists('downloads'):
|
|
||||||
os.makedirs('downloads')
|
|
||||||
|
|
||||||
os.chdir('downloads')
|
|
||||||
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])
|
|
||||||
|
|
||||||
run(['zip', '-r', 'musics.zip', '.'])
|
|
||||||
os.chdir('../')
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
|
||||||
def upload_form():
|
|
||||||
return render_template('index.html')
|
|
||||||
|
|
||||||
@app.route('/download', methods=['POST'])
|
|
||||||
def download_file():
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
|
||||||
url1 = request.form['url1']
|
url1 = request.form['url1']
|
||||||
url2 = request.form['url2']
|
url2 = request.form['url2']
|
||||||
url3 = request.form['url3']
|
url3 = request.form['url3']
|
||||||
@ -50,9 +25,27 @@ def download_file():
|
|||||||
|
|
||||||
urls = [url1, url2, url3, url4, url5]
|
urls = [url1, url2, url3, url4, url5]
|
||||||
|
|
||||||
process_file(urls)
|
# Créer le dossier 'downloads' s'il n'existe pas
|
||||||
PATH = "downloads/musics.zip"
|
if not os.path.exists('downloads'):
|
||||||
return send_file(PATH, as_attachment=True)
|
os.makedirs('downloads')
|
||||||
|
|
||||||
|
os.chdir('downloads')
|
||||||
|
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])
|
||||||
|
|
||||||
|
run(['zip', '-r', 'musics.zip', '.'])
|
||||||
|
os.chdir('../')
|
||||||
|
|
||||||
|
PATH = "downloads/musics.zip"
|
||||||
|
return send_file(PATH, as_attachment=True)
|
||||||
|
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(error):
|
def page_not_found(error):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
function startDownload() {
|
function startDownload() {
|
||||||
document.getElementById('download-button').innerHTML = 'Téléchargement en cours...';
|
document.getElementById('download-button').innerHTML = 'Téléchargement en cours...';
|
||||||
}
|
}
|
||||||
function refreshPage() {
|
function refreshPage() {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
@ -15,7 +15,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<form action="/download" method="POST">
|
<form action="/" method="POST">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="text" class="form-control" name="url1" id="url1" pattern="^https://open\.spotify\.com/(?:album|playlist)/[\w-]+(?:\?si=[\w-]+)?$" placeholder="Entrez l'URL d'un Album ou d'une Playlist">
|
<input type="text" class="form-control" name="url1" id="url1" pattern="^https://open\.spotify\.com/(?:album|playlist)/[\w-]+(?:\?si=[\w-]+)?$" placeholder="Entrez l'URL d'un Album ou d'une Playlist">
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user