-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser_torrent.py
38 lines (28 loc) · 1 KB
/
parser_torrent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
'''
为了匹配ut传过来的消息,根据torrent信息返回种子内容下载的:
1、文件就一个的话:相对路径
2、文件多个的话: 所在目录和某个视频相对路径
'''
import torrent_parser as tp
def get_info_from_torrent(file):
data = tp.parse_torrent_file(file)
info = data['info']
file_dir = info['name']
if 'files' in info.keys():
biggest = 0
file_path = ''
files = info['files']
for file in files:
if file['length'] > biggest
if file['path'][-1].endswith(('mp4','mkv','avi','ts','mov')):
biggest = file['length']
file_path = '\\'.join(file['path'])
file_path = file_dir+'\\'+file_path
return file_dir, file_path
else:
return file_dir, file_dir
if __name__ == "__main__":
# file_ = r'C:\test.torrent'
file_ = input('请输入一个种子的绝对路径')
print(get_info_from_torrent(file_))