Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve issue #207 #209

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/MangaManagerV2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions .idea/runConfigurations/Build.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/MangaManager.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/MangaManager_DEBUG.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/MangaManager_TRACE.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions DEVELOPMENT.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,4 @@ After that you can now create the build with the command below
If you can not run the build make sure all requirements are installed.
Pyinstaller does not use the virtual env requirements. So make sure the base python has them installed
Some of the requirements that gave me issues are:
- `chardet`

# QuickGuides
## Adding a setting

### Is this a main app/default setting?

If so go into src.Settings.SettingsDefault and add it there.

Say i want to add a toggle to enable darkmode

I add the key i'll use under Main section. `{"darkmode_enabled":False}` I want it opt-in so i set it to False
Lets add the setting in the settings menu. Head to src.MetadataManager.GUI.windows.SettingsWindow. Add your key in the corresponding section using the SettingControl of your choosing. In my case its a boolean. So SettingControlType.Bool
- `chardet`
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ENV GUIAUTOSTART=true

WORKDIR /tmp
COPY requirements.txt /tmp/
COPY requirements.txt /app/

# Copy App
COPY --chown=$UID:$GID [ "/MangaManager", "/app" ]
Expand All @@ -23,7 +22,6 @@ RUN apt-get update && \
xubuntu-default-settings \
xubuntu-icon-theme \
unrar\
# git\
# Python \
idle-python3.11 \
python3-tk \
Expand Down
39 changes: 0 additions & 39 deletions MangaManager/Extensions/CoverDownloader/CoverData.py

This file was deleted.

151 changes: 11 additions & 140 deletions MangaManager/Extensions/CoverDownloader/CoverDownloader.py
Original file line number Diff line number Diff line change
@@ -1,156 +1,27 @@
# import tkinter
# from idlelib.tooltip import Hovertip
# from idlelib.tooltip import Hovertip
import asyncio
import logging
import urllib.request
import os
import platform
import subprocess
from enum import StrEnum
from pathlib import Path
from tkinter import Frame, Label, StringVar
from tkinter.ttk import Entry, Button, Frame
import slugify
import requests
from tkinter import Label, Frame, Entry


from Extensions.CoverDownloader.CoverData import CoverData
from Extensions.CoverDownloader.MangaDex import parse_mangadex_id
from Extensions.CoverDownloader.exceptions import UrlNotFound
from Extensions.IExtensionApp import IExtensionApp
from src.MetadataManager.GUI.widgets import ProgressBarWidget
# from src.MetadataManager.GUI.tooltip import ToolTip
from src.Settings import Settings, SettingHeading, SettingSection, SettingControl, SettingControlType

logger = logging.getLogger()
def get_cover_from_source_dummy() -> list:
...


class CoverDownloaderSetting(StrEnum):
ForceOverwrite = "force_overwrite" # If existing covers should be re-downloaded and overwritten
class CoverDownloader(IExtensionApp):
class CoverDownloader():#IExtensionApp):
name = "Cover Downloader"
embedded_ui = True

def init_settings(self):

self.settings = [
SettingSection(self.name,self.name,[
SettingControl(
key=CoverDownloaderSetting.ForceOverwrite,
name="Force Overwrite",
control_type=SettingControlType.Bool,
value=False,
tooltip="Enable if existing covers should be re-downloaded and overwritten"
)
])
]
super().init_settings()

@property
def output_folder(self):
return Settings().get(SettingHeading.Main, 'covers_folder_path')

def serve_gui(self):
self.url_var = StringVar(name="mdex_cover_url")
self.url_var.trace("w",self.get_series_data)

self.dest_path_var = StringVar(name="dest_path",value=str(Path((self.output_folder or Path(Path.home(),"Pictures","Manga Covers")),
'<Manga Name Folder>')))
Label(self.master,text="MangaManager will download all availabe images from").pack()
# self.frame_3 = Frame(frame1)
Label(self.master, text='MANGADEX MANGA ID / URL').pack(side='top')
Entry(master=self.master,textvariable=self.url_var).pack(side='top')

Label(self.master, text="to the folder:").pack()
label_path = Label(self.master,textvariable=self.dest_path_var)
label_path.pack(pady="10 30", side='top')

self.button_1 = Button(self.master, text='Correct! Start!', state="disabled", command=self.process_download)
self.button_1.pack(side='top')
self.button_explorer = Button(self.master, text='Open explorer', command=self.open_explorer)
self.pb = ProgressBarWidget(self.master)

def process_download(self):
try:
self.download()
except Exception as e:
logger.exception("Error downloading")
finally:
self.button_1.configure(text="DONE", state="disabled")
self.show_open_explorer_btn()

def show_open_explorer_btn(self):
self.button_explorer.pack(side='top')
def hide_open_explorer_btn(self):
self.button_explorer.pack_forget()

def open_explorer(self):

path = self.dest_path_var.get()
if platform.system() == "Windows":
os.startfile(path)
elif platform.system() == "Darwin":
subprocess.Popen(["open", path])
else:
subprocess.Popen(["xdg-open", path])
...




if not self.master:
return Exception("Tried to initialize ui with no master window")

def get_series_data(self,*_):
mdex_id = parse_mangadex_id(self.url_var.get())
if mdex_id is None:
return
self.hide_open_explorer_btn()
self.button_1.configure(text="Correct! Start", state="normal")
# self.show_open_explorer_btn()
frame = Frame(self.master)
frame.pack()

logger.debug(f"Parsed mdex id: '{mdex_id}'")
data = {"manga[]": [mdex_id], "includes[]": ["manga"], "limit": 50}
# Request the list of covers in the prrovided manga
r = requests.get(f"https://api.mangadex.org/cover", params=data)
Label(frame, text="Manga identifier").pack()
Entry(frame).pack()
# Combobox(frame, state="readonly",values=sources_factory["CoverSources"]).pack()

if r.status_code != 200:
logger.warning(f"Page responded with {r.status_code}",extra={"url":r.url})
return
# raise UrlNotFound(r.url)
data = r.json().get("data")
cover_attributes = data[0].get("relationships")[0].get("attributes")
covers = get_cover_from_source_dummy()

# Get title
ja_title = list(filter(lambda p: p.get("ja-ro"),
cover_attributes.get("altTitles")))
if ja_title:
ja_title = ja_title[0].get("ja-ro")
full_name = (ja_title or cover_attributes.get("title").get("en"))
normalized_manga_name = slugify.slugify(full_name[:50])

# Get final path where images will be saved
self.destination_dirpath = Path((self.output_folder or Path(Path.home(), "Pictures", "Manga Covers")),normalized_manga_name)

# Update ui path
self.dest_path_var.set(str(self.destination_dirpath))
self.update()
self.cur_id = mdex_id
self.cur_data = data
def download(self):
self.pb.start(len(self.cur_data))
self.destination_dirpath.mkdir(parents=True, exist_ok=True)
for i,cover_data in enumerate(self.cur_data):
cover = CoverData().from_cover_data(cover_data)
image_path = Path(self.destination_dirpath, cover.dest_filename)
if not image_path.exists() or Settings().get(self.name,CoverDownloaderSetting.ForceOverwrite):
image_url = f"https://mangadex.org/covers/{self.cur_id}/{cover.source_filename}"

urllib.request.urlretrieve(image_url, image_path)
logger.debug(f"Downloaded '{image_path}'")
else:
logger.info(f"Skipped https://mangadex.org/covers/{self.cur_id}/{cover.source_filename} -> Already exists")
self.pb.increase_failed()
self.pb.increase_processed()
self.pb.stop()
self.update()
Loading