def get_file_list(path): t = Torrent.read(path) print('Torrent size: ', t.size) #print(t) mi = t.metainfo #print(mi['info']) return mi['info']['files']
async def edit_torrent(self, meta): if os.path.exists( f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent"): THR_torrent = Torrent.read( f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent") THR_torrent.metainfo['announce'] = self.config['TRACKERS']['THR'][ 'announce_url'] THR_torrent.metainfo['info'][ 'source'] = "[https://www.torrenthr.org] TorrentHR.org" Torrent.copy(THR_torrent).write( f"{meta['base_dir']}/tmp/{meta['uuid']}/[THR]{meta['clean_name']}.torrent", overwrite=True) return
async def find_existing_torrent(self, meta): if meta.get('client', None) == None: default_torrent_client = self.config['DEFAULT']['default_torrent_client'] else: default_torrent_client = meta['client'] if meta.get('client', None) == 'none': return None client = self.config['TORRENT_CLIENTS'][default_torrent_client] torrent_storage_dir = client.get('torrent_storage_dir', None) torrent_client = client.get('torrent_client', None) if torrent_storage_dir == None: cprint(f'Missing torrent_storage_dir for {default_torrent_client}', 'grey', 'on_red') if torrent_storage_dir != None: if meta.get('torrenthash', None) != None: torrenthash = meta['torrenthash'] elif meta.get('ptp_torrenthash', None) != None: torrenthash = meta['ptp_torrenthash'] if torrent_client == 'qbit': torrenthash = torrenthash.lower() elif torrent_client == 'rtorrent': torrenthash = torrenthash.upper() torrent_path = f"{torrent_storage_dir}/{torrenthash}.torrent" if os.path.exists(torrent_path): # Reuse if disc if meta.get('is_disc', None) != None: cprint(f'REUSING .torrent with infohash: {torrenthash}', 'grey', 'on_green') return torrent_path torrent = Torrent.read(torrent_path) # If one file, check for folder if len(torrent.files) == len(meta['filelist']) == 1: if str(torrent.files[0]) == os.path.basename(torrent.files[0]): cprint(f'REUSING .torrent with infohash: {torrenthash}', 'grey', 'on_green') return torrent_path # Check if number of files matches number of videos elif len(torrent.files) == len(meta['filelist']): torrent_filepath = os.path.commonpath(torrent.files) actual_filepath = os.path.commonpath(meta['filelist']) if torrent_filepath in actual_filepath: cprint(f'REUSING .torrent with infohash: {torrenthash}', 'grey', 'on_green') return torrent_path cprint('Unwanted Files/Folders Identified', 'grey', 'on_yellow') return None else: cprint(f'NO .torrent WITH INFOHASH {torrenthash} FOUND', 'grey', 'on_yellow') return None
async def add_to_client(self, meta, tracker): torrent_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{tracker}]{meta['clean_name']}.torrent" if os.path.exists(torrent_path): torrent = Torrent.read(torrent_path) else: return if meta.get('client', None) == None: default_torrent_client = self.config['DEFAULT']['default_torrent_client'] else: default_torrent_client = meta['client'] if meta.get('client', None) == 'none': return if default_torrent_client == "none": return client = self.config['TORRENT_CLIENTS'][default_torrent_client] torrent_client = client['torrent_client'] local_path = list_local_path = self.config['TORRENT_CLIENTS'][default_torrent_client].get('local_path','/LocalPath') remote_path = list_remote_path = self.config['TORRENT_CLIENTS'][default_torrent_client].get('remote_path', '/RemotePath') if isinstance(local_path, list): for i in range(len(local_path)): if os.path.normpath(local_path[i]) in meta['path']: list_local_path = local_path[i] list_remote_path = remote_path[i] local_path = os.path.normpath(list_local_path) remote_path = os.path.normpath(list_remote_path) if local_path.endswith(os.sep): remote_path = remote_path + os.sep cprint(f"Adding to {torrent_client}", 'grey', 'on_yellow') if torrent_client.lower() == "rtorrent": self.rtorrent(meta['path'], torrent_path, torrent, meta, local_path, remote_path, client) elif torrent_client == "qbit": await self.qbittorrent(meta['path'], torrent, local_path, remote_path, client, meta['is_disc'], meta['filelist']) elif torrent_client.lower() == "deluge": if meta['type'] == "DISC": path = os.path.dirname(meta['path']) self.deluge(meta['path'], torrent_path, torrent, local_path, remote_path, client, meta) elif torrent_client.lower() == "watch": shutil.copy(torrent_path, client['watch_folder']) return
from torf import Torrent import json nom_torrent = '561ff56f-f7ab-4637-a699-ec2719781b64' t = Torrent.read( '/opt/millegrilles/dev3/mounts/consignation/torrents/%s.torrent.added' % nom_torrent) print('----------------------------------') print("Nom collection: %s" % t.name) print("Commentaires: %s" % t.comment) transaction = t.metainfo['info']['millegrilles'] print('MilleGrilles:\n%s' % json.dumps(transaction, indent=4)) print('----------------------------------') print("Trackers: %s" % str(t.trackers)) print("Creation date: %s" % t.creation_date) print("Piece size: %s" % t.piece_size) print("Created by: %s" % t.created_by) print('----------------------------------') print("Files: ") for file in t.metainfo['info']['files']: print(str(file))