Shows destinations
This commit is contained in:
+29
-7
@@ -15,7 +15,7 @@ import mutagen
|
||||
from mutagen.easyid3 import EasyID3
|
||||
from mutagen.mp3 import MP3
|
||||
from mutagen.id3 import ID3, APIC
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
from flask import Flask, render_template, request, jsonify, send_file
|
||||
|
||||
MUSIC_FOLDER = "Music"
|
||||
|
||||
@@ -33,6 +33,7 @@ class ReleaseInfo:
|
||||
class ReleaseStatus:
|
||||
info: ReleaseInfo | None
|
||||
status: str
|
||||
destinations: set[str]
|
||||
|
||||
|
||||
class RipError(Exception):
|
||||
@@ -178,7 +179,9 @@ def find_tmp_path() -> str:
|
||||
return f"{project_root_path}/tmp"
|
||||
|
||||
|
||||
def sort_into_music(path: str, info: ReleaseInfo) -> None:
|
||||
def sort_into_music(path: str, info: ReleaseInfo) -> set[str]:
|
||||
destinations: set[str] = set()
|
||||
|
||||
try:
|
||||
for file_name in os.listdir(path):
|
||||
if file_name == "cover.jpg":
|
||||
@@ -218,11 +221,15 @@ def sort_into_music(path: str, info: ReleaseInfo) -> None:
|
||||
source_file_path_cover = os.path.join(path, "cover.jpg")
|
||||
shutil.copy(source_file_path_cover, release_path)
|
||||
|
||||
destinations.add(release_path)
|
||||
|
||||
except Exception:
|
||||
raise RipError("Filesystem error")
|
||||
|
||||
return destinations
|
||||
|
||||
def rip_worker(rip_queue: list[str], status_callback: Callable[[ReleaseInfo | str, bool],]):
|
||||
|
||||
def rip_worker(rip_queue: list[str], status_callback: Callable[[ReleaseInfo | str | set[str], bool],]):
|
||||
tmp_path = find_tmp_path()
|
||||
|
||||
while True:
|
||||
@@ -259,7 +266,8 @@ def rip_worker(rip_queue: list[str], status_callback: Callable[[ReleaseInfo | st
|
||||
raise RipError("No content was downloaded")
|
||||
|
||||
status_callback("Sorting content", False)
|
||||
sort_into_music(tmp_path, info)
|
||||
destinations = sort_into_music(tmp_path, info)
|
||||
status_callback(destinations, False)
|
||||
|
||||
except RipError as e:
|
||||
status_callback(e.msg, True)
|
||||
@@ -278,10 +286,12 @@ if __name__ == "__main__":
|
||||
|
||||
current_release_info: ReleaseInfo | None = None
|
||||
current_release_status_message: str = ""
|
||||
current_release_destinations: set[str] = set()
|
||||
|
||||
def get_current_release_status(x: ReleaseInfo | str, finished: bool):
|
||||
def get_current_release_status(x: ReleaseInfo | str | set[str], finished: bool):
|
||||
global current_release_info
|
||||
global current_release_status_message
|
||||
global current_release_destinations
|
||||
global finished_queue
|
||||
|
||||
if type(x) is ReleaseInfo:
|
||||
@@ -290,13 +300,19 @@ if __name__ == "__main__":
|
||||
elif type(x) is str:
|
||||
current_release_status_message = x
|
||||
|
||||
elif type(x) is set:
|
||||
current_release_destinations = x.copy()
|
||||
|
||||
if finished:
|
||||
if current_release_info is None:
|
||||
current_release_info = ReleaseInfo("Unknown", "Unknown", "url", False, False)
|
||||
|
||||
finished_queue.append(ReleaseStatus(current_release_info, current_release_status_message))
|
||||
finished_queue.append(
|
||||
ReleaseStatus(current_release_info, current_release_status_message, current_release_destinations.copy())
|
||||
)
|
||||
current_release_info = None
|
||||
current_release_status_message = "Waiting"
|
||||
current_release_destinations = set()
|
||||
|
||||
if len(finished_queue) > 30:
|
||||
finished_queue.pop(0)
|
||||
@@ -325,7 +341,13 @@ if __name__ == "__main__":
|
||||
continue
|
||||
|
||||
data["finishedQueue"].append(
|
||||
{"artist": q.info.artist, "title": q.info.title, "status": q.status, "art_url": q.info.art_url}
|
||||
{
|
||||
"artist": q.info.artist,
|
||||
"title": q.info.title,
|
||||
"status": q.status,
|
||||
"art_url": q.info.art_url,
|
||||
"destinations": list(q.destinations),
|
||||
}
|
||||
)
|
||||
|
||||
if current_release_info is not None:
|
||||
|
||||
+35
-1
@@ -79,6 +79,40 @@
|
||||
`;
|
||||
}
|
||||
|
||||
function createFinishCard(artist, title, status, art, destinations) {
|
||||
let dstList = ""
|
||||
for (destination of destinations) {
|
||||
dstList += `<li>${destination}</li>`;
|
||||
}
|
||||
|
||||
let extraClasses = ""
|
||||
if (status !== "Finished sucessfully") {
|
||||
extraClasses = "border-danger"
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="card mb-3 ${extraClasses}" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="${art}" class="img-fluid rounded-start">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${title}</h5>
|
||||
<p class="card-text">${artist}</p>
|
||||
|
||||
<ol>
|
||||
${dstList}
|
||||
</ol>
|
||||
|
||||
<p class="card-text"><small class="text-body-secondary">${status}</small></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
const ripFormInput = document.getElementById("urlInput");
|
||||
|
||||
document
|
||||
@@ -124,7 +158,7 @@
|
||||
|
||||
finishTableBody.innerHTML = "";
|
||||
for (const q of statusJson.finishedQueue) {
|
||||
finishTableBody.innerHTML += createCard(q.artist, q.title, q.status, q.art_url);
|
||||
finishTableBody.innerHTML += createFinishCard(q.artist, q.title, q.status, q.art_url, q.destinations);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user