diff --git a/src/prep.py b/src/prep.py index 808ea730..0dfcd7a0 100644 --- a/src/prep.py +++ b/src/prep.py @@ -780,25 +780,28 @@ async def process_tracker(tracker_name, meta): elif meta['skipping']: tracker_status[tracker_name]['skipped'] = True if tracker_name == "MTV": - tracker_config = self.config['TRACKERS'].get(tracker_name, {}) - if str(tracker_config.get('prefer_mtv_torrent', 'false')).lower() == "true": - meta['prefer_small_pieces'] = True - else: - meta['prefer_small_pieces'] = False - if str(tracker_config.get('skip_if_rehash', 'false')).lower() == "true": - torrent_path = os.path.abspath(f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent") - if not os.path.exists(torrent_path): - check_torrent = await client.find_existing_torrent(meta) - if check_torrent: - console.print(f"[yellow]Existing torrent found on {check_torrent}[/yellow]") - self.create_base_from_existing_torrent(check_torrent, meta['base_dir'], meta['uuid']) + if not tracker_status[tracker_name]['banned'] and not tracker_status[tracker_name]['skipped'] and not tracker_status[tracker_name]['dupe']: + tracker_config = self.config['TRACKERS'].get(tracker_name, {}) + if str(tracker_config.get('prefer_mtv_torrent', 'false')).lower() == "true": + meta['prefer_small_pieces'] = True + else: + meta['prefer_small_pieces'] = False + if str(tracker_config.get('skip_if_rehash', 'false')).lower() == "true": + torrent_path = os.path.abspath(f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent") + if not os.path.exists(torrent_path): + check_torrent = await client.find_existing_torrent(meta) + if check_torrent: + console.print(f"[yellow]Existing torrent found on {check_torrent}[/yellow]") + self.create_base_from_existing_torrent(check_torrent, meta['base_dir'], meta['uuid']) + torrent = Torrent.read(torrent_path) + if torrent.piece_size > 8388608: + console.print("[yellow]No existing torrent found with piece size lesser than 8MB[/yellow]") + tracker_status[tracker_name]['skipped'] = True + elif os.path.exists(torrent_path): torrent = Torrent.read(torrent_path) if torrent.piece_size > 8388608: + console.print("[yellow]Existing torrent found with piece size greater than 8MB[/yellow]") tracker_status[tracker_name]['skipped'] = True - elif os.path.exists(torrent_path): - torrent = Torrent.read(torrent_path) - if torrent.piece_size > 8388608: - tracker_status[tracker_name]['skipped'] = True if meta.get('skipping') is None and not is_dupe and tracker_name == "PTP": if meta.get('imdb_info', {}) == {}: meta['imdb_info'] = self.get_imdb_info_api(meta['imdb_id'], meta) diff --git a/src/trackers/MTV.py b/src/trackers/MTV.py index 5c64aa54..18fb57b3 100644 --- a/src/trackers/MTV.py +++ b/src/trackers/MTV.py @@ -46,6 +46,52 @@ async def upload(self, meta, disctype): await self.upload_with_retry(meta, cookiefile, common) async def upload_with_retry(self, meta, cookiefile, common, img_host_index=1): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + if not os.path.exists(torrent_file_path): + torrent_filename = "BASE" + torrent_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent" + torrent = Torrent.read(torrent_path) + + if torrent.piece_size > 8388608: + tracker_config = self.config['TRACKERS'].get(MTV, {}) + if str(tracker_config.get('skip_if_rehash', 'false')).lower() == "true": + console.print("[red]Piece size is OVER 8M and does not work on MTV. Generating a new .torrent") + + meta['max_piece_size'] = '8' + if meta['is_disc']: + include = [] + exclude = [] + else: + include = ["*.mkv", "*.mp4", "*.ts"] + exclude = ["*.*", "*sample.mkv", "!sample*.*"] + + from src.prep import Prep + prep = Prep(screens=meta['screens'], img_host=meta['imghost'], config=self.config) + new_torrent = prep.CustomTorrent( + meta=meta, + path=Path(meta['path']), + trackers=["https://fake.tracker"], + source="L4G", + private=True, + exclude_globs=exclude, # Ensure this is always a list + include_globs=include, # Ensure this is always a list + creation_date=datetime.now(), + comment="Created by L4G's Upload Assistant", + created_by="L4G's Upload Assistant" + ) + + new_torrent.piece_size = 8 * 1024 * 1024 + new_torrent.validate_piece_size() + new_torrent.generate(callback=prep.torf_cb, interval=5) + new_torrent.write(f"{meta['base_dir']}/tmp/{meta['uuid']}/MTV.torrent", overwrite=True) + + torrent_filename = "MTV" + + await common.edit_torrent(meta, self.tracker, self.source_flag, torrent_filename=torrent_filename) + else: + console.print("[red]Piece size is OVER 8M and skip_if_rehash enabled. Skipping upload.") + return + approved_image_hosts = ['ptpimg', 'imgbox', 'imgbb'] url_host_mapping = { "i.ibb.co": "imgbb", @@ -92,47 +138,6 @@ async def upload_with_retry(self, meta, cookiefile, common, img_host_index=1): console.print("[red]All image hosts failed. Please check your configuration.") return - torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" - if not os.path.exists(torrent_file_path): - torrent_filename = "BASE" - torrent_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent" - torrent = Torrent.read(torrent_path) - - if torrent.piece_size > 8388608: - console.print("[red]Piece size is OVER 8M and does not work on MTV. Generating a new .torrent") - - meta['max_piece_size'] = '8' - if meta['is_disc']: - include = [] - exclude = [] - else: - include = ["*.mkv", "*.mp4", "*.ts"] - exclude = ["*.*", "*sample.mkv", "!sample*.*"] - - from src.prep import Prep - prep = Prep(screens=meta['screens'], img_host=meta['imghost'], config=self.config) - new_torrent = prep.CustomTorrent( - meta=meta, - path=Path(meta['path']), - trackers=["https://fake.tracker"], - source="L4G", - private=True, - exclude_globs=exclude, # Ensure this is always a list - include_globs=include, # Ensure this is always a list - creation_date=datetime.now(), - comment="Created by L4G's Upload Assistant", - created_by="L4G's Upload Assistant" - ) - - new_torrent.piece_size = 8 * 1024 * 1024 - new_torrent.validate_piece_size() - new_torrent.generate(callback=prep.torf_cb, interval=5) - new_torrent.write(f"{meta['base_dir']}/tmp/{meta['uuid']}/MTV.torrent", overwrite=True) - - torrent_filename = "MTV" - - await common.edit_torrent(meta, self.tracker, self.source_flag, torrent_filename=torrent_filename) - cat_id = await self.get_cat_id(meta) resolution_id = await self.get_res_id(meta['resolution']) source_id = await self.get_source_id(meta)