コード例 #1
0
ファイル: main.py プロジェクト: Frankmau5/TRiver
 def save_as(self):
     name = fd.asksaveasfilename()
     name = name.replace(".torrent", "")
     myJsonStr = self.t.get('1.0', tkinter.END)
     if "Please open a torrent file " in myJsonStr:
         pass
     else:
         jsonDict = json.loads(myJsonStr)
         tp.create_torrent_file(f"{name}.torrent", jsonDict)
コード例 #2
0
def add_torrent(torrent_file, dl_path):
    torrent = tp.parse_torrent_file(torrent_file)
    head, tail = os.path.split(dl_path)

    if ('files' in torrent['info']
        ):  # Torrent contains a folder, rather than a single file
        # Ensure that the torrent's root folder name is the same as the local folder's name
        torrent['info']['name'] = tail
        tp.create_torrent_file(torrent_file, torrent)

        # Adjust the DL path to be one folder up, so that it matches up correctly
        dl_path = head

    config = configparser.ConfigParser()
    config.read('config.ini')

    if not 'qBittorrent' in config:
        print('Torrent Loader requires that qBittorrent WebUI is enabled.')
        address = input('Address of WebUI (e.g. http://localhost:8080/): ')
        secured = input('Does WebUI require a login? (y/n) ')

        username = '******'
        password = '******'

        if secured == 'y':
            username = input('Username: '******'Password: '******'qBittorrent'] = {
            'address': address,
            'secured': secured,
            'username': username,
            'password': password
        }

        print()

    with open('config.ini', 'w') as config_file:
        config.write(config_file)

    qb = Client(config['qBittorrent']['address'])
    if config['qBittorrent']['secured'] == 'y':
        qb.login(config['qBittorrent']['username'],
                 config['qBittorrent']['password'])

    try:
        qb.download_from_file(open(torrent_file, 'rb'), savepath=dl_path)
        print('Added "' + torrent_file + '", content found in "' + dl_path +
              '"')
    except:
        print('An error occurred; the torrent probably already exists (' +
              torrent_file + ')')
コード例 #3
0
def addTracker(btFileName,trackList):
    data = tp.parse_torrent_file(btFileName)
    track = data['announce-list']
    for each in track:
        if each[0] in trackList:
            trackList.remove(each[0])

    if(len(trackList)>0):
        print("add new track ",len(trackList))
        for i in range(len(trackList)):
            track.append(trackList[i:i+1])
            
        tp.create_torrent_file(btFileName, data)

    else:
        print("there is nothing to add",btFileName)
コード例 #4
0
 def create_torrent(self, metadata):
     file_name = metadata["file"]
     path = self.path + "/" + file_name
     torrent_parser.create_torrent_file(f'{path}.torrent', metadata)
コード例 #5
0
def create_torrent(metainfo_dict):
    name = metainfo_dict["info"]["name"] + ".torrent"
    torrent_parser.create_torrent_file(name, metainfo_dict)
    return name
コード例 #6
0
import re


def md5_string(val):
	m = md5.new()
	matchObj = re.match(r'^(.*)\.(.*?)$', val)
	if matchObj:
		val = matchObj.group(1)
		m.update(val)
		return m.hexdigest() + '.' +  matchObj.group(2)
	else:
		m.update(val)
		return m.hexdigest()


data = tp.parse_torrent_file(sys.argv[1])

data['info']['name'] = md5_string(data['info']['name'].encode('utf-8'))
data['info']['publisher'] = md5_string(data['info']['publisher'].encode('utf-8'))
if 'name.utf-8' in data['info']:
	data['info']['name.utf-8'] = md5_string(data['info']['name.utf-8'].encode('utf-8'))
if 'publisher.utf-8' in data['info']:
	data['info']['publisher.utf-8'] = md5_string(data['info']['publisher.utf-8'].encode('utf-8'))

for i in range(0, len(data['info']['files'])):
	data['info']['files'][i]['path'][0] = md5_string(data['info']['files'][i]['path'][0].encode('utf-8'))
	if 'path.utf-8' in data['info']['files'][i]:
		data['info']['files'][i]['path.utf-8'][0] = md5_string(data['info']['files'][i]['path.utf-8'][0].encode('utf-8'))

tp.create_torrent_file(sys.argv[2], data)