def get_torrent_file(sha256): #### 1. Locate the sample for downloading f_src = DIR_DATA + sha256[0] + "/" + sha256[1] + "/" + sha256[2] + "/" + sha256[3] + "/" + sha256 f_src = os.path.abspath(f_src) print("[p2p] Download sample: {}".format(f_src)) #### 2. Create a folder to store sample dir_download = DIR_DOWNLOAD_TORRENT + sha256 + "/" dir_download = os.path.abspath(dir_download) + "/" os.makedirs(dir_download, exist_ok=True) print("[p2p] Download folder: {}".format(dir_download)) #### 3. Copy the sample into download folder f_dst = dir_download + sha256 f_dst = os.path.abspath(f_dst) shutil.copyfile(f_src, f_dst) print("[p2p] Copy sample to {}".format(f_dst)) #### 4. Generate torrent file new_torrent = Torrent.create_from(dir_download) f_torrent = DIR_DOWNLOAD_TORRENT + sha256 + ".torrent" f_torrent = os.path.abspath(f_torrent) new_torrent.to_file(f_torrent) print("[p2p] Create torrent file {}".format(f_torrent)) #### 5. Return torrent file return f_torrent
def get_torrent_files(list_sha256): if not list_sha256: return "" #### 1. Clean TEMP folder del_dir_files() #### 2. Mov files into TEMP folder for sha256 in list_sha256: # 1.1 locate source file f_src = DIR_DATA + sha256[0] + "/" + sha256[1] + "/" + sha256[2] + "/" + sha256[3] + "/" + sha256 f_src = os.path.abspath(f_src) if not os.path.exists(f_src): continue # 1.2 locate destination file f_dst = DIR_TEMP + sha256 f_dst = os.path.abspath(f_dst) # 1.3 copy samples into TEMP folder shutil.copy(f_src, f_dst) #### 3. Generate torrent file new_torrent = Torrent.create_from(DIR_TEMP) f_torrent = DIR_DOWNLOAD + "list.torrent" f_torrent = os.path.abspath(f_torrent) new_torrent.to_file(f_torrent) print("[p2p] Create torrent file {}".format(f_torrent)) #### 4. Return torrent file return f_torrent
def test_create(): fp = join(CURRENT_DIR, 'torrtest', 'root.txt') t = Torrent.create_from(fp) t.private = True assert t._struct['info'] == STRUCT_TORRENT_SIMPLE['info'] # Note that STRUCT_TORRENT_WITH_DIR will probably # differ from struct created during this test (due to different file ordering - Transmission-torrentool), # so all we do is checking all files are present. t = Torrent.create_from(join(CURRENT_DIR, 'torrtest')) info = t._struct['info'] expected_info = STRUCT_TORRENT_WITH_DIR['info'] def get_fpaths(info): return {'|'.join(f['path']) for f in info['files']} assert get_fpaths(info) == get_fpaths(expected_info)
def test_create(datafix_dir, struct_torr_dir, struct_torr_file): fp = datafix_dir / 'torrtest' / 'root.txt' t = Torrent.create_from(str(fp)) t.private = True assert t._struct['info'] == struct_torr_file['info'] # Note that STRUCT_TORRENT_WITH_DIR will probably # differ from struct created during this test (due to different file ordering - Transmission-torrentool), # so all we do is checking all files are present. t = Torrent.create_from(str(datafix_dir / 'torrtest')) info = t._struct['info'] expected_info = struct_torr_dir['info'] def get_fpaths(info): return {'|'.join(f['path']) for f in info['files']} assert get_fpaths(info) == get_fpaths(expected_info)
def to_torrent(self, save_path=None): if save_path is None: save_path = os.path.join(os.getcwd(), (self.name + '.torrent')) # Fix me! new_torrent = Torrent.create_from(self.fp) # #new_torrent.announce_urls = 'udp://tracker.openbittorrent.com:80' new_torrent.to_file(save_path) # fix me self.torrent_name = os.path.basename(save_path) return new_torrent, save_path """0-250MB: 256KB (262144 bytes)
def create(source, dest, tracker, open_trackers, comment, cache): """Create torrent file from a single file or a directory.""" def check_path(fpath): fpath = path.abspath(fpath) if not path.exists(fpath): click.secho('Path is not found: %s' % fpath, fg='red', err=True) exit(1) return fpath if not dest: dest = getcwd() source = check_path(source) source_title = path.basename(source).replace('.', '_').replace(' ', '_') dest = check_path(dest) dest = '%s.torrent' % path.join(dest, source_title) click.secho('Creating torrent from %s ...' % source) my_torrent = Torrent.create_from(source) if comment: my_torrent.comment = comment urls = [] if tracker: urls = tracker.split(',') if open_trackers: urls.extend(get_open_trackers()) if urls: my_torrent.announce_urls = urls my_torrent.to_file(dest) click.secho('Torrent file created: %s' % dest, fg='green') click.secho('Torrent info hash: %s' % my_torrent.info_hash, fg='blue') if cache: upload_cache(dest)
def to_torrent(self, save_path=None, announce_urls=None): """Create a torrent Args: save_path (str, None): save torrent to this location if omitted its saved to the userdata/torrents foler announce_urls (str, list): list of trackers """ if save_path is None: save_path = os.path.join(self.save_torrent_path, os.path.basename(self.name) + '.torrent') self.torrent_name = os.path.basename(save_path) new_torrent = Torrent.create_from(self.fp) if announce_urls: new_torrent.announce_urls = announce_urls new_torrent.to_file(save_path) return new_torrent, save_path """0-250MB: 256KB (262144 bytes)
def generate_torrent_file(dir_sample, file_torrent): # d_samples is the directory containing samples # f_name is the specified name for the new torrent file print("\n[i] Generating torrent file.") new_torrent = Torrent.create_from(dir_sample) new_torrent.to_file(file_torrent)
except request.HTTPError as e: print("Error "+str(e.code)) print("Resource not available. Quitting...") quit() #latest Desktop Live iso URL webseed_desktop_live = "https://cdn.download.clearlinux.org/releases/"+latest_version+"/clear/clear-"+latest_version+"-live-desktop.iso" iso_desktop_live = "/tmp/clear-linux_"+latest_version+"_live-desktop.iso" #Check if iso is available try: print("Downloading latest iso (Version : " + latest_version + ") from mirror (" + humanize.naturalsize(request.urlopen(webseed_desktop_live).getheader("Content-Length")) + "). Please wait...") #TODO : Check if file exists and overwrite #retrieve iso from clear linux website request.urlretrieve(webseed_desktop_live,iso_desktop_live) except request.HTTPError as e: print("Error "+str(e.code)) print("Resource not available. Quitting...") quit() live_desktop_torrent = Torrent.create_from(iso_desktop_live) live_desktop_torrent.announce_urls = 'udp://tracker.openbittorrent.com:80' live_desktop_torrent.webseeds = webseed_desktop_live live_desktop_torrent.comment = "Torrent automatically created on " + datetime.now().strftime("%m/%d/%Y, %H:%M:%S") live_desktop_torrent.to_file('clear-linux-live-desktop-'+latest_version+'.torrent')
activePath = activeDownload.replace(dataSource, dataReturn) try: ##Debug #print(activePath) #input() ## os.makedirs(activePath) except: print("Folder Exists, Skipping...") activeFile = os.path.normpath(activeFile) activeTorrent = os.path.normpath(activeTorrent) ##Debug #print(activeFile) #input() ## GlassTorrent = Torrent.create_from(activeFile) GlassTorrent.announce_urls = urls GlassTorrent.comment = "Torrent created by the GlassLibrary" ##Debug #print(activeTorrent) #input() ## GlassTorrent.to_file(activeTorrent) print(f"Made {activeTorrent}") newTorrents += 1 try: launchSeed(activeTorrent) except: try: launchSeed(activeTorrent) except: