Created
September 13, 2024 01:01
-
-
Save ShanaryS/27873eb7091f09f903b18bc3000403ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import os | |
| import json | |
| # Configuration variables | |
| QBITTORRENT_URL = "http://localhost:8080" # Change to your qBittorrent Web UI address | |
| USERNAME = "" # Replace with your qBittorrent username if needed | |
| PASSWORD = "" # Replace with your qBittorrent password if needed | |
| EXPORT_PATH = "./exported_torrents" # Directory to store the exported torrents | |
| # Login to qBittorrent | |
| session = requests.Session() | |
| login_payload = { | |
| 'username': USERNAME, | |
| 'password': PASSWORD | |
| } | |
| login_response = session.post(f"{QBITTORRENT_URL}/api/v2/auth/login", data=login_payload) | |
| if login_response.ok: | |
| print("Login successful. Exporting torrents...") | |
| # Create the export directory if it doesn't exist | |
| os.makedirs(EXPORT_PATH, exist_ok=True) | |
| # Get the list of torrents (hashes) | |
| torrents_response = session.get(f"{QBITTORRENT_URL}/api/v2/torrents/info") | |
| if torrents_response.ok: | |
| torrents = json.loads(torrents_response.text) | |
| for torrent in torrents: | |
| torrent_hash = torrent['hash'] | |
| print(f"Exporting torrent with hash: {torrent_hash}") | |
| # Export each torrent by its hash | |
| export_response = session.get(f"{QBITTORRENT_URL}/api/v2/torrents/export", params={'hash': torrent_hash}) | |
| # Save the torrent file | |
| if export_response.ok: | |
| with open(os.path.join(EXPORT_PATH, f"{torrent_hash}.torrent"), 'wb') as torrent_file: | |
| torrent_file.write(export_response.content) | |
| print(f"Exported {torrent_hash} successfully.") | |
| else: | |
| print(f"Failed to export torrent {torrent_hash}") | |
| else: | |
| print("Failed to retrieve torrent list.") | |
| # Logout | |
| session.get(f"{QBITTORRENT_URL}/api/v2/auth/logout") | |
| else: | |
| print("Login failed.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment