Ajout d'une procédure pour télécharger un album ou une playlist, modification des champs url, ajout de la suppression du contenu du dossier downloads en début de script
This commit is contained in:
parent
b0225778a1
commit
b764f652c0
75
app.py
75
app.py
@ -7,6 +7,25 @@ app = Flask(__name__)
|
||||
def upload_form():
|
||||
return render_template('upload.html')
|
||||
|
||||
def process_file(urls):
|
||||
# path = os.path.expanduser('~/musics/downloads')
|
||||
path = './downloads'
|
||||
download_param_album = '{artist}/{album}/{artist} - {title}'
|
||||
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
||||
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'rm -rf *')
|
||||
|
||||
for url in urls:
|
||||
if url:
|
||||
if "album" in url:
|
||||
os.system(f'python3 -m spotdl {url} --output "{download_param_album}"')
|
||||
elif "playlist" in url:
|
||||
os.system(f'python3 -m spotdl {url} --output "{download_param_playlist}"')
|
||||
|
||||
|
||||
os.system(f'zip -r musics.zip ./')
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
message = None
|
||||
@ -21,62 +40,14 @@ def index():
|
||||
if not url1 and not url2 and not url3 and not url4 and not url5:
|
||||
return render_template('erreur.html')
|
||||
|
||||
result = process_file(url1, url2, url3, url4, url5)
|
||||
urls = [url1, url2, url3, url4, url5]
|
||||
result = process_file(urls)
|
||||
return render_template('download_complete.html')
|
||||
|
||||
def process_file(url1, url2, url3, url4, url5):
|
||||
path = os.path.expanduser('~/musics/downloads')
|
||||
download_param_album = '{artist}/{album}/{artist} - {title}'
|
||||
download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
|
||||
|
||||
# Télécharger chaque URL s'il n'est pas vide
|
||||
if url1:
|
||||
if "album" in url1:
|
||||
#os.makedirs(f'{path}/download-1', exist_ok=True)
|
||||
os.chdir(f'{path}')
|
||||
os.system(f'python3 -m spotdl {url1} --output "{download_param_album}"')
|
||||
elif "playlist" in url1:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url1} --output "{download_param_playlist}"')
|
||||
|
||||
if url2:
|
||||
if "album" in url2:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url2} --output "{download_param_album}"')
|
||||
elif "playlist" in url2:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url2} --output "{download_param_playlist}"')
|
||||
|
||||
if url3:
|
||||
if "album" in url3:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url3} --output "{download_param_album}"')
|
||||
elif "playlist" in url3:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url3} --output "{download_param_playlist}"')
|
||||
|
||||
if url4:
|
||||
if "album" in url4:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url4} --output "{download_param_album}"')
|
||||
elif "playlist" in url4:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url4} --output "{download_param_playlist}"')
|
||||
|
||||
if url5:
|
||||
if "album" in url5:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url5} --output "{download_param_album}"')
|
||||
elif "playlist" in url5:
|
||||
os.chdir(f"{path}")
|
||||
os.system(f'python3 -m spotdl {url5} --output "{download_param_playlist}"')
|
||||
|
||||
os.chdir(f'{path}')
|
||||
os.system(f'zip -r musics.zip ./')
|
||||
|
||||
@app.route('/download', methods=['GET'])
|
||||
def download():
|
||||
PATH='/home/gu1ll4um3/musics/downloads/musics.zip'
|
||||
# PATH='/home/gu1ll4um3/musics/downloads/musics.zip'
|
||||
PATH='./downloads/musics.zip'
|
||||
return send_file(PATH,as_attachment=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
BIN
downloads/Jerry Manoukian/Romance/Jerry Manoukian - Romance.mp3
Normal file
BIN
downloads/Jerry Manoukian/Romance/Jerry Manoukian - Romance.mp3
Normal file
Binary file not shown.
BIN
downloads/musics.zip
Normal file
BIN
downloads/musics.zip
Normal file
Binary file not shown.
@ -27,6 +27,15 @@ h2 {
|
||||
color: white
|
||||
}
|
||||
|
||||
div {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
/* align-items: center; */
|
||||
/* min-height:100%; */
|
||||
background-color: black;
|
||||
color: white
|
||||
}
|
||||
|
||||
|
||||
input[type="submit"] {
|
||||
display: block;
|
||||
|
@ -5,34 +5,37 @@
|
||||
</head>
|
||||
|
||||
<h1>SpotDL Web</h1>
|
||||
<div class="url">
|
||||
<div><a href="https://open.spotify.com/" style="color:white;" target="_blank">Aller sur Spotify</a></div>
|
||||
<div> - Chercher un album ou une playlist</div>
|
||||
<div> - Copier le ou les lien(s) url ci-dessous</div>
|
||||
<div class="url" style="padding-top: 10px;">
|
||||
<form method="POST">
|
||||
<!-- <label for="url">URL:</label>
|
||||
<input type="text" name="url" id="url"> -->
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
<label for="url1">URL 1:</label>
|
||||
<input type="text" name="url1" id="url1">
|
||||
<!-- <label for="url1">URL 1:</label> -->
|
||||
<input type="text" name="url1" id="url1" placeholder="URL">
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
<label for="url2">URL 2:</label>
|
||||
<input type="text" name="url2" id="url2">
|
||||
<!-- <label for="url2">URL 2:</label> -->
|
||||
<input type="text" name="url2" id="url2" placeholder="URL">
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
<label for="url3">URL 3:</label>
|
||||
<input type="text" name="url3" id="url3">
|
||||
<!-- <label for="url3">URL 3:</label> -->
|
||||
<input type="text" name="url3" id="url3" placeholder="URL">
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
<label for="url4">URL 4:</label>
|
||||
<input type="text" name="url4" id="url4">
|
||||
<!-- <label for="url4">URL 4:</label> -->
|
||||
<input type="text" name="url4" id="url4" placeholder="URL">
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
<label for="url5">URL 5:</label>
|
||||
<input type="text" name="url5" id="url5">
|
||||
<!-- <label for="url5">URL 5:</label> -->
|
||||
<input type="text" name="url5" id="url5" placeholder="URL">
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
|
Loading…
x
Reference in New Issue
Block a user