示例#1
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
示例#2
0
 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
示例#3
0
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']
示例#4
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
def create_torrent(resource, torrent, trackers, name=None, comment=""):
    t = Torrent(
        path=resource,
        trackers=trackers,
        comment=comment,
        name=name,
    )
    t.generate()
    t.write(torrent)
示例#6
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
示例#7
0
 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
示例#8
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)
示例#9
0
 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
示例#10
0
文件: fhost.py 项目: audiodude/0bt
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,
示例#12
0
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))
示例#13
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)
示例#14
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')