diff --git a/scraper.py b/scraper.py index be36d4f..84e8d1e 100644 --- a/scraper.py +++ b/scraper.py @@ -135,19 +135,24 @@ def get_torrents(): print("Please edit set.yaml") exit() + output_dir = "torrents" + os.makedirs(output_dir, exist_ok=True) # Create the directory if it doesn't exist + for url in url_list: torrent_url = url - # Call wtfcloudflare to download the torrent file - response = wtfcloudflare_t(torrent_url, useragent=useragent, cookie=cookie) - + torrent_id = url.split('/')[4] # The ID is in the 4th segment of the URL + torrent_path = os.path.join(output_dir, f"{torrent_id}.torrent") + # Extract the ID from the URL for naming the file torrent_id = url.split('/')[4] # The ID is in the 4th segment of the URL - - # Define the output directory and file name - output_dir = "torrents" - os.makedirs(output_dir, exist_ok=True) # Create the directory if it doesn't exist - torrent_path = os.path.join(output_dir, f"{torrent_id}.torrent") + + # Skip downloading if the torrent file already exists + if os.path.exists(torrent_path): + print(f"Torrent file already exists: {torrent_path}") + continue + + response = wtfcloudflare_t(torrent_url, useragent=useragent, cookie=cookie) # Save the torrent file to disk with open(torrent_path, 'wb') as torrent_file: