From 34b064700fa89a31b8e0f90291605640baf3331f Mon Sep 17 00:00:00 2001 From: Ken Chou Date: Wed, 13 Dec 2017 11:09:40 +0800 Subject: [PATCH 1/2] add Shebang --- aria2_to_magnet.py | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 aria2_to_magnet.py diff --git a/aria2_to_magnet.py b/aria2_to_magnet.py old mode 100644 new mode 100755 index db6c343..da7b085 --- a/aria2_to_magnet.py +++ b/aria2_to_magnet.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python import struct import binascii import argparse From c876043220c7fd454dac90212b88bc73b2b8af03 Mon Sep 17 00:00:00 2001 From: Ken Chou Date: Wed, 13 Dec 2017 11:48:41 +0800 Subject: [PATCH 2/2] support multiple files --- README.md | 15 ++++++++++----- aria2_to_magnet.py | 7 ++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e9437fc..9015746 100644 --- a/README.md +++ b/README.md @@ -44,14 +44,19 @@ also @alphatr write a tool transform .aria2 file to a magnet link use javascript # ================================================================ ``` -# how to run - -``` -python aria2_to_magnet.py -f dahufa.aria2 +## how to run +```bash +python aria2_to_magnet.py dahufa.aria2 ``` output ``` magnet:?xt=urn:btih:959E2ECEB954313D3869EFF7924CA7CD8DE739 -``` \ No newline at end of file +``` + +with multiple files +```bash +python aria2_to_magnet.py *.aria2 +``` + diff --git a/aria2_to_magnet.py b/aria2_to_magnet.py index da7b085..c250c24 100755 --- a/aria2_to_magnet.py +++ b/aria2_to_magnet.py @@ -4,7 +4,7 @@ import binascii import argparse parser = argparse.ArgumentParser() -parser.add_argument("-f", "--file", required=True, +parser.add_argument("file", nargs='+', help="input file XXX.aria2") args = parser.parse_args() @@ -76,8 +76,9 @@ def parse_aria_control_file(file_name): if __name__ == '__main__': - file_name = args.file - parse_aria_control_file(file_name) + file_list = args.file + for file_name in file_list: + parse_aria_control_file(file_name) # version is 1 # hash length is 20 # magnet:?xt=urn:btih:959E2ECEB954313D38690EFF7924CA7CD80DE739