diff --git a/vspreview/toolbars/comp/toolbar.py b/vspreview/toolbars/comp/toolbar.py index b6d7ef17..eb826887 100644 --- a/vspreview/toolbars/comp/toolbar.py +++ b/vspreview/toolbars/comp/toolbar.py @@ -1,12 +1,26 @@ from __future__ import annotations +import logging +import random +import re +import shutil +import string +import unicodedata +from concurrent.futures import Future, ThreadPoolExecutor +from datetime import datetime from functools import partial from pathlib import Path -from typing import TYPE_CHECKING, Any, Callable, Final, NamedTuple, cast, Mapping +from typing import TYPE_CHECKING, Any, Callable, Final, Mapping, NamedTuple, cast +from uuid import uuid4 + +import requests import vapoursynth as vs from PyQt6 import QtCore from PyQt6.QtCore import QKeyCombination, QObject, Qt, QThread, pyqtSignal -from PyQt6.QtWidgets import QComboBox, QLabel +from PyQt6.QtWidgets import QComboBox, QFrame, QLabel +from requests import Session +from requests_toolbelt import MultipartEncoder # type: ignore +from requests_toolbelt import MultipartEncoderMonitor from ...core import ( AbstractToolbar, CheckBox, ComboBox, FrameEdit, HBoxLayout, LineEdit, ProgressBar, PushButton, VBoxLayout, @@ -16,8 +30,6 @@ from .settings import CompSettings if TYPE_CHECKING: - from requests import Session - from ...main import MainWindow @@ -31,31 +43,28 @@ def _get_slowpic_headers(content_length: int, content_type: str, sess: Session) -> dict[str, str]: return { - "Accept": "*/*", - "Accept-Encoding": "gzip, deflate", - "Accept-Language": "en-US,en;q=0.9", - "Access-Control-Allow-Origin": "*", - "Content-Length": str(content_length), - "Content-Type": content_type, - "Origin": "https://slow.pics/", - "Referer": "https://slow.pics/comparison", - "User-Agent": ( - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " - "(KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" + 'Accept': '*/*', + 'Accept-Encoding': 'gzip, deflate', + 'Accept-Language': 'en-US,en;q=0.9', + 'Access-Control-Allow-Origin': '*', + 'Content-Length': str(content_length), + 'Content-Type': content_type, + 'Origin': 'https://slow.pics/', + 'Referer': 'https://slow.pics/comparison', + 'User-Agent': ( + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' + '(KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' ), - "X-XSRF-TOKEN": sess.cookies.get("XSRF-TOKEN") + 'X-XSRF-TOKEN': sess.cookies.get('XSRF-TOKEN') } def _do_single_slowpic_upload(sess: Session, collection: str, imageUuid: str, image: Path, browser_id: str) -> None: - from uuid import uuid4 - - from requests_toolbelt import MultipartEncoder # type: ignore upload_info = MultipartEncoder({ - "collectionUuid": collection, - "imageUuid": imageUuid, - "file": (image.name, image.read_bytes(), 'image/png'), + 'collectionUuid': collection, + 'imageUuid': imageUuid, + 'file': (image.name, image.read_bytes(), 'image/png'), 'browserId': browser_id, }, str(uuid4())) @@ -66,9 +75,6 @@ def _do_single_slowpic_upload(sess: Session, collection: str, imageUuid: str, im def clear_filename(filename: str) -> str: - import re - import unicodedata - blacklist = ['\\', '/', ':', '*', '?', '\'', '<', '>', '|', '\0'] reserved = [ 'CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', @@ -119,7 +125,7 @@ class WorkerConfiguration(NamedTuple): public: bool nsfw: bool optimise: bool - remove_after: int | None + remove_after: str | None frames: list[int] compression: int path: Path @@ -150,13 +156,6 @@ def isFinished(self) -> bool: return self.is_finished def run(self, conf: WorkerConfiguration) -> None: - import shutil - from concurrent.futures import ThreadPoolExecutor - from uuid import uuid4 - - from requests import Session - from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor # type: ignore - all_images = list[list[Path]]() conf.path.mkdir(parents=True, exist_ok=False) @@ -173,7 +172,7 @@ def run(self, conf: WorkerConfiguration) -> None: max_num = max(conf.frames) path_images = [ - path_name / (f'{folder_name}_' + f'{f}'.zfill(len("%i" % max_num)) + '.png') + path_name / (f'{folder_name}_' + f'{f}'.zfill(len('%i' % max_num)) + '.png') for f in conf.frames ] @@ -222,7 +221,7 @@ def run(self, conf: WorkerConfiguration) -> None: with Session() as sess: if conf.browser_id and conf.session_id: - sess.cookies.set("SLPSESSION", conf.session_id, domain="slow.pics") + sess.cookies.set('SLPSESSION', conf.session_id, domain='slow.pics') browser_id = conf.browser_id check_session = True else: @@ -262,13 +261,14 @@ def _monitor_cb(monitor: MultipartEncoderMonitor) -> None: 'https://slow.pics/upload/comparison', data=monitor.to_string(), headers=_get_slowpic_headers(monitor.len, monitor.content_type, sess) ).json() - collection = comp_response["collectionUuid"] - key = comp_response["key"] - image_ids = comp_response["images"] + collection = comp_response['collectionUuid'] + key = comp_response['key'] + image_ids = comp_response['images'] images_done = 0 self._progress_update_func(0, total_images, uuid=conf.uuid) with ThreadPoolExecutor() as executor: - futures = [] + futures = list[Future[None]]() + for i, (output, images) in enumerate(zip(conf.outputs, all_images)): if self.isFinished(): return self.finished.emit(conf.uuid) @@ -312,15 +312,6 @@ def _monitor_cb(monitor: MultipartEncoderMonitor) -> None: self.finished.emit(conf.uuid) -try: - import requests - from datetime import datetime - import re -except ModuleNotFoundError: - raise ModuleNotFoundError( - 'You are missing `requests`!\n' - 'Install them with "pip install requests"!' - ) class CompToolbar(AbstractToolbar): _thread_running = False @@ -337,10 +328,38 @@ class CompToolbar(AbstractToolbar): upload_thread: QThread upload_worker: Worker + pic_type_button_I: CheckBox + pic_type_button_P: CheckBox + pic_type_button_B: CheckBox + + tag_add_button: PushButton + tag_add_custom_button: PushButton + + tag_filter_lineedit: LineEdit + tmdb_id_lineedit: LineEdit + + tag_list_combox: ComboBox[str] + + tag_separator: QFrame + + tag_data: dict[str, str] + current_tags: list[str] + + tag_data_cache: dict[str, str] | None + tag_data_error: bool + + collection_name_cache: str | None + curr_uuid = '' + tmdb_data = dict[str, dict[str, Any]]() + + _old_threads_workers = list[Any]() + + KEYWORD_RE = re.compile(r'\{[a-z0-9_-]+\}', flags=re.IGNORECASE) def __init__(self, main: MainWindow) -> None: super().__init__(main, CompSettings(self)) + self.setup_ui() self.set_qobject_names() @@ -348,104 +367,106 @@ def __init__(self, main: MainWindow) -> None: self.add_shortcuts() self.tag_data_cache = None + self.tag_data_error = False + + def _force_clicked(self, self_s: str) -> Callable[[bool], None]: + def _on_clicked(is_checked: bool) -> None: + if self_s == 'I': + el = self.pic_type_button_I + oth = (self.pic_type_button_P, self.pic_type_button_B) + elif self_s == 'P': + el = self.pic_type_button_P + oth = (self.pic_type_button_I, self.pic_type_button_B) + else: + el = self.pic_type_button_B + oth = (self.pic_type_button_I, self.pic_type_button_P) - self.cache_state = None + if not is_checked and not any(o.isChecked() for o in oth): + el.click() - def setup_ui(self) -> None: - super().setup_ui() + return _on_clicked - self.collection_name_lineedit = LineEdit('Collection name', self) + def _select_filter_text(self, text: str) -> None: + if text: + if text in self.current_tags: + self.tag_add_custom_button.setText('Remove Tag') + else: + self.tag_add_custom_button.setText('Add Tag') - self.random_frames_control = FrameEdit(self) - # self.bright_frames_control = FrameEdit(self) - # self.dark_frames_control = FrameEdit(self) + index = self.tag_list_combox.findText(text, QtCore.Qt.MatchFlag.MatchContains) - self.manual_frames_lineedit = LineEdit('Manual frames: frame,frame,frame', self, ) + if index < 0: + return - self.current_frame_checkbox = CheckBox('Current frame', self, checked=True) + self.tag_list_combox.setCurrentIndex( + index + ) - def _force_clicked(self_s: str): - def _on_clicked(is_checked: bool) -> None: - if self_s == 'I': - el = self.pic_type_button_I - oth = (self.pic_type_button_P, self.pic_type_button_B) - elif self_s == 'P': - el = self.pic_type_button_P - oth = (self.pic_type_button_I, self.pic_type_button_B) - else: - el = self.pic_type_button_B - oth = (self.pic_type_button_I, self.pic_type_button_P) + def _handle_current_combox_tag(self) -> None: + value = self.tag_list_combox.currentValue() - if not is_checked and not any(o.isChecked() for o in oth): - el.click() + if value in self.current_tags: + self.current_tags.remove(value) + self.tag_add_button.setText('Add Tag') + else: + self.current_tags.append(value) + self.tag_add_button.setText('Remove Tag') - return _on_clicked + def _handle_current_new_tag(self) -> None: + value = self.tag_filter_lineedit.text() - def _select_filter_text(text: str): - if text: - if text in self.current_tags: - self.tag_add_custom_button.setText("Remove Tag") - else: - self.tag_add_custom_button.setText("Add Tag") + if value in self.current_tags: + self.current_tags.remove(value) + self.tag_add_custom_button.setText('Add Tag') + else: + self.current_tags.append(value) + self.tag_add_custom_button.setText('Remove Tag') - index = self.tag_list_combox.findText(text, QtCore.Qt.MatchFlag.MatchContains) - if index < 0: - return - self.tag_list_combox.setCurrentIndex( - index - ) + def _handle_tag_index(self, index: int) -> None: + value = self.tag_list_combox.currentValue() - def _handle_current_combox_tag(): - value = self.tag_list_combox.currentValue() - if value in self.current_tags: - self.current_tags.remove(value) - self.tag_add_button.setText("Add Tag") - else: - self.current_tags.append(value) - self.tag_add_button.setText("Remove Tag") - - def _handle_current_new_tag(): - value = self.tag_filter_lineedit.text() - if value in self.current_tags: - self.current_tags.remove(value) - self.tag_add_custom_button.setText("Add Tag") - else: - self.current_tags.append(value) - self.tag_add_custom_button.setText("Remove Tag") + if value in self.current_tags: + self.tag_add_button.setText('Remove Tag') + else: + self.tag_add_button.setText('Add Tag') - def _handle_tag_index(index): - value = self.tag_list_combox.currentValue() - if value in self.current_tags: - self.tag_add_button.setText("Remove Tag") - else: - self.tag_add_button.setText("Add Tag") + def _public_click(self, is_checked: bool) -> None: + self.tag_add_button.setHidden(not is_checked) + self.tag_add_custom_button.setHidden(not is_checked) + self.tag_filter_lineedit.setHidden(not is_checked) + self.tag_list_combox.setHidden(not is_checked) + self.tag_separator.setHidden(not is_checked) + self.on_public_toggle(is_checked) - def _public_click(is_checked: bool): - self.tag_add_button.setHidden(not is_checked) - self.tag_add_custom_button.setHidden(not is_checked) - self.tag_filter_lineedit.setHidden(not is_checked) - self.tag_list_combox.setHidden(not is_checked) - self.tag_separator.setHidden(not is_checked) - self.on_public_toggle(is_checked) + def _handle_collection_name_down(self) -> None: + self.collection_name_cache = self.collection_name_lineedit.text() + self.collection_name_lineedit.setText(self._handle_collection_generate()) - self.collection_name_cache = None + def _handle_collection_name_up(self) -> None: + if self.collection_name_cache is not None: + self.collection_name_lineedit.setText(self.collection_name_cache) + self.collection_name_cache = None + + def setup_ui(self) -> None: + super().setup_ui() + + self.collection_name_lineedit = LineEdit('Collection name', self) + + self.random_frames_control = FrameEdit(self) - def _handle_collection_name_down(): - self.collection_name_cache = self.collection_name_lineedit.text() - self.collection_name_lineedit.setText(self._handle_collection_generate()) + self.manual_frames_lineedit = LineEdit('Manual frames: frame,frame,frame', self, ) + + self.current_frame_checkbox = CheckBox('Current frame', self, checked=True) - def _handle_collection_name_up(): - if self.collection_name_cache is not None: - self.collection_name_lineedit.setText(self.collection_name_cache) - self.collection_name_cache = None + self.collection_name_cache = None self.collection_name_button = PushButton( - '🛈', self, pressed=_handle_collection_name_down, released=_handle_collection_name_up + '🛈', self, pressed=self._handle_collection_name_down, released=self._handle_collection_name_up ) - self.pic_type_button_I = CheckBox('I', self, checked=True, clicked=_force_clicked('I')) - self.pic_type_button_P = CheckBox('P', self, checked=True, clicked=_force_clicked('P')) - self.pic_type_button_B = CheckBox('B', self, checked=True, clicked=_force_clicked('B')) + self.pic_type_button_I = CheckBox('I', self, checked=True, clicked=self._force_clicked('I')) + self.pic_type_button_P = CheckBox('P', self, checked=True, clicked=self._force_clicked('P')) + self.pic_type_button_B = CheckBox('B', self, checked=True, clicked=self._force_clicked('B')) self.tmdb_id_lineedit = LineEdit('TMDB ID', self) self.tmdb_id_lineedit.setMaximumWidth(75) @@ -455,8 +476,8 @@ def _handle_collection_name_up(): currentIndex=0, sizeAdjustPolicy=QComboBox.SizeAdjustPolicy.AdjustToContents ) - self.tag_data = {} - self.current_tags = [] + self.tag_data = dict[str, str]() + self.current_tags = list[str]() self.tag_list_combox = ComboBox[str]( self, currentIndex=0, sizeAdjustPolicy=QComboBox.SizeAdjustPolicy.AdjustToContents @@ -465,19 +486,19 @@ def _handle_collection_name_up(): self.update_tags() - self.tag_filter_lineedit = LineEdit('Tag Selection', self, textChanged=_select_filter_text) + self.tag_filter_lineedit = LineEdit('Tag Selection', self, textChanged=self._select_filter_text) - self.tag_add_custom_button = PushButton('Add Tag', self, clicked=_handle_current_new_tag) + self.tag_add_custom_button = PushButton('Add Tag', self, clicked=self._handle_current_new_tag) - self.tag_add_button = PushButton('Add Tag', self, clicked=_handle_current_combox_tag) + self.tag_add_button = PushButton('Add Tag', self, clicked=self._handle_current_combox_tag) self.tag_separator = self.get_separator() self.delete_after_lineedit = LineEdit('Days', self) self.delete_after_lineedit.setMaximumWidth(75) - self.is_public_checkbox = CheckBox('Public', self, checked=False, clicked=_public_click) - _public_click(self.is_public_checkbox.isChecked()) + self.is_public_checkbox = CheckBox('Public', self, checked=False, clicked=self._public_click) + self._public_click(self.is_public_checkbox.isChecked()) self.is_nsfw_checkbox = CheckBox('NSFW', self, checked=False) @@ -492,12 +513,12 @@ def _handle_collection_name_up(): self.upload_progressbar = ProgressBar(self, value=0) self.upload_progressbar.setGeometry(200, 80, 250, 20) - self.upload_status_label = QLabel(self, text='Select Frames') + self.upload_status_label = QLabel('Select Frames') self.upload_status_elements = (self.upload_progressbar, self.upload_status_label) VBoxLayout(self.hlayout, [ - HBoxLayout([ + HBoxLayout([ self.collection_name_lineedit, self.collection_name_button, ]), @@ -509,14 +530,8 @@ def _handle_collection_name_up(): self.hlayout.addWidget(self.get_separator()) VBoxLayout(self.hlayout, [ - HBoxLayout([ - self.current_frame_checkbox # , self.get_separator(), - # QLabel('Bright:'), self.bright_frames_control - ]), - HBoxLayout([ - QLabel('Random:'), self.random_frames_control, - # QLabel('Dark:'), self.dark_frames_control, - ]) + HBoxLayout([self.current_frame_checkbox]), + HBoxLayout([QLabel('Random:'), self.random_frames_control]) ]) self.hlayout.addWidget(self.get_separator()) @@ -571,54 +586,61 @@ def _handle_collection_name_up(): HBoxLayout([*self.upload_status_elements]) ]) - self.tag_list_combox.currentIndexChanged.connect(_handle_tag_index) + self.tag_list_combox.currentIndexChanged.connect(self._handle_tag_index) - tmdb_data = {} + def _get_replace_option(self, key: str) -> str | None: + if not self.main.outputs: + return '' - def _get_replace_option(self, key: str) -> str: - tmdb_id = self.tmdb_id_lineedit.text() or "" - if "tmdb_" in key and tmdb_id not in self.tmdb_data: - return "" + tmdb_id = self.tmdb_id_lineedit.text() or '' + + if 'tmdb_' in key and tmdb_id not in self.tmdb_data: + return '' + + data = self.tmdb_data[tmdb_id] - data: dict = self.tmdb_data.get(tmdb_id) match key: - case "{tmdb_title}": - return data.get("name", self.tmdb_data.get("title", "")) - case "{tmdb_year}": + case '{tmdb_title}': + return data.get('name', self.tmdb_data.get('title', '')) + case '{tmdb_year}': return str( datetime.strptime( - data.get("first_air_date", data.get("release_date", "1970-1-1")), + data.get('first_air_date', data.get('release_date', '1970-1-1')), '%Y-%m-%d' ).year ) - case "{video_nodes}": - return " vs ".join([video.title for video in self.main.outputs]) + case '{video_nodes}': + return ' vs '.join([video.name for video in self.main.outputs]) return None def _do_tmdb_request(self) -> None: if not (self.settings.tmdb_apikey and self.tmdb_id_lineedit.text()): - return False + return + tmdb_type = self.tmdb_type_combox.currentText().lower() tmdb_id = self.tmdb_id_lineedit.text() - url = f"https://api.themoviedb.org/3/{tmdb_type}/{self.tmdb_id_lineedit.text()}?language=en-US" + + url = f'https://api.themoviedb.org/3/{tmdb_type}/{self.tmdb_id_lineedit.text()}?language=en-US' + headers = { - "accept": "application/json", - "Authorization": f"Bearer {self.settings.tmdb_apikey}" + 'accept': 'application/json', + 'Authorization': f'Bearer {self.settings.tmdb_apikey}' } + resp = requests.get(url, headers=headers) - assert resp.status_code == 200, "Response isn't 200" - data: dict = resp.json() - assert data.get("success", True), "Success is false" + assert resp.status_code == 200, 'Response isn\'t 200' - self.tmdb_data[tmdb_id] = data + data: dict[str, Any] = resp.json() - return True + assert data.get('success', True), 'Success is false' - KEYWORD_RE = re.compile(r'\{[a-z0-9_-]+\}', flags=re.IGNORECASE) + self.tmdb_data[tmdb_id] = data + + return - def _handle_collection_generate(self): + def _handle_collection_generate(self) -> str: self._do_tmdb_request() collection_text = self.collection_name_lineedit.text() @@ -644,26 +666,20 @@ def on_public_toggle(self, new_state: bool) -> None: if not new_state or self.tag_data: return - if self.tag_data_cache is None or self.cache_state in ["ImportError", "Exception"]: + if self.tag_data_cache is None or self.tag_data_error: try: - from requests import Session - with Session() as sess: sess.get('https://slow.pics/comparison') - api_resp = sess.get("https://slow.pics/api/tags").json() + api_resp = sess.get('https://slow.pics/api/tags').json() - self.tag_data = {data["label"]: data["value"] for data in api_resp} + self.tag_data = {data['label']: data['value'] for data in api_resp} self.tag_data_cache = self.tag_data - self.cache_state = "Success" - - except ImportError: - self.tag_data = {"Missing requests": "Missing requests"} - self.cache_state = "ImportError" + self.tag_data_error = False except Exception: - self.tag_data = {"Network error": "Network error"} - self.cache_state = "Exception" + self.tag_data = {'Network error': 'Network error'} + self.tag_data_error = True else: self.tag_data = self.tag_data_cache @@ -676,12 +692,14 @@ def add_current_frame_to_comp(self) -> None: if not current_frames: self.manual_frames_lineedit.setText(frame) else: - current_frames = current_frames.split(",") + current_frames_l = current_frames.split(',') + if frame not in current_frames: - current_frames.append(frame) + current_frames_l.append(frame) else: - current_frames.remove(frame) - self.manual_frames_lineedit.setText(",".join(current_frames)) + current_frames_l.remove(frame) + + self.manual_frames_lineedit.setText(','.join(current_frames_l)) def on_copy_output_url_clicked(self, checked: bool | None = None) -> None: self.main.clipboard.setText(self.output_url_lineedit.text()) @@ -690,8 +708,10 @@ def on_copy_output_url_clicked(self, checked: bool | None = None) -> None: def on_start_upload(self) -> None: if self._thread_running: return + if not self.upload_to_slowpics(): return + self.start_upload_button.setVisible(False) self.stop_upload_button.setVisible(True) @@ -701,13 +721,14 @@ def on_end_upload(self, uuid: str, forced: bool = False) -> None: self.start_upload_button.setVisible(True) self.stop_upload_button.setVisible(False) + self._thread_running = False if forced: self.upload_progressbar.setValue(int()) - self.upload_status_label.setText("Stopped!") + self.upload_status_label.setText('Stopped!') else: - self.upload_status_label.setText("Finished!") + self.upload_status_label.setText('Finished!') def on_stop_upload(self) -> None: self.upload_worker.is_finished = True @@ -731,20 +752,20 @@ def update_status_label(self, uuid: str, kind: str, curr: int | None = None, tot else: self.output_url_lineedit.setText(kind) self.on_end_upload(self.curr_uuid, False) + return self.upload_status_label.setText(f'{message}{moreinfo}...') def _rand_num_frames(self, checked: set[int], rand_func: Callable[[], int]) -> int: rnum = rand_func() + while rnum in checked: rnum = rand_func() + return rnum def _select_samples_ptypes(self, num_frames: int, k: int, picture_types: set[str]) -> list[int]: - import logging - import random - samples = set[int]() _max_attempts = 0 _rnum_checked = set[int]() @@ -792,45 +813,41 @@ def _select_samples_ptypes(self, num_frames: int, k: int, picture_types: set[str return list(samples) - def create_slowpics_tags(self): - tags = [] - try: - from requests import Session - except Exception: - return tags + def create_slowpics_tags(self) -> list[str]: + tags = list[str]() with Session() as sess: sess.get('https://slow.pics/comparison') for tag in self.current_tags: if tag in self.tag_data: - tags.append(self.tag_data.get(tag)) + tags.append(self.tag_data[tag]) continue - api_resp: dict = sess.post( - "https://slow.pics/api/tags", + api_resp: dict[str, str] = sess.post( + 'https://slow.pics/api/tags', data=tag, - headers=_get_slowpic_headers(len(tag), "application/json", sess) + headers=_get_slowpic_headers(len(tag), 'application/json', sess) ).json() - self.tag_data[api_resp.get("label")] = api_resp.get("value") - tags.append(api_resp.get("value")) + label, value = api_resp['label'], api_resp['value'] + + self.tag_data[label] = value + + tags.append(value) + self.update_tags() + return tags def get_slowpics_conf(self) -> WorkerConfiguration: - import logging - import random - import re - import string - from uuid import uuid4 - assert self.main.outputs num = int(self.random_frames_control.value()) frames = list[int]( map(int, filter(None, [x.strip() for x in self.manual_frames_lineedit.text().split(',')])) ) + picture_types = set[str]() if self.pic_type_button_I.isChecked(): @@ -875,35 +892,31 @@ def get_slowpics_conf(self) -> WorkerConfiguration: if not collection_name: raise ValueError('You have to put a collection name!') - elif len(collection_name) <= 1: + + if len(collection_name) <= 1: raise ValueError('Your collection name is too short!') - collection_name = collection_name.format( - script_name=self.main.script_path.stem - ) + collection_name = collection_name.format(script_name=self.main.script_path.stem) sample_frames = list(sorted(set(samples))) - check_frame = sample_frames[0] if sample_frames else 0 + delete_after = self.delete_after_lineedit.text() or None - delete_after = self.delete_after_lineedit.text() if delete_after and re.match(r'^\d+$', delete_after) is None: raise ValueError('Delete after has to be a number!') - elif not delete_after: - delete_after = None tmdb_id = self.tmdb_id_lineedit.text() if tmdb_id: tmdb_type = self.tmdb_type_combox.currentData() - if tmdb_type == "TV": - suffix = "TV_" - elif tmdb_type == "MOVIE": - suffix = "MOVIE_" + if tmdb_type == 'TV': + suffix = 'TV_' + elif tmdb_type == 'MOVIE': + suffix = 'MOVIE_' else: raise ValueError('Unknown TMDB type!') if not tmdb_id.startswith(suffix): - tmdb_id = f"{suffix}{tmdb_id}" + tmdb_id = f'{suffix}{tmdb_id}' tags = self.create_slowpics_tags() @@ -921,8 +934,6 @@ def get_slowpics_conf(self) -> WorkerConfiguration: self.settings.browser_id, self.settings.session_id, tmdb_id, tags ) - _old_threads_workers = list[Any]() - def upload_to_slowpics(self) -> bool: try: self.main.current_scene.setPixmap(self.main.current_scene.pixmap().copy()) @@ -942,7 +953,8 @@ def upload_to_slowpics(self) -> bool: config = self.get_slowpics_conf() except RuntimeError as e: print(e) - return self.on_end_upload('', True) + self.on_end_upload('', True) + return False self.curr_uuid = config.uuid