Ajout des fonctionnalitée pour nextcloud
This commit is contained in:
@@ -16,7 +16,7 @@ def load_config(config_abs):
|
|||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read(config_abs)
|
config.read(config_abs)
|
||||||
|
|
||||||
assert list(config.keys()) == ['DEFAULT', 'mpd', 'download_dirs', 'debug', 'http', 'proxy', 'threadpool', 'deezer', 'youtubedl'], f"Validating config file failed. Check {config_abs}"
|
assert list(config.keys()) == ['DEFAULT', 'mpd', 'download_dirs', 'debug', 'http', 'proxy', 'threadpool', 'deezer', 'youtubedl', 'nextcloud', 'nextcloud_ssh_scan_files'], f"Validating config file failed. Check {config_abs}"
|
||||||
|
|
||||||
if config['mpd'].getboolean('use_mpd'):
|
if config['mpd'].getboolean('use_mpd'):
|
||||||
if not config['mpd']['music_dir_root'].startswith(config['download_dirs']['base']):
|
if not config['mpd']['music_dir_root'].startswith(config['download_dirs']['base']):
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from mutagen.flac import FLAC, Picture
|
|||||||
from mutagen.mp3 import MP3
|
from mutagen.mp3 import MP3
|
||||||
from mutagen.id3 import PictureType, TIT2, TALB, TPE1, TRCK, TDRC, TPOS, APIC, TPE2
|
from mutagen.id3 import PictureType, TIT2, TALB, TPE1, TRCK, TDRC, TPOS, APIC, TPE2
|
||||||
from mutagen import MutagenError
|
from mutagen import MutagenError
|
||||||
|
from deezer_downloader.update_nextcloud_files import call_scan
|
||||||
|
|
||||||
|
|
||||||
# BEGIN TYPES
|
# BEGIN TYPES
|
||||||
@@ -244,6 +245,8 @@ def download_song(song: dict, output_file: str) -> None:
|
|||||||
print(f"Warning: Could not write metadata to file: {e}")
|
print(f"Warning: Could not write metadata to file: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise DeezerApiException(f"Could not write song to disk: {e}") from e
|
raise DeezerApiException(f"Could not write song to disk: {e}") from e
|
||||||
|
|
||||||
|
call_scan(output_file)
|
||||||
print("Download finished: {}".format(output_file))
|
print("Download finished: {}".format(output_file))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
69
deezer_downloader/nextcloud.py
Normal file
69
deezer_downloader/nextcloud.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import jwt # PyJWT
|
||||||
|
from jwt import InvalidTokenError
|
||||||
|
from jwt import ExpiredSignatureError
|
||||||
|
import os
|
||||||
|
from flask import jsonify, abort, session
|
||||||
|
from deezer_downloader.configuration import config
|
||||||
|
|
||||||
|
#def setJwtInCookieToResponse(request, response):
|
||||||
|
# jwt_token = request.args.get("jwt")
|
||||||
|
# if not jwt_token:
|
||||||
|
# return response
|
||||||
|
#
|
||||||
|
# response.set_cookie(
|
||||||
|
# "access_token",
|
||||||
|
# jwt_token,
|
||||||
|
# max_age=60*60*24,
|
||||||
|
# httponly=True,
|
||||||
|
# secure=True # True si HTTPS
|
||||||
|
# )
|
||||||
|
# return response
|
||||||
|
|
||||||
|
def addJwtInUserSession(request):
|
||||||
|
if 'user_uid' in session:
|
||||||
|
return
|
||||||
|
|
||||||
|
jwt_token = request.args.get(config["nextcloud"]["jwt_name_parameter"])
|
||||||
|
if not jwt_token:
|
||||||
|
return abort(403)
|
||||||
|
|
||||||
|
try:
|
||||||
|
decoded = jwt.decode(jwt_token, config["nextcloud"]["public_key"], algorithms=["ES256"])
|
||||||
|
iss = decoded.get("iss")
|
||||||
|
iat = decoded.get("iat")
|
||||||
|
exp = decoded.get("exp")
|
||||||
|
userdata = decoded.get("userdata", {})
|
||||||
|
email = userdata.get("email")
|
||||||
|
uid = userdata.get("uid")
|
||||||
|
display_name = userdata.get("displayName")
|
||||||
|
|
||||||
|
print("✅ JWT décodé :")
|
||||||
|
print("Iss:", iss)
|
||||||
|
print("Issued At:", iat)
|
||||||
|
print("Expires:", exp)
|
||||||
|
print("Email:", email)
|
||||||
|
print("UID:", uid)
|
||||||
|
print("Display Name:", display_name)
|
||||||
|
|
||||||
|
#base_dir_user = base_dir.format(user=uid)
|
||||||
|
#config["download_dirs"]["base"] = base_dir_user
|
||||||
|
|
||||||
|
session['user_uid'] = uid
|
||||||
|
session['user_email'] = email
|
||||||
|
session['user_displayName'] = display_name
|
||||||
|
session['user_base_dir'] = config["download_dirs"]["base"] + "\\" + uid
|
||||||
|
#createDownloadDirectoriesIfNotExist()
|
||||||
|
|
||||||
|
print(f"✅ Download base dir set to: {session['user_base_dir']}")
|
||||||
|
except ExpiredSignatureError:
|
||||||
|
return jsonify({"error": "Token expired"}), 401
|
||||||
|
except InvalidTokenError as e:
|
||||||
|
print("❌ Erreur de validation du token :", e)
|
||||||
|
|
||||||
|
def createDownloadDirectoriesIfNotExist():
|
||||||
|
os.makedirs(config["download_dirs"]["base"], exist_ok=True)
|
||||||
|
os.makedirs(config["download_dirs"]["songs"], exist_ok=True)
|
||||||
|
os.makedirs(config["download_dirs"]["albums"], exist_ok=True)
|
||||||
|
os.makedirs(config["download_dirs"]["zips"], exist_ok=True)
|
||||||
|
os.makedirs(config["download_dirs"]["playlists"], exist_ok=True)
|
||||||
|
os.makedirs(config["download_dirs"]["youtubedl"], exist_ok=True)
|
||||||
35
deezer_downloader/update_nextcloud_files.py
Normal file
35
deezer_downloader/update_nextcloud_files.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import paramiko
|
||||||
|
import os
|
||||||
|
from deezer_downloader.configuration import config
|
||||||
|
|
||||||
|
def call_scan(directory_path):
|
||||||
|
if not config['nextcloud_ssh_scan_files']['host']:
|
||||||
|
return
|
||||||
|
host = config['nextcloud_ssh_scan_files']['host']
|
||||||
|
port = config['nextcloud_ssh_scan_files']['port']
|
||||||
|
username = config['nextcloud_ssh_scan_files']['username']
|
||||||
|
password = config['nextcloud_ssh_scan_files']['password']
|
||||||
|
|
||||||
|
directory_path = os.path.dirname(directory_path)
|
||||||
|
directory_path = directory_path.replace(config['download_dirs']['base'] + "\\", "")
|
||||||
|
print("Path Nexcloud Scan " + directory_path)
|
||||||
|
# Commande à exécuter
|
||||||
|
cmd = 'sudo /home/nextclouddeezer/scan_deezerDl_folder.sh "{dir}"'.format(dir=directory_path)
|
||||||
|
|
||||||
|
# Création de la connexion SSH
|
||||||
|
ssh = paramiko.SSHClient()
|
||||||
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # accepter clés inconnues
|
||||||
|
ssh.connect(hostname=host, port=port, username=username, password=password)
|
||||||
|
|
||||||
|
# Exécuter la commande
|
||||||
|
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||||
|
|
||||||
|
# Afficher les résultats
|
||||||
|
print("STDOUT:")
|
||||||
|
print(stdout.read().decode())
|
||||||
|
|
||||||
|
print("STDERR:")
|
||||||
|
print(stderr.read().decode())
|
||||||
|
|
||||||
|
# Fermer la connexion
|
||||||
|
ssh.close()
|
||||||
@@ -4,17 +4,19 @@ from subprocess import Popen, PIPE
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
import requests
|
import requests
|
||||||
import atexit
|
import atexit
|
||||||
from flask import Flask, render_template, request, jsonify
|
from flask import Flask, render_template, request, jsonify, session, make_response
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
from flask_autoindex import AutoIndex
|
from flask_autoindex import AutoIndex
|
||||||
import warnings
|
import warnings
|
||||||
import giphypop
|
import giphypop
|
||||||
|
|
||||||
from deezer_downloader.configuration import config
|
from deezer_downloader.configuration import config
|
||||||
from deezer_downloader.web.music_backend import sched
|
from deezer_downloader.web.music_backend import sched, check_and_set_download_dirs_exist
|
||||||
from deezer_downloader.deezer import deezer_search, init_deezer_session
|
from deezer_downloader.deezer import deezer_search, init_deezer_session
|
||||||
|
from deezer_downloader.nextcloud import addJwtInUserSession
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.secret_key = "vilvhmqerjgùqrgojpùqjgvnùzevoijrpùvqpzejgijzepgùg"
|
||||||
auto_index = AutoIndex(app, config["download_dirs"]["base"], add_url_rules=False)
|
auto_index = AutoIndex(app, config["download_dirs"]["base"], add_url_rules=False)
|
||||||
auto_index.add_icon_rule('music.png', ext='m3u8')
|
auto_index.add_icon_rule('music.png', ext='m3u8')
|
||||||
|
|
||||||
@@ -82,6 +84,9 @@ def validate_schema(*parameters_to_check):
|
|||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def beforeRequest():
|
||||||
|
addJwtInUserSession(request)
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
@@ -117,7 +122,7 @@ def autoindex(path="."):
|
|||||||
media_url = "https://cataas.com/cat"
|
media_url = "https://cataas.com/cat"
|
||||||
|
|
||||||
template_context = {'gif_url': media_url}
|
template_context = {'gif_url': media_url}
|
||||||
return auto_index.render_autoindex(path, template_context=template_context)
|
return auto_index.render_autoindex(path=session['user_base_dir'], template_context=template_context)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/queue', methods=['GET'])
|
@app.route('/queue', methods=['GET'])
|
||||||
@@ -168,6 +173,7 @@ def deezer_download_song_or_album():
|
|||||||
add_to_playlist: True|False (add to mpd playlist)
|
add_to_playlist: True|False (add to mpd playlist)
|
||||||
create_zip: True|False (create a zip for the album)
|
create_zip: True|False (create a zip for the album)
|
||||||
"""
|
"""
|
||||||
|
check_and_set_download_dirs_exist()
|
||||||
user_input = request.get_json(force=True)
|
user_input = request.get_json(force=True)
|
||||||
desc = "Downloading {}".format(user_input['type'])
|
desc = "Downloading {}".format(user_input['type'])
|
||||||
if user_input['type'] == "track":
|
if user_input['type'] == "track":
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from os.path import basename
|
|||||||
import mpd
|
import mpd
|
||||||
import platform
|
import platform
|
||||||
from zipfile import ZipFile, ZIP_DEFLATED
|
from zipfile import ZipFile, ZIP_DEFLATED
|
||||||
|
from flask import session
|
||||||
|
|
||||||
from deezer_downloader.configuration import config
|
from deezer_downloader.configuration import config
|
||||||
from deezer_downloader.youtubedl import youtubedl_download
|
from deezer_downloader.youtubedl import youtubedl_download
|
||||||
@@ -16,15 +17,16 @@ from deezer_downloader.threadpool_queue import ThreadpoolScheduler, report_progr
|
|||||||
sched = ThreadpoolScheduler()
|
sched = ThreadpoolScheduler()
|
||||||
|
|
||||||
|
|
||||||
def check_download_dirs_exist():
|
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")
|
||||||
for directory in [config["download_dirs"]["songs"], config["download_dirs"]["zips"], config["download_dirs"]["albums"],
|
for directory in [config["download_dirs"]["songs"], config["download_dirs"]["zips"], config["download_dirs"]["albums"],
|
||||||
config["download_dirs"]["playlists"], config["download_dirs"]["youtubedl"]]:
|
config["download_dirs"]["playlists"], config["download_dirs"]["youtubedl"]]:
|
||||||
os.makedirs(directory, exist_ok=True)
|
os.makedirs(directory, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
check_download_dirs_exist()
|
|
||||||
|
|
||||||
|
|
||||||
def make_song_paths_relative_to_mpd_root(songs, prefix=""):
|
def make_song_paths_relative_to_mpd_root(songs, prefix=""):
|
||||||
# ensure last slash
|
# ensure last slash
|
||||||
config["mpd"]["music_dir_root"] = os.path.join(config["mpd"]["music_dir_root"], '')
|
config["mpd"]["music_dir_root"] = os.path.join(config["mpd"]["music_dir_root"], '')
|
||||||
|
|||||||
Reference in New Issue
Block a user