Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def create_torrent(resource, torrent, trackers, name=None, comment=""):
    t = Torrent(
        path=resource,
        trackers=trackers,
        comment=comment,
        name=name,
    )
    t.generate()
    t.write(torrent)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def create_torrent(fp: str) -> str:
    """
    Not documented yet.
    """
    create_at: Any = Path(CONFIG["torrent"]["createAt"]).resolve()

    # Get the file name.
    t_name: str = fp.split("\\")[-1].split(".zip")[0]

    # Append the paths and create a (hopefully) unique file name.
    t_path: Any = create_at / f"{t_name}.torrent"

    t: Torrent = Torrent(fp, trackers=CONFIG["torrent"]["trackers"])
    t.generate()
    t.write(t_path)

    print(f"  -> Created torrent file: {t_path}")

    return str(t_path)
Exemplo n.º 6
0
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",
    ])
from torf import Torrent
import datetime

t = Torrent()
t.created_by = "create-torrent/MilleGrilles 1.16"
t.creation_date = datetime.datetime.utcnow().timestamp()
t.trackers = [
    'https://mg-dev3.local:3004/announce'
]
t.comment = 'Archive 11 octobre 2019 UTC'
t.metainfo['millegrilles'] = {
    "en-tete": {
        'millegrille': "371dabe45115a8fe7e594945190ee6cd6f81f890",  # Fingerprint SSRoot
        "certificat": "8f3e528bb8c7d489b6b296b07b16db2bf76fa729",  # Certificat verifiable contre SSRoot (chaine)
        "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,
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
from torf import Torrent

t = Torrent(path='C:/Users/Profesor/Documents/arquisoft',
            trackers=['udp://tracker.openbittorrent.com:80/announce'],
            comment='This is a comment')
t.private = False
t.generate()
t.write('C:/Users/Profesor/Documents/monitoria/nueva/torrents/ultimo.torrent')