Loading ballontranslator/ui/constants.py +2 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ STYLESHEET_PATH = osp.join(PROGRAM_PATH, 'data/config/stylesheet.css') THEME_PATH = osp.join(PROGRAM_PATH, 'data/config/themes.json') CONFIG_PATH = osp.join(PROGRAM_PATH, 'data/config/config.json') DOWNLOAD_PATH = osp.join(PROGRAM_PATH, 'gallery-dl') CONFIG_FONTSIZE_HEADER = 18 CONFIG_FONTSIZE_TABLE = 14 CONFIG_FONTSIZE_CONTENT = 14 Loading ballontranslator/ui/pagesources/__init__.py +39 −16 Original line number Diff line number Diff line from gallery_dl.job import DownloadJob from gallery_dl import config from qtpy.QtCore import QObject, Signal, QThread from qtpy.QtCore import Signal, QThread from utils.logger import logger as LOGGER from ui.misc import ProgramConfig from ui.imgtrans_proj import ProjImgTrans from ui.constants import DOWNLOAD_PATH import os class SourceDownload(QThread): open_downloaded_proj = Signal(str) Loading @@ -15,12 +17,9 @@ class SourceDownload(QThread): self.job = None self.config_pnl = config self.imgtrans_proj = imgtrans_proj self.path = '' self.path = f'{DOWNLOAD_PATH}/' self.url = '' def ReturnFullPathToProject(self) -> str: return self.path def ValidateUrl(self): if 'https://' not in self.url: self.url = 'https://' + self.url Loading @@ -30,34 +29,58 @@ class SourceDownload(QThread): def FetchImages(self): config.load() config.set((), "skip", False) job = DownloadJob(self.url) job.run() self.path = job.pathfmt.directory def FindNewestFolderAndSetPath(self): source_dirs = self.SubDirList(self.path) manga_dirs, chapter_dirs = [], [] for source_dir in source_dirs: manga_dirs += self.SubDirList(source_dir) for manga_dir in manga_dirs: chapter_dirs += self.SubDirList(manga_dir) subdirs = source_dirs + manga_dirs + chapter_dirs latest_subdir = max(subdirs, key=os.path.getmtime) self.path = latest_subdir @staticmethod def SubDirList(path): path_list = [] for file in os.listdir(path): file_path = os.path.join(path, file) if os.path.isdir(file_path): path_list.append(file_path) return path_list def openDownloadedProj(self, proj_path): self.open_downloaded_proj.emit(proj_path) def _SyncSourceDownload(self): # TODO keep track of downloaded page # TODO edit DownloadJob to always include url import time for i in range(100): self.update_progress_bar.emit(i) LOGGER.info(i) time.sleep(0.05) # for i in range(100): # self.update_progress_bar.emit(i) # LOGGER.info(i) # time.sleep(0.05) self.url = self.config_pnl.src_link_flag if self.url: LOGGER.info(f'Url set to {self.url}') self.ValidateUrl() self.FetchImages() self.FindNewestFolderAndSetPath() self.PassUrlToImgTransProj() proj_path = self.ReturnFullPathToProject() LOGGER.info(f'Project path set to {proj_path}') LOGGER.info(f'Project path set to {self.path}') if proj_path: self.openDownloadedProj(proj_path) if self.path: self.openDownloadedProj(self.path) self.finished_downloading.emit() Loading Loading
ballontranslator/ui/constants.py +2 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ STYLESHEET_PATH = osp.join(PROGRAM_PATH, 'data/config/stylesheet.css') THEME_PATH = osp.join(PROGRAM_PATH, 'data/config/themes.json') CONFIG_PATH = osp.join(PROGRAM_PATH, 'data/config/config.json') DOWNLOAD_PATH = osp.join(PROGRAM_PATH, 'gallery-dl') CONFIG_FONTSIZE_HEADER = 18 CONFIG_FONTSIZE_TABLE = 14 CONFIG_FONTSIZE_CONTENT = 14 Loading
ballontranslator/ui/pagesources/__init__.py +39 −16 Original line number Diff line number Diff line from gallery_dl.job import DownloadJob from gallery_dl import config from qtpy.QtCore import QObject, Signal, QThread from qtpy.QtCore import Signal, QThread from utils.logger import logger as LOGGER from ui.misc import ProgramConfig from ui.imgtrans_proj import ProjImgTrans from ui.constants import DOWNLOAD_PATH import os class SourceDownload(QThread): open_downloaded_proj = Signal(str) Loading @@ -15,12 +17,9 @@ class SourceDownload(QThread): self.job = None self.config_pnl = config self.imgtrans_proj = imgtrans_proj self.path = '' self.path = f'{DOWNLOAD_PATH}/' self.url = '' def ReturnFullPathToProject(self) -> str: return self.path def ValidateUrl(self): if 'https://' not in self.url: self.url = 'https://' + self.url Loading @@ -30,34 +29,58 @@ class SourceDownload(QThread): def FetchImages(self): config.load() config.set((), "skip", False) job = DownloadJob(self.url) job.run() self.path = job.pathfmt.directory def FindNewestFolderAndSetPath(self): source_dirs = self.SubDirList(self.path) manga_dirs, chapter_dirs = [], [] for source_dir in source_dirs: manga_dirs += self.SubDirList(source_dir) for manga_dir in manga_dirs: chapter_dirs += self.SubDirList(manga_dir) subdirs = source_dirs + manga_dirs + chapter_dirs latest_subdir = max(subdirs, key=os.path.getmtime) self.path = latest_subdir @staticmethod def SubDirList(path): path_list = [] for file in os.listdir(path): file_path = os.path.join(path, file) if os.path.isdir(file_path): path_list.append(file_path) return path_list def openDownloadedProj(self, proj_path): self.open_downloaded_proj.emit(proj_path) def _SyncSourceDownload(self): # TODO keep track of downloaded page # TODO edit DownloadJob to always include url import time for i in range(100): self.update_progress_bar.emit(i) LOGGER.info(i) time.sleep(0.05) # for i in range(100): # self.update_progress_bar.emit(i) # LOGGER.info(i) # time.sleep(0.05) self.url = self.config_pnl.src_link_flag if self.url: LOGGER.info(f'Url set to {self.url}') self.ValidateUrl() self.FetchImages() self.FindNewestFolderAndSetPath() self.PassUrlToImgTransProj() proj_path = self.ReturnFullPathToProject() LOGGER.info(f'Project path set to {proj_path}') LOGGER.info(f'Project path set to {self.path}') if proj_path: self.openDownloadedProj(proj_path) if self.path: self.openDownloadedProj(self.path) self.finished_downloading.emit() Loading