吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2289|回复: 9
上一主题 下一主题
收起左侧

[Python 原创] 种子文件转磁力链接 torrent2magnet

  [复制链接]
跳转到指定楼层
楼主
maxkingmax 发表于 2023-12-15 12:39 回帖奖励
功能如题,注意问题如下:
1.默认写入注册表关联种子文件,不喜欢修改源码 winreg.SetValue 那几行注释掉;
2.默认转换个人下载文件夹中的种子文件并将磁力链接复制到剪切板;
3.如果python版本较旧,请修改torrent_file_to_magnet(torrent_file)函数中的[b'info'][b'name'] 把 b 去掉再试;
4.默认转换成功后,删除种子文件,不喜欢可修改最后一行。

[Python] 纯文本查看 复制代码
######################################
#种子文件批量转换成磁力链
#运行前需要安装依赖

#  pip install bencode.py==3.0.1

#  Pip install pyperclip

#可以打包成可执行程序

#  Pip install pyinstaller

#  Pyinstaller -F torrent2magnet.py
######################################


#import sys,os


#print(r'C:\Windows\py.exe "'+ __file__ +r'" %1')

import winreg
import bencode
import hashlib
import os
import pyperclip
import sys
from urllib.parse import quote


data_dir = os.environ['USERPROFILE']+'\Downloads'
###print(sys.argv)

if len(sys.argv)==2:
    if os.path.isdir(sys.argv[1]):
        ###print(sys.argv[1])
        data_dir = sys.argv[1]
    elif os.path.isfile(sys.argv[1]):
        ###print(os.path.dirname(sys.argv[1]))
        data_dir = os.path.dirname(sys.argv[1])
else:
    try:
        winreg.SetValue(winreg.HKEY_CLASSES_ROOT, r".torrent",winreg.REG_SZ,r"Torrent.Document")
        winreg.SetValue(winreg.HKEY_CLASSES_ROOT, r"Torrent.Document\shell\open\command",winreg.REG_SZ,sys.executable+r' "'+ __file__ +r'" %1')
        print(sys.executable+r' "'+ __file__ +r'" %1')
        print("已成功关联种子文件")
    except:
        print('请在“以管理员身份运行”的CMD窗口中调用本程序,命令行如下: \npy "'+__file__+'"')
        print('如果已经可以正常双击“种子”文件进行转换,请忽略!')
        print('')

###os.system("pause")

torrent=[]
magnet=[]
 
def torrent_file_to_magnet(torrent_file):
    data =  open(torrent_file, 'rb').read()
    metadata = bencode.bdecode(data)
    # print(metadata)
    name = metadata[b'info'][b'name']
    dn = quote(name)
    info_bts = bencode.bencode(metadata[b'info'])
    info_hash = hashlib.sha1(info_bts).hexdigest()
    return f'magnet:?xt=urn:btih:{info_hash}'#&dn={dn}'
 
'''
if __name__ == '__main__':
    print(torrent_file_to_magnet('[ThZu.Cc][ThZu.Cc]020421-001-carib-1080p.torrent'))
'''


"""--------------------------------------------------------
<<获取文件列表>>
(1) os.listdir() 方法用于返回指定的文件夹包含的文件或文件夹的名字的列表。
这个列表以字母顺序。 它不包括 '.' 和'..' 即使它在文件夹中。只支持在
Unix, Windows 下使用。
(2) os.path.join(path1[, path2[, ...]])    把目录和文件名合成一个路径
---------------------------------------------------------"""



"""获取文件列表"""
def getRawFileList(path):
    """-------------------------
    files,names=getRawFileList(raw_data_dir)
    files: ['datacn/dialog/one.txt', 'datacn/dialog/two.txt']
    names: ['one.txt', 'two.txt']
    ----------------------------"""
    files = []
    names = []
    for f in os.listdir(path):
        if  not f.endswith("~") or not f == "" :      # 返回指定的文件夹包含的文件或文件夹的名字的列表
            files.append(os.path.join(path, f))     # 把目录和文件名合成一个路径
            names.append(f)
    return files, names

files,names = getRawFileList(data_dir)
'''print("files:", files)
print("names:", names)'''


for tf in files:
    if tf.endswith(".torrent"):
        torrent.append(tf)
'''print(torrent)'''

for to in torrent:
    magnet.append(torrent_file_to_magnet(to))
txt=""
for l in magnet:
    print(l)
    txt=l+'\n'+txt
print("成功转换",len(magnet),"个磁力链接")
pyperclip.copy(txt)
os.system("pause")
for i in torrent:
    os.remove(i)

免费评分

参与人数 3吾爱币 +7 热心值 +3 收起 理由
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
loonyjoy + 1 + 1 谢谢@Thanks!
helian147 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

沙发
helian147 发表于 2023-12-15 16:11
大佬,磁力转种子文件是怎么转换?
3#
QRQF001 发表于 2023-12-15 16:23
我是用拖进qb或者Xdown
至于磁力转种子文件,用迅雷下载磁力,下载目录就有一个种子文件(隐藏属性)
4#
 楼主| maxkingmax 发表于 2023-12-15 19:18 |楼主
helian147 发表于 2023-12-15 16:11
大佬,磁力转种子文件是怎么转换?

应该能网上转换,可以写个爬虫
https://btsow.motorcycles/convert/magnet
https://magnet2torrent.com/
https://m2t.lolicon.app/
5#
 楼主| maxkingmax 发表于 2023-12-15 19:25 |楼主
helian147 发表于 2023-12-15 16:11
大佬,磁力转种子文件是怎么转换?

比如这个磁力链接:magnet:?xt=urn:btih:66522e025c46c7f5c1ffba7133d702bdf02bb963
刚看了一下,可以访问这个地址直接下载,注意:把 magnet:?xt=urn:btih: 替换为https://m2t.lolicon.app/m/ 就行
https://m2t.lolicon.app/m/66522e025c46c7f5c1ffba7133d702bdf02bb963

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
helian147 + 1 + 1 谢谢@Thanks!

查看全部评分

6#
FruitBaby 发表于 2023-12-15 22:40
是下载种子吗,还是怎么的
7#
 楼主| maxkingmax 发表于 2023-12-17 09:24 |楼主
FruitBaby 发表于 2023-12-15 22:40
是下载种子吗,还是怎么的

是把下载的种子文件(扩展名为.torrent的文件)转为磁力链接 magnet:?xt=urn:btih:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 的工具
8#
FruitBaby 发表于 2023-12-17 10:16
maxkingmax 发表于 2023-12-17 09:24
是把下载的种子文件(扩展名为.torrent的文件)转为磁力链接 magnet:?xt=urn:btih:xxxxxxxxxxxxxxxxxxxxx ...

哦哦,是这样啊,下载试用下,感谢
9#
湖底的猪 发表于 2023-12-17 10:18
有成品吗?
10#
turmasi1234 发表于 2023-12-19 11:20
感谢大佬分享的好东西,方便
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-14 02:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表