Ajout update nextcloud file index
This commit is contained in:
@@ -4,8 +4,8 @@ from os.path import basename
|
||||
import mpd
|
||||
import platform
|
||||
from zipfile import ZipFile, ZIP_DEFLATED
|
||||
from flask import session
|
||||
|
||||
from deezer_downloader.update_nextcloud_files import call_scan
|
||||
from deezer_downloader.configuration import config
|
||||
from deezer_downloader.youtubedl import youtubedl_download
|
||||
from deezer_downloader.spotify import get_songs_from_spotify_website
|
||||
@@ -17,16 +17,17 @@ from deezer_downloader.threadpool_queue import ThreadpoolScheduler, report_progr
|
||||
sched = ThreadpoolScheduler()
|
||||
|
||||
|
||||
def check_and_set_download_dirs_exist():
|
||||
config["download_dirs"]["songs"] = os.path.join(session['user_base_dir'], "DeezerDownload", "songs")
|
||||
config["download_dirs"]["zips"] = os.path.join(session['user_base_dir'], "DeezerDownload","zips")
|
||||
config["download_dirs"]["albums"] = os.path.join(session['user_base_dir'], "DeezerDownload","albums")
|
||||
config["download_dirs"]["playlists"] = os.path.join(session['user_base_dir'], "DeezerDownload","playlists")
|
||||
config["download_dirs"]["youtubedl"] = os.path.join(session['user_base_dir'], "DeezerDownload","youtubedl")
|
||||
def check_and_set_download_dirs_exist(uid_user):
|
||||
config["download_dirs"]["songs"] = config["download_dirs"]["songs"].format(uid=uid_user)
|
||||
config["download_dirs"]["zips"] = config["download_dirs"]["zips"].format(uid=uid_user)
|
||||
config["download_dirs"]["albums"] = config["download_dirs"]["albums"].format(uid=uid_user)
|
||||
config["download_dirs"]["playlists"] = config["download_dirs"]["playlists"].format(uid=uid_user)
|
||||
config["download_dirs"]["youtubedl"] = config["download_dirs"]["youtubedl"].format(uid=uid_user)
|
||||
for directory in [config["download_dirs"]["songs"], config["download_dirs"]["zips"], config["download_dirs"]["albums"],
|
||||
config["download_dirs"]["playlists"], config["download_dirs"]["youtubedl"]]:
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
|
||||
|
||||
def make_song_paths_relative_to_mpd_root(songs, prefix=""):
|
||||
# ensure last slash
|
||||
config["mpd"]["music_dir_root"] = os.path.join(config["mpd"]["music_dir_root"], '')
|
||||
@@ -118,7 +119,8 @@ def download_song_and_get_absolute_filename(search_type, song, playlist_name=Non
|
||||
return absolute_filename
|
||||
|
||||
|
||||
def create_zip_file(songs_absolute_location):
|
||||
def create_zip_file(songs_absolute_location, uid_user):
|
||||
check_and_set_download_dirs_exist(uid_user)
|
||||
# take first song in list and take the parent dir (name of album/playlist")
|
||||
parent_dir = basename(os.path.dirname(songs_absolute_location[0]))
|
||||
location_zip_file = os.path.join(config["download_dirs"]["zips"], "{}.zip".format(parent_dir))
|
||||
@@ -130,6 +132,7 @@ def create_zip_file(songs_absolute_location):
|
||||
zip.write(song_location, arcname=os.path.join(parent_dir, basename(song_location)))
|
||||
except FileNotFoundError:
|
||||
print("Could not find file '{}'".format(song_location))
|
||||
call_scan(location_zip_file)
|
||||
print("Done with the zip")
|
||||
return location_zip_file
|
||||
|
||||
@@ -150,10 +153,12 @@ def create_m3u8_file(songs_absolute_location):
|
||||
|
||||
|
||||
@sched.register_command()
|
||||
def download_deezer_song_and_queue(track_id, add_to_playlist):
|
||||
def download_deezer_song_and_queue(track_id, add_to_playlist, uid_user):
|
||||
check_and_set_download_dirs_exist(uid_user)
|
||||
song = get_song_infos_from_deezer_website(TYPE_TRACK, track_id)
|
||||
try:
|
||||
absolute_filename = download_song_and_get_absolute_filename(TYPE_TRACK, song)
|
||||
call_scan(absolute_filename)
|
||||
update_mpd_db(absolute_filename, add_to_playlist)
|
||||
return make_song_paths_relative_to_mpd_root([absolute_filename])
|
||||
except DeezerApiException:
|
||||
@@ -162,7 +167,8 @@ def download_deezer_song_and_queue(track_id, add_to_playlist):
|
||||
|
||||
|
||||
@sched.register_command()
|
||||
def download_deezer_album_and_queue_and_zip(album_id, add_to_playlist, create_zip):
|
||||
def download_deezer_album_and_queue_and_zip(album_id, add_to_playlist, create_zip, uid_user):
|
||||
check_and_set_download_dirs_exist(uid_user)
|
||||
songs = get_song_infos_from_deezer_website(TYPE_ALBUM, album_id)
|
||||
songs_absolute_location = []
|
||||
for i, song in enumerate(songs):
|
||||
@@ -173,14 +179,16 @@ def download_deezer_album_and_queue_and_zip(album_id, add_to_playlist, create_zi
|
||||
songs_absolute_location.append(absolute_filename)
|
||||
except Exception as e:
|
||||
print(f"Warning: {e}. Continuing with album...")
|
||||
call_scan(songs_absolute_location)
|
||||
update_mpd_db(songs_absolute_location, add_to_playlist)
|
||||
if create_zip:
|
||||
return [create_zip_file(songs_absolute_location)]
|
||||
return [create_zip_file(songs_absolute_location, uid_user)]
|
||||
return make_song_paths_relative_to_mpd_root(songs_absolute_location)
|
||||
|
||||
|
||||
@sched.register_command()
|
||||
def download_deezer_playlist_and_queue_and_zip(playlist_id, add_to_playlist, create_zip):
|
||||
def download_deezer_playlist_and_queue_and_zip(playlist_id, add_to_playlist, create_zip, uid_user):
|
||||
check_and_set_download_dirs_exist(uid_user)
|
||||
playlist_name, songs = parse_deezer_playlist(playlist_id)
|
||||
songs_absolute_location = []
|
||||
for i, song in enumerate(songs):
|
||||
@@ -192,13 +200,15 @@ def download_deezer_playlist_and_queue_and_zip(playlist_id, add_to_playlist, cre
|
||||
print(f"Warning: {e}. Continuing with playlist...")
|
||||
update_mpd_db(songs_absolute_location, add_to_playlist)
|
||||
songs_with_m3u8_file = create_m3u8_file(songs_absolute_location)
|
||||
call_scan(songs_absolute_location)
|
||||
if create_zip:
|
||||
return [create_zip_file(songs_with_m3u8_file)]
|
||||
return [create_zip_file(songs_with_m3u8_file, uid_user)]
|
||||
return make_song_paths_relative_to_mpd_root(songs_absolute_location)
|
||||
|
||||
|
||||
@sched.register_command()
|
||||
def download_spotify_playlist_and_queue_and_zip(playlist_name, playlist_id, add_to_playlist, create_zip):
|
||||
def download_spotify_playlist_and_queue_and_zip(playlist_name, playlist_id, add_to_playlist, create_zip, uid_user):
|
||||
check_and_set_download_dirs_exist(uid_user)
|
||||
songs = get_songs_from_spotify_website(playlist_id,
|
||||
config["proxy"]["server"])
|
||||
songs_absolute_location = []
|
||||
@@ -215,22 +225,26 @@ def download_spotify_playlist_and_queue_and_zip(playlist_name, playlist_id, add_
|
||||
print(f"Warning: Could not download Spotify song ({song_of_playlist}) on Deezer: {e}")
|
||||
update_mpd_db(songs_absolute_location, add_to_playlist)
|
||||
songs_with_m3u8_file = create_m3u8_file(songs_absolute_location)
|
||||
call_scan(songs_absolute_location)
|
||||
if create_zip:
|
||||
return [create_zip_file(songs_with_m3u8_file)]
|
||||
return [create_zip_file(songs_with_m3u8_file, uid_user)]
|
||||
return make_song_paths_relative_to_mpd_root(songs_absolute_location)
|
||||
|
||||
|
||||
@sched.register_command()
|
||||
def download_youtubedl_and_queue(video_url, add_to_playlist):
|
||||
def download_youtubedl_and_queue(video_url, add_to_playlist, uid_user):
|
||||
check_and_set_download_dirs_exist(uid_user)
|
||||
filename_absolute = youtubedl_download(video_url,
|
||||
config["download_dirs"]["youtubedl"],
|
||||
config["proxy"]["server"])
|
||||
call_scan(filename_absolute)
|
||||
update_mpd_db(filename_absolute, add_to_playlist)
|
||||
return make_song_paths_relative_to_mpd_root([filename_absolute])
|
||||
|
||||
|
||||
@sched.register_command()
|
||||
def download_deezer_favorites(user_id: str, add_to_playlist: bool, create_zip: bool):
|
||||
def download_deezer_favorites(user_id: str, add_to_playlist: bool, create_zip: bool, uid_user):
|
||||
check_and_set_download_dirs_exist(uid_user)
|
||||
songs_absolute_location = []
|
||||
output_directory = f"favorites_{user_id}"
|
||||
favorite_songs = get_deezer_favorites(user_id)
|
||||
@@ -248,8 +262,9 @@ def download_deezer_favorites(user_id: str, add_to_playlist: bool, create_zip: b
|
||||
print(f"Could not find song ({fav_song}) on Deezer?")
|
||||
update_mpd_db(songs_absolute_location, add_to_playlist)
|
||||
songs_with_m3u8_file = create_m3u8_file(songs_absolute_location)
|
||||
call_scan(songs_absolute_location)
|
||||
if create_zip:
|
||||
return [create_zip_file(songs_with_m3u8_file)]
|
||||
return [create_zip_file(songs_with_m3u8_file, uid_user)]
|
||||
return make_song_paths_relative_to_mpd_root(songs_absolute_location)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user