def generate_torrent(): print(" [*] Generating the torrent file...") try: with open('/tmp/{}.txt'.format(randname), 'w') as f: f.write(string_generator(20)) f.close() t = Torrent( path='/tmp/{}.txt'.format(randname), trackers=[ 'https://tracker1.{}.org:1234/announce'.format(randname), 'https://tracker2.{}.org:5678/announce'.format(randname) ], comment='*****@*****.**') t.private = True t.generate() t.write('/tmp/{}.torrent'.format(randname)) except Exception as e: print(e) print(" [*] Failed to generate the torrent due and error.") sys.exit(1) else: print(" [*] Torrent generated with success!") return True
def createtorrent(authkey, directory, filename, releasedata): t = Torrent( path=directory, trackers=[authkey] ) # Torf requires we store authkeys in a list object. This makes it easier to add multiple announce urls. # Set torrent to private as standard practice for private trackers t.private = True t.generate() ## Format releasedata to bring a suitable torrent name. # The reason we don't just use the directory name is because of an error in POSTING. # POSTS do not seem to POST hangul/jp characters alongside files. filename = f"{releasedata['artist']} - {releasedata['title']} [{releasedata['media']}-{releasedata['format']}].torrent" try: t.write(filename) print("_" * 100) print("Torrent creation:\n") print(f"{filename} has been created.") except: print("_" * 100) print("Torrent creation:\n") os.remove(filename) print(f"{filename} already exists, existing torrent will be replaced.") t.write(filename) print(f"{filename} has been created.") return filename
def create_torrent(resource, torrent, trackers, name=None, comment=""): t = Torrent( path=resource, trackers=trackers, comment=comment, name=name, ) t.generate() t.write(torrent)
def make_torrent(content_path, tracker, output_name): t = Torrent(path=content_path, trackers=[tracker], comment='-') t.generate() torrent_path = output_name + ".torrent" if os.path.exists(torrent_path): os.remove(torrent_path) t.write(torrent_path) return torrent_path
def create_torrent_file(torrent, f, name): fpath = getwritepath(f.sha256) t = Torrent(path=fpath, name=name, trackers=["%s:5555/announce" % fhost_url()]) t.generate() tpath = "%s.torrent" % fpath t.write(tpath) torrent.magnet = str(t.magnet()) # TODO: Check for errors here and don't hardcode the paths. subprocess.run([ "transmission-remote", "transmission:9091", "-N", "/app/config/transmission.netrc", "-x", "-y", "-a", tpath, "--find", "/downloads", ])
"domaine": "millegrilles.domaines.GrosFichiers.torrent", "estampille": 1575149613, "hachage-contenu": "A7Y96fpsP8YNLLCrXO31qHLihY3CFUBgcjqiv+JVWho=", "uuid-transaction": "0e6d9632-13b9-11ea-afcd-00155d011f09", # UUID du torrent/collection figee "version": 6 }, "securite": '1.public', # Niveau de securite global du torrent 'catalogue': { '11656060-0ba4-11ea-8f37-0dcce7873a80.dat': { # version / nom fichier dans archive # Contenu equivalent a une transaction millegrilles.domaines.GrosFichiers.nouvelleVersion.metadata # La millegrille qui recoit ce torrent va agir de la meme facon quelle le ferait avec une nouvelle # transaction (qui sera extraite et soumise sur reception du torrent). 'uuid': '9e589c55-e2ce-4ef1-9770-b0a9b58cc8b8', # uuid fichier 'fuuid': '11656060-0ba4-11ea-8f37-0dcce7873a80', # fuuid version 'nom': 'AmazonFreeTierEC2.pdf', 'mimetype': 'application/pdf', "taille": 5478, 'sha256': '9cb0e10c033a0e1bab62596d5dc68a7d3df4b558aa103b74e5b1b409a377b695', } }, 'commentaires': "J'aime bian les torrents", } # Signature de sha256, par cert key_fingerprint t.metainfo['_signature'] = 'U6OVWPkPk7ojx0Kz1xQCX02pR3w/EJuFMzvGTY42/kdpVyNjlJ7d+irh2u/fgMO3MOLZieyCWgamkHOauydIk3dtzorBtHvIemtBID482tSC815TTDTDpN3A7pzfyh/dnimR98izMROcsCdUnU0yupJOgDR/Qz+OjNb7HeowdW01EWrKOMzTcdDn2MvyK29K6nEDAAiAeUbpX7PXvxi2XkvBfwrnXeW66OGErtSg0FzxKFWp+r008G4S4Y8sk6w5LlKKh+qp92KvkY2y3VdTz6okf1PCfe4LrWsj4PKQ+YR5/6DEtS7Ff2JhnmT94wG9s7+omnu5b4GIiMA1yS2S8A==' # t.private = True t.generate() t.write('/home/mathieu/tmp/dev3_archive_20191011UTC.torrent')
def handle_playlist_update(src_path: str): rtmp_playlist_path = os.path.abspath(src_path) basedir: str = os.path.dirname(rtmp_playlist_path) try: stream_obj: Stream = Stream.objects.get(pk=os.path.basename(basedir)) except ValueError as err: capture_exception(err) logging.error("Stream id is not valid UUID") return tracker_urls = [ tracker.url for tracker in Tracker.objects.filter(is_active=True).all() ] with open(rtmp_playlist_path) as f: chunk_filenames = re.findall(CHUNK_FILENAME_PATTERN, f.read(), re.MULTILINE) print(chunk_filenames) if not chunk_filenames: return chunk_filename = chunk_filenames[-1] start_time = time.time() chunk_number: int = int(chunk_filename.rstrip(".ts")) if not Chunk.objects.filter(stream=stream_obj, number=chunk_number).exists(): try: with transaction.atomic(): if stream_obj.viewers and stream_obj.viewers < config.TARGET_SEED_USERS: cloud_url_prob = stream_obj.viewers / config.TARGET_SEED_USERS else: cloud_url_prob = Decimal( config.USE_CLOUD_PROB / 100) if config.USE_CLOUD_PROB else 0 chunk_path = os.path.join(basedir, chunk_filename) secret_filename = f"{chunk_number}_{random_string()}.ts" new_chunk: Chunk = \ Chunk.objects.create(stream=stream_obj, number=chunk_number, filename=secret_filename, prob=cloud_url_prob) t = Torrent(path=chunk_path, trackers=tracker_urls, webseeds=[ new_chunk.file_url, ], piece_size=2**20) t.generate() new_chunk.magnet_link = t.magnet() with io.BytesIO() as torrent_file: t.write_stream(torrent_file) gs_client.upload_file( torrent_file, gs_torrent_path(stream_obj.id, new_chunk.number)) with VideoFileClip(chunk_path) as chunk_clip: new_chunk.duration = Decimal(chunk_clip.duration) if new_chunk.number % UPDATE_THUMBNAIL_EVERY == 0: thumbnail_path = f"/tmp/thumbnails/{stream_obj.id}.jpg" time_mark = chunk_clip.duration * 0.05 chunk_clip.save_frame(thumbnail_path, t=time_mark) gs_client.upload_file( thumbnail_path, gs_thumbnail_path(stream_obj.id)) gs_client.upload_file(chunk_path, gs_chunk_path( stream_obj.id, new_chunk.filename), content_type="video/MP2T") new_chunk.is_public = True new_chunk.save() stream_obj.update_playlist() logging.info( f"new chunk: {str(stream_obj.id)[0:5]}/{chunk_number} in {round(time.time() - start_time, 2)}s" ) except Exception as err: capture_exception(err) logging.error(err)