Compression des fichiers téléchargés dans downloads et possibilité de les télécharger

This commit is contained in:
Gu1llaum-3 2022-12-29 12:59:28 +01:00
parent 61c61d203b
commit b0225778a1
2 changed files with 11 additions and 21 deletions

30
app.py
View File

@ -25,14 +25,15 @@ def index():
return render_template('download_complete.html') return render_template('download_complete.html')
def process_file(url1, url2, url3, url4, url5): def process_file(url1, url2, url3, url4, url5):
path = os.path.expanduser('~/musics') path = os.path.expanduser('~/musics/downloads')
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}'
# Télécharger chaque URL s'il n'est pas vide # Télécharger chaque URL s'il n'est pas vide
if url1: if url1:
if "album" in url1: if "album" in url1:
os.chdir(f"{path}") #os.makedirs(f'{path}/download-1', exist_ok=True)
os.chdir(f'{path}')
os.system(f'python3 -m spotdl {url1} --output "{download_param_album}"') os.system(f'python3 -m spotdl {url1} --output "{download_param_album}"')
elif "playlist" in url1: elif "playlist" in url1:
os.chdir(f"{path}") os.chdir(f"{path}")
@ -69,27 +70,14 @@ def process_file(url1, url2, url3, url4, url5):
elif "playlist" in url5: elif "playlist" in url5:
os.chdir(f"{path}") os.chdir(f"{path}")
os.system(f'python3 -m spotdl {url5} --output "{download_param_playlist}"') os.system(f'python3 -m spotdl {url5} --output "{download_param_playlist}"')
# def process_file(url):
# path = os.path.expanduser('~/musics')
# download_param_album = '{artist}/{album}/{artist} - {title}'
# download_param_playlist = '{playlist}/{artists}/{album} - {title} {artist}'
# if "album" in url:
# #os.makedirs(f"{path}")
# os.chdir(f"{path}")
# print ("album found")
# os.system(f'python3 -m spotdl {url} --output "{download_param_album}"')
# elif "playlist" in url:
# os.chdir(f"{path}")
# print("playlist found")
# os.system(f'python3 -m spotdl {url} --output "{download_param_playlist}"')
os.chdir(f'{path}')
os.system(f'zip -r musics.zip ./')
# @app.route('/download/<path:filename>') @app.route('/download', methods=['GET'])
# def download_file(filename): def download():
# return send_file(filename, attachment_filename=filename, as_attachment=True) PATH='/home/gu1ll4um3/musics/downloads/musics.zip'
return send_file(PATH,as_attachment=True)
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True, port=3000) app.run(debug=True, port=3000)

View File

@ -6,5 +6,7 @@
<body> <body>
<h1> SpotDL Web </h1> <h1> SpotDL Web </h1>
<h2> Téléchargement Terminé </h2> <h2> Téléchargement Terminé </h2>
<!-- <a class="btn btn-success" href="{{url_for('download')}}">Download</a> -->
<button onclick="window.location.href ='{{url_for('download')}}';">Download</button>
<button onclick="window.location.href = '/';">Télécharger à nouveau</button> <button onclick="window.location.href = '/';">Télécharger à nouveau</button>
</body> </body>