0

我正在尝试为日常使用制作一个自动化脚本,现在我想在 uTorrents Web UI http://www.utorrent.com/community/developers/webapi#devs7中使用此操作。获取下载的 torrent 中的文件列表。

一个小代码只是为了看看输出是如何工作的:

import sys
from utorrent.client import UTorrentClient

uTorrent = UTorrentClient("secret", "secret", "secret")
hash = sys.argv[1]

if uTorrent:
    read = uTorrent.getfiles(hash)
    for line in read:
        print line

那会输出这样的东西;

{u'files': [u'BA99812BAF360F1913D6D98ED8219A94176BAD4C', [[u'This.is.the.file.i.dow​​nloaded.with.uTorrent.zip', 9596597617L, 9596597617L, 2, 0, 2289, True, 164433, 62 , 1920, 816, -1]]], u'build': 28705}

或者对于几个文件:

{u'files': [u'67B8F560C81233F3A38F859D99D43193C97A17C6', [[u'This.is.the.file.i.dow​​nloaded.with.uTorrent1.zip', 39900, 39900, 2, 0, 1, False, -1, -1, -1, -1, -1], [u'This.is.the.file.i.dow​​nloaded.with.uTorrent.zip', 10090482895L, 10090482895L, 2, 0, 4812, True, 230676, 6505 , 1920, 1080, -1], [u'This.is.the.file.i.dow​​nloaded.with.uTorrent.zip', 6670336, 6670336, 2, 4811, 4, False, -1, -1, - 1, -1, -1]]], u'build': 28705}

现在到主要问题;如何将输出有效地解析(仅提取文件)到一个列表中,稍后我可以在列表中循环并根据文件扩展名做一些事情?我一直在拉我的头发,不知道该怎么办

4

1 回答 1

1

要获取文件列表,请使用此 URI

http://[IP]:[PORT]/gui/?action=getfiles&hash=[TORRENT HASH] 

它发回这个:

{
    "build": NUMÉRO DE VERSION (entier),
    "files": [
    HACHAGE (chaîne),
    [
    [
    FILE NAME (NOM DE FICHIER) (chaîne),
    FILE SIZE (TAILLE DE FICHIER) (entier, en octets),
    TÉLÉCHARGÉ (entier, en octets),
    PRIORITY (PRIORITÉ)* (entier)   ],
    ...
    ]
    ]
}

使用您退回的样品:

我只是做

a = {u'files': [u'67B8F560C81233F3A38F859D99D43193C97A17C6', [[u'This.is.the.file.i.downloaded.with.uTorrent1.zip', 39900, 39900, 2, 0, 1, False, -1, -1, -1, -1, -1], [u'This.is.the.file.i.downloaded.with.uTorrent.zip', 10090482895L, 10090482895L, 2, 0, 4812, True, 230676, 6505, 1920, 1080, -1], [u'This.is.the.file.i.downloaded.with.uTorrent.zip', 6670336, 6670336, 2, 4811, 4, False, -1, -1, -1, -1, -1]]], u'build': 28705}

z = a['files']

f = z.pop()

获取第一个元素是名称的文件列表的列表

f[0][0]

u'This.is.the.file.i.downloaded.with.uTorrent1.zip'
于 2013-05-16T07:44:12.927 回答