diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4a4a418..a691495 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,7 @@ - + @@ -14,16 +14,16 @@ - + - - + + - - + + @@ -34,8 +34,8 @@ - - + + @@ -44,7 +44,7 @@ - + @@ -126,8 +126,8 @@ - + @@ -179,8 +179,8 @@ @@ -393,7 +393,49 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -437,16 +479,16 @@ - + - + - - + + @@ -455,8 +497,8 @@ - - + + diff --git a/README.md b/README.md index 4578ee7..bb8b45f 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,16 @@ also @alphatr write a tool transform .aria2 file to a magnet link use javascript # more detail # https://aria2.github.io/manual/en/html/technical-notes.html # ================================================================ +``` + +# how to run + +``` +python.exe aria2_to_magnet.py -f dahufa.aria2 + +``` + +output +``` +magnet:?xt=urn:btih:959E2ECEB954313D3869EFF7924CA7CD8DE739 ``` \ No newline at end of file diff --git a/read_a2.py b/aria2_to_magnet.py similarity index 88% rename from read_a2.py rename to aria2_to_magnet.py index 5ce67bc..363dd4b 100644 --- a/read_a2.py +++ b/aria2_to_magnet.py @@ -1,5 +1,12 @@ import struct import binascii +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument("-f", "--file", required=True, + help="input file XXX.aria2") + +args = parser.parse_args() # ================================================================ @@ -40,14 +47,14 @@ def parse_aria_control_file(file_name): version = f.read(2) i = int(version.encode('hex'), 16) - print "version is " + str(i) + # print "version is " + str(i) # skip EXT, find info hash_binary length f.seek(6) length = f.read(4) hash_length = int(length.encode('hex'), 16) - print "hash length is " + str(hash_length) + # print "hash length is " + str(hash_length) # read next hash_length f.seek(10) # Go to info hash @@ -67,7 +74,8 @@ def parse_aria_control_file(file_name): if __name__ == '__main__': - parse_aria_control_file("dahufa.aria2") + file_name = args.file + parse_aria_control_file(file_name) # version is 1 # hash length is 20 # magnet:?xt=urn:btih:959E2ECEB954313D3869EFF7924CA7CD8DE739