From a22e8e96063248a5993341b15b9214580b883f39 Mon Sep 17 00:00:00 2001 From: solderzzc Date: Tue, 4 Aug 2015 15:47:18 -0700 Subject: [PATCH 01/26] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4a018df..858e260 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ A command line tool that converts magnet links in to .torrent files. ## How to Use `python Magnet_To_Torrent2.py [torrent file]` +## To install libtorrent-python on Mac +`brew install libtorrent-rasterbar --with-python` + ### Example `python Magnet_To_Torrent2.py "magnet:?xt=urn:btih:49fbd26322960d982da855c54e36df19ad3113b8&dn=ubuntu-12.04-desktop-i386.iso&tr=udp%3A%2F%2Ftracker.openbittorrent.com" ubunut12-04.iso` From 09611b858c7a08be022899b8f6ef8de7e1328329 Mon Sep 17 00:00:00 2001 From: hpfn Date: Sun, 28 Feb 2016 09:32:04 -0300 Subject: [PATCH 02/26] add_magnet_uri is deprecated add_magnet_uri() is deprecated. Using add_torrent(). I also add a listen_on() to set ports and a "info msg" if the download is taking to much time. I tested 10 times with sucess. --- Magnet_To_Torrent2.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index d8d648c..99df5ce 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -41,19 +41,38 @@ def magnet2torrent(magnet, output_name=None): tempdir = tempfile.mkdtemp() ses = lt.session() + # one could want to set this + #ses.listen_on(6881, 6882) + + # add 'url'. for add_torrent() params = { + 'url': magnet, 'save_path': tempdir, 'storage_mode': lt.storage_mode_t(2), 'paused': False, 'auto_managed': True, 'duplicate_is_error': True } - handle = lt.add_magnet_uri(ses, magnet, params) + # add_magnet_uri is deprecated + # http://www.rasterbar.com/products/libtorrent/manual.html#add-magnet-uri + #handle = lt.add_magnet_uri(ses, magnet, params) + handle = ses.add_torrent(params) print("Downloading Metadata (this may take a while)") + + # used to control "Maybe..." and "or the" msgs + # after sleep(1) + x = 1 + limit = 120 + while (not handle.has_metadata()): try: sleep(1) + if x > limit: + print("Maybe your firewall is blocking, ") + print(" or the magnet link is not right...") + limit += 30 + x += 1 except KeyboardInterrupt: print("Aborting...") ses.pause() From c53d079931677eab8d1f542d1e2e2a182ab41c45 Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 09:57:31 +0800 Subject: [PATCH 03/26] chg: use name in magnet if no output filename is given. --- Magnet_To_Torrent2.py | 94 +++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 57 deletions(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index 67b04bf..9482a7e 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -1,5 +1,6 @@ #!/usr/bin/env python -''' +"""convert magnet link to torrent file. + Created on Apr 19, 2012 @author: dan, Faless @@ -20,18 +21,23 @@ http://www.gnu.org/licenses/gpl-3.0.txt -''' +""" -import shutil -import tempfile +import libtorrent as lt import os.path as pt +import shutil import sys -import libtorrent as lt -from time import sleep +import tempfile from argparse import ArgumentParser +from time import sleep +try: + from urllib.parse import unquote +except ImportError: + from urllib import unquote def magnet2torrent(magnet, output_name=None): + """convert magent2torrent.""" if output_name and \ not pt.isdir(output_name) and \ not pt.isdir(pt.dirname(pt.abspath(output_name))): @@ -76,7 +82,7 @@ def magnet2torrent(magnet, output_name=None): output = pt.abspath(output_name) print("Saving torrent file here : " + output + " ...") - torcontent = lt.bencode(torfile.generate()) + # torcontent = lt.bencode(torfile.generate()) # not used f = open(output, "wb") f.write(lt.bencode(torfile.generate())) f.close() @@ -86,57 +92,31 @@ def magnet2torrent(magnet, output_name=None): return output -def main(): - parser = ArgumentParser(description="A command line tool that converts magnet links in to .torrent files") - parser.add_argument('-m','--magnet', help='The magnet url') - parser.add_argument('-o','--output', help='The output torrent file name') - - # - # This second parser is created to force the user to provide - # the 'output' arg if they provide the 'magnet' arg. - # - # The current version of argparse does not have support - # for conditionally required arguments. That is the reason - # for creating the second parser - # - # Side note: one should look into forking argparse and adding this - # feature. - # - conditionally_required_arg_parser = ArgumentParser(description="A command line tool that converts magnet links in to .torrent files") - conditionally_required_arg_parser.add_argument('-m','--magnet', help='The magnet url') - conditionally_required_arg_parser.add_argument('-o','--output', help='The output torrent file name', required=True) - - magnet = None - output_name = None - - # - # Attempting to retrieve args using the new method - # - args = vars(parser.parse_known_args()[0]) - if args['magnet'] is not None: - magnet = args['magnet'] - argsHack = vars(conditionally_required_arg_parser.parse_known_args()[0]) - output_name = argsHack['output'] - if args['output'] is not None and output_name is None: - output_name = args['output'] - if magnet is None: - # - # This is a special case. - # This is when the user provides only the "output" args. - # We're forcing him to provide the 'magnet' args in the new method - # - print ('usage: {0} [-h] [-m MAGNET] -o OUTPUT'.format(sys.argv[0])) - print ('{0}: error: argument -m/--magnet is required'.format(sys.argv[0])) - sys.exit() - # - # Defaulting to the old of doing things - # - if output_name is None and magnet is None: - if len(sys.argv) >= 2: - magnet = sys.argv[1] - if len(sys.argv) >= 3: - output_name = sys.argv[2] +def main(): + """main function.""" + # parsing the argument. + description = "A command line tool that converts magnet links in to .torrent files" + parser = ArgumentParser(description=description) + parser.add_argument('-m', '--magnet', help='The magnet url', required=True) + parser.add_argument('-o', '--output', help='The output torrent file name') + args = parser.parse_args(sys.argv[1:]) + output_name = args.output + magnet = args.magnet + + # guess the name if output name is not given. + # in magnet link it is between'&dn' and '&tr' + if output_name is None: + output_name = magnet.split('&dn=')[1].split('&tr')[0] + if '+' in output_name: + output_name = unquote(output_name) + output_name += '.torrent' + + # encode magnet link if it appear url decoded. + if magnet != unquote(magnet): + magnet = unquote(magnet) + + # run the converter magnet2torrent(magnet, output_name) From 109807752f45b81f19688b9dea039e5a583af287 Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 10:19:03 +0800 Subject: [PATCH 04/26] new: new option to rewrite the file(or not) if file exist. --- Magnet_To_Torrent2.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index 9482a7e..a5e14f1 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -30,6 +30,7 @@ import tempfile from argparse import ArgumentParser from time import sleep +from os.path import isfile, splitext try: from urllib.parse import unquote except ImportError: @@ -100,6 +101,12 @@ def main(): parser = ArgumentParser(description=description) parser.add_argument('-m', '--magnet', help='The magnet url', required=True) parser.add_argument('-o', '--output', help='The output torrent file name') + parser.add_argument('--rewrite-file', help='Rewrite torrent file if exist(default)', + dest='rewrite_file', action='store_true') + parser.add_argument('--no-rewrite-file', + help='Create a new filename if torrent exist.', + dest='rewrite_file', action='store_false') + parser.set_defaults(rewrite_file=True) args = parser.parse_args(sys.argv[1:]) output_name = args.output magnet = args.magnet @@ -112,6 +119,19 @@ def main(): output_name = unquote(output_name) output_name += '.torrent' + # create fullname if file exist. + if isfile(output_name) and not args.rewrite_file: + new_output_name = output_name + counter = 1 + while isfile(new_output_name): + non_basename, non_ext = splitext(new_output_name) + if counter - 1 != 0: + non_basename = non_basename.rsplit('_{}'.format(counter - 1), 1)[0] + non_basename += '_{}'.format(counter) + new_output_name = '{}{}'.format(non_basename, non_ext) + counter += 1 + output_name = new_output_name + # encode magnet link if it appear url decoded. if magnet != unquote(magnet): magnet = unquote(magnet) From 4e32e1d6a2741c2e3c56481e8511b760f6b0bd72 Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 10:25:39 +0800 Subject: [PATCH 05/26] new: create option to skip file if file already exist. --- Magnet_To_Torrent2.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index a5e14f1..b28d371 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -101,12 +101,17 @@ def main(): parser = ArgumentParser(description=description) parser.add_argument('-m', '--magnet', help='The magnet url', required=True) parser.add_argument('-o', '--output', help='The output torrent file name') + # rewrite file option parser.add_argument('--rewrite-file', help='Rewrite torrent file if exist(default)', dest='rewrite_file', action='store_true') parser.add_argument('--no-rewrite-file', help='Create a new filename if torrent exist.', dest='rewrite_file', action='store_false') parser.set_defaults(rewrite_file=True) + # Skip file if exist option + parser.add_argument('--skip-file', help='Skip file if file already exist.', + dest='skip_file', action='store_true') + parser.set_defaults(skip_file=False) args = parser.parse_args(sys.argv[1:]) output_name = args.output magnet = args.magnet @@ -119,6 +124,11 @@ def main(): output_name = unquote(output_name) output_name += '.torrent' + # return if user want to skip existing file. + if isfile(output_name) and args.skip_file: + print('File [{}] is already exist.'.format(output_name)) + return + # create fullname if file exist. if isfile(output_name) and not args.rewrite_file: new_output_name = output_name @@ -141,4 +151,4 @@ def main(): if __name__ == "__main__": - main() + sys.exit(main()) From 11d80aa7deec826cac9fcd77fd395b87944a01ce Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 10:41:50 +0800 Subject: [PATCH 06/26] new: option to open the torrent after converting magnet link. --- Magnet_To_Torrent2.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index b28d371..7b9b500 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -24,8 +24,10 @@ """ import libtorrent as lt +import os import os.path as pt import shutil +import subprocess import sys import tempfile from argparse import ArgumentParser @@ -94,6 +96,16 @@ def magnet2torrent(magnet, output_name=None): return output +def open_file(filepath): + """open filepath with default application for each operating system.""" + if sys.platform.startswith('darwin'): + subprocess.call(('open', filepath)) + elif os.name == 'nt': + os.startfile(filepath) + elif os.name == 'posix': + subprocess.call(('xdg-open', filepath)) + + def main(): """main function.""" # parsing the argument. @@ -112,6 +124,10 @@ def main(): parser.add_argument('--skip-file', help='Skip file if file already exist.', dest='skip_file', action='store_true') parser.set_defaults(skip_file=False) + # open file after creating torrent file + parser.add_argument('--open-file', help='Open file after conferting.', + dest='open_file', action='store_true') + parser.set_defaults(open_file=False) args = parser.parse_args(sys.argv[1:]) output_name = args.output magnet = args.magnet @@ -127,6 +143,9 @@ def main(): # return if user want to skip existing file. if isfile(output_name) and args.skip_file: print('File [{}] is already exist.'.format(output_name)) + # still open file if file already existed. + if args.open_file: + open_file(output_name) return # create fullname if file exist. @@ -149,6 +168,9 @@ def main(): # run the converter magnet2torrent(magnet, output_name) + if args.open_file: + open_file(output_name) + if __name__ == "__main__": sys.exit(main()) From 839422fe2b8512a491ea40e79f173ae29145b582 Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 11:15:46 +0800 Subject: [PATCH 07/26] chg: update readme. --- README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b6bbfbb..e5538b4 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,28 @@ A command line tool that converts magnet links in to .torrent files. ### This project is mostly abandoned. I will still merge most pull requests. ## Requirements -* python -* python-libtorrent (libtorrent-rasterbar version 0.16 or later) +* python2.7/3.5 +* python-libtorrent (libtorrent-rasterbar version 0.16 or later) for python 2.7 or + python3-libtorrent for python 3.5 ## How to Use -`python Magnet_To_Torrent2.py [torrent file]` + + usage: Magnet_To_Torrent2.py [-h] -m MAGNET [-o OUTPUT] [--rewrite-file] + [--no-rewrite-file] [--skip-file] [--open-file] + +A command line tool that converts magnet links in to .torrent files + +optional arguments: + + -h, --help show this help message and exit + -m MAGNET, --magnet MAGNET + The magnet url + -o OUTPUT, --output OUTPUT + The output torrent file name + --rewrite-file Rewrite torrent file if exist(default) + --no-rewrite-file Create a new filename if torrent exist. + --skip-file Skip file if file already exist. + --open-file Open file after conferting. ### Example `python Magnet_To_Torrent2.py -m "magnet:?xt=urn:btih:49fbd26322960d982da855c54e36df19ad3113b8&dn=ubuntu-12.04-desktop-i386.iso&tr=udp%3A%2F%2Ftracker.openbittorrent.com" -o ubunut12-04.iso` From d115ba5880f7ccdaa5c0aa70c450f1d066fc0013 Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 11:26:28 +0800 Subject: [PATCH 08/26] chg: change status as active. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e5538b4..72baae6 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ A command line tool that converts magnet links in to .torrent files. -### This project is mostly abandoned. I will still merge most pull requests. - ## Requirements * python2.7/3.5 * python-libtorrent (libtorrent-rasterbar version 0.16 or later) for python 2.7 or From a53f042054c43cfc919682b7e3898fda1848e023 Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 11:26:52 +0800 Subject: [PATCH 09/26] chg: fix typo. --- Magnet_To_Torrent2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index 7b9b500..cde5328 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -125,7 +125,7 @@ def main(): dest='skip_file', action='store_true') parser.set_defaults(skip_file=False) # open file after creating torrent file - parser.add_argument('--open-file', help='Open file after conferting.', + parser.add_argument('--open-file', help='Open file after converting.', dest='open_file', action='store_true') parser.set_defaults(open_file=False) args = parser.parse_args(sys.argv[1:]) From 9e9f63500e3e548c94b86aea2696ebcfc47d735d Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 19:55:20 +0800 Subject: [PATCH 10/26] chg: fix runtimerror when torrent already exist in sessin. --- Magnet_To_Torrent2.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index f8411a0..7e60b90 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -1,9 +1,7 @@ #!/usr/bin/env python """convert magnet link to torrent file. -Created on Apr 19, 2012 -@author: dan, Faless - +Created on Apr 19, 2012 @author: dan, Faless GNU GENERAL PUBLIC LICENSE - Version 3 This program is free software: you can redistribute it and/or modify @@ -51,8 +49,8 @@ def magnet2torrent(magnet, output_name=None): tempdir = tempfile.mkdtemp() ses = lt.session() # one could want to set this - #ses.listen_on(6881, 6882) - + # ses.listen_on(6881, 6882) + # add 'url'. for add_torrent() params = { 'url': magnet, @@ -64,16 +62,20 @@ def magnet2torrent(magnet, output_name=None): } # add_magnet_uri is deprecated # http://www.rasterbar.com/products/libtorrent/manual.html#add-magnet-uri - #handle = lt.add_magnet_uri(ses, magnet, params) - handle = ses.add_torrent(params) + # handle = lt.add_magnet_uri(ses, magnet, params) + try: + handle = ses.add_torrent(params) + except RuntimeError: + params['duplicate_is_error'] = False + handle = ses.add_torrent(params) print("Downloading Metadata (this may take a while)") - + # used to control "Maybe..." and "or the" msgs # after sleep(1) x = 1 limit = 120 - + while (not handle.has_metadata()): try: sleep(1) From 349e3dd97c192fde3588acbff761df70482b6bda Mon Sep 17 00:00:00 2001 From: dani Date: Tue, 12 Apr 2016 20:36:06 +0800 Subject: [PATCH 11/26] chg: convert function to class to simplify the process. --- Magnet_To_Torrent2.py | 177 +++++++++++++++++++++++------------------- 1 file changed, 99 insertions(+), 78 deletions(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index 7e60b90..3b47b65 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -37,84 +37,104 @@ from urllib import unquote -def magnet2torrent(magnet, output_name=None): - """convert magent2torrent.""" - if output_name and \ - not pt.isdir(output_name) and \ - not pt.isdir(pt.dirname(pt.abspath(output_name))): - print("Invalid output folder: " + pt.dirname(pt.abspath(output_name))) - print("") - sys.exit(0) - - tempdir = tempfile.mkdtemp() - ses = lt.session() - # one could want to set this - # ses.listen_on(6881, 6882) - - # add 'url'. for add_torrent() - params = { - 'url': magnet, - 'save_path': tempdir, - 'storage_mode': lt.storage_mode_t(2), - 'paused': False, - 'auto_managed': True, - 'duplicate_is_error': True - } - # add_magnet_uri is deprecated - # http://www.rasterbar.com/products/libtorrent/manual.html#add-magnet-uri - # handle = lt.add_magnet_uri(ses, magnet, params) - try: - handle = ses.add_torrent(params) - except RuntimeError: - params['duplicate_is_error'] = False - handle = ses.add_torrent(params) - - print("Downloading Metadata (this may take a while)") - - # used to control "Maybe..." and "or the" msgs - # after sleep(1) - x = 1 - limit = 120 - - while (not handle.has_metadata()): +class Magnet2Torrent: + """class for converter from magnet link to torrent.""" + + def __init__(self, magnet, output_name=None): + """init function. + + check for validity of the input. + + Raises: + ValueError: if input is not valid this error will be raise + """ + if output_name and \ + not pt.isdir(output_name) and \ + not pt.isdir(pt.dirname(pt.abspath(output_name))): + raise ValueError("Invalid output folder: " + pt.dirname(pt.abspath(output_name))) + self.output_name = output_name + # create tempdir + self.tempdir = tempfile.mkdtemp() + # create session + self.ses = lt.session() + # one could want to set this + # ses.listen_on(6881, 6882) + + # add 'url'. for add_torrent() + params = { + 'url': magnet, + 'save_path': self.tempdir, + 'storage_mode': lt.storage_mode_t(2), + 'paused': False, + 'auto_managed': True, + 'duplicate_is_error': True + } + # add_magnet_uri is deprecated + # http://www.rasterbar.com/products/libtorrent/manual.html#add-magnet-uri + # handle = lt.add_magnet_uri(ses, magnet, params) try: - sleep(1) - if x > limit: - print("Maybe your firewall is blocking, ") - print(" or the magnet link is not right...") - limit += 30 - x += 1 - except KeyboardInterrupt: - print("Aborting...") - ses.pause() - print("Cleanup dir " + tempdir) - shutil.rmtree(tempdir) - sys.exit(0) - ses.pause() - print("Done") - - torinfo = handle.get_torrent_info() - torfile = lt.create_torrent(torinfo) - - output = pt.abspath(torinfo.name() + ".torrent") - - if output_name: - if pt.isdir(output_name): - output = pt.abspath(pt.join( - output_name, torinfo.name() + ".torrent")) - elif pt.isdir(pt.dirname(pt.abspath(output_name))): - output = pt.abspath(output_name) - - print("Saving torrent file here : " + output + " ...") - # torcontent = lt.bencode(torfile.generate()) # not used - f = open(output, "wb") - f.write(lt.bencode(torfile.generate())) - f.close() - print("Saved! Cleaning up dir: " + tempdir) - ses.remove_torrent(handle) - shutil.rmtree(tempdir) - - return output + self.handle = self.ses.add_torrent(params) + except RuntimeError: + params['duplicate_is_error'] = False + self.handle = self.ses.add_torrent(params) + + def run(self): + """run the converter. + + using the class attribute initiated at init function. + + Returns: + Filename of created torrent. + + Raises: + KeyboardInterrupt: This error caused by user to stop this. + When downloading metada from magnet link, + it require additional step before the error reraised again. + """ + print("Downloading Metadata (this may take a while)") + # used to control "Maybe..." and "or the" msgs + # after sleep(1) + x = 1 + limit = 120 + + while (not self.handle.has_metadata()): + try: + sleep(1) + if x > limit: + print("Maybe your firewall is blocking, ") + print(" or the magnet link is not right...") + limit += 30 + x += 1 + except KeyboardInterrupt as ee: + print("Aborting...") + self.ses.pause() + print("Cleanup dir " + self.tempdir) + shutil.rmtree(self.tempdir) + raise ee + self.ses.pause() + print("Done") + + torinfo = self.handle.get_torrent_info() + torfile = lt.create_torrent(torinfo) + + output = pt.abspath(torinfo.name() + ".torrent") + + if self.output_name: + if pt.isdir(self.output_name): + output = pt.abspath(pt.join(self.output_name, torinfo.name() + ".torrent")) + elif pt.isdir(pt.dirname(pt.abspath(self.output_name))): + output = pt.abspath(self.output_name) + + print("Saving torrent file here : " + output + " ...") + # torcontent = lt.bencode(torfile.generate()) # not used + f = open(output, "wb") + f.write(lt.bencode(torfile.generate())) + f.close() + print("Saved! Cleaning up dir: " + self.tempdir) + self.ses.remove_torrent(self.handle) + shutil.rmtree(self.tempdir) + + return output def open_file(filepath): @@ -187,7 +207,8 @@ def main(): magnet = unquote(magnet) # run the converter - magnet2torrent(magnet, output_name) + conv = Magnet2Torrent(magnet, output_name) + conv.run() if args.open_file: open_file(output_name) From 53df6ee2dfdeb2d8ffd8417a54ec04f992b8390e Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 28 Jun 2016 21:55:11 +0100 Subject: [PATCH 12/26] Fix needless RuntimeError handling --- Magnet_To_Torrent2.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index 3b47b65..b1c7e42 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -67,16 +67,9 @@ def __init__(self, magnet, output_name=None): 'storage_mode': lt.storage_mode_t(2), 'paused': False, 'auto_managed': True, - 'duplicate_is_error': True + 'duplicate_is_error': False } - # add_magnet_uri is deprecated - # http://www.rasterbar.com/products/libtorrent/manual.html#add-magnet-uri - # handle = lt.add_magnet_uri(ses, magnet, params) - try: - self.handle = self.ses.add_torrent(params) - except RuntimeError: - params['duplicate_is_error'] = False - self.handle = self.ses.add_torrent(params) + self.handle = self.ses.add_torrent(params) def run(self): """run the converter. From a105a6102ab8a3d36bea7fd20b339d02f0408e40 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 28 Jun 2016 21:59:45 +0100 Subject: [PATCH 13/26] Some minor tidyups --- Magnet_To_Torrent2.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index b1c7e42..5e69272 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -21,7 +21,6 @@ """ -import libtorrent as lt import os import os.path as pt import shutil @@ -30,11 +29,11 @@ import tempfile from argparse import ArgumentParser from time import sleep -from os.path import isfile, splitext try: from urllib.parse import unquote except ImportError: from urllib import unquote +import libtorrent as lt class Magnet2Torrent: @@ -90,7 +89,7 @@ def run(self): x = 1 limit = 120 - while (not self.handle.has_metadata()): + while not self.handle.has_metadata(): try: sleep(1) if x > limit: @@ -98,12 +97,12 @@ def run(self): print(" or the magnet link is not right...") limit += 30 x += 1 - except KeyboardInterrupt as ee: + except KeyboardInterrupt: print("Aborting...") self.ses.pause() print("Cleanup dir " + self.tempdir) shutil.rmtree(self.tempdir) - raise ee + raise self.ses.pause() print("Done") @@ -175,7 +174,7 @@ def main(): output_name += '.torrent' # return if user want to skip existing file. - if isfile(output_name) and args.skip_file: + if pt.isfile(output_name) and args.skip_file: print('File [{}] is already exist.'.format(output_name)) # still open file if file already existed. if args.open_file: @@ -183,11 +182,11 @@ def main(): return # create fullname if file exist. - if isfile(output_name) and not args.rewrite_file: + if pt.isfile(output_name) and not args.rewrite_file: new_output_name = output_name counter = 1 - while isfile(new_output_name): - non_basename, non_ext = splitext(new_output_name) + while pt.isfile(new_output_name): + non_basename, non_ext = pt.splitext(new_output_name) if counter - 1 != 0: non_basename = non_basename.rsplit('_{}'.format(counter - 1), 1)[0] non_basename += '_{}'.format(counter) From a2f9ca2cc5d530b524e5404c5aa5e5227c20b346 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 28 Jun 2016 22:31:36 +0100 Subject: [PATCH 14/26] Tidy up output in the case of long running downloads --- Magnet_To_Torrent2.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index 5e69272..161f7b1 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -86,17 +86,17 @@ def run(self): print("Downloading Metadata (this may take a while)") # used to control "Maybe..." and "or the" msgs # after sleep(1) - x = 1 - limit = 120 + wait_time = 1 + soft_limit = 120 while not self.handle.has_metadata(): try: sleep(1) - if x > limit: - print("Maybe your firewall is blocking, ") - print(" or the magnet link is not right...") - limit += 30 - x += 1 + if wait_time > soft_limit: + print("Download is taking a long time, maybe there is an " + "issue with the magnet link or your network connection") + soft_limit += 30 + wait_time += 1 except KeyboardInterrupt: print("Aborting...") self.ses.pause() From d54e3379357ba73df7f9326bfa9e00f9fc4255f5 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 28 Jun 2016 22:32:06 +0100 Subject: [PATCH 15/26] Rename open_file to more clearly reflect what it does --- Magnet_To_Torrent2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index 161f7b1..3176e48 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -129,7 +129,7 @@ def run(self): return output -def open_file(filepath): +def open_default_app(filepath): """open filepath with default application for each operating system.""" if sys.platform.startswith('darwin'): subprocess.call(('open', filepath)) @@ -178,7 +178,7 @@ def main(): print('File [{}] is already exist.'.format(output_name)) # still open file if file already existed. if args.open_file: - open_file(output_name) + open_default_app(output_name) return # create fullname if file exist. @@ -203,7 +203,7 @@ def main(): conv.run() if args.open_file: - open_file(output_name) + open_default_app(output_name) if __name__ == "__main__": From 5bc75cdec39a1c1eeba28b100ef1caae17aa84aa Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 28 Jun 2016 22:32:13 +0100 Subject: [PATCH 16/26] Some tidyups --- Magnet_To_Torrent2.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Magnet_To_Torrent2.py b/Magnet_To_Torrent2.py index 3176e48..357e61b 100755 --- a/Magnet_To_Torrent2.py +++ b/Magnet_To_Torrent2.py @@ -36,7 +36,7 @@ import libtorrent as lt -class Magnet2Torrent: +class Magnet2Torrent(object): """class for converter from magnet link to torrent.""" def __init__(self, magnet, output_name=None): @@ -47,17 +47,13 @@ def __init__(self, magnet, output_name=None): Raises: ValueError: if input is not valid this error will be raise """ - if output_name and \ - not pt.isdir(output_name) and \ - not pt.isdir(pt.dirname(pt.abspath(output_name))): + if (output_name and not pt.isdir(output_name) and + not pt.isdir(pt.dirname(pt.abspath(output_name)))): raise ValueError("Invalid output folder: " + pt.dirname(pt.abspath(output_name))) self.output_name = output_name - # create tempdir + self.tempdir = tempfile.mkdtemp() - # create session self.ses = lt.session() - # one could want to set this - # ses.listen_on(6881, 6882) # add 'url'. for add_torrent() params = { @@ -118,10 +114,9 @@ def run(self): output = pt.abspath(self.output_name) print("Saving torrent file here : " + output + " ...") - # torcontent = lt.bencode(torfile.generate()) # not used - f = open(output, "wb") - f.write(lt.bencode(torfile.generate())) - f.close() + with open(output, "wb") as outfile: + torcontent = lt.bencode(torfile.generate()) + outfile.write(torcontent) print("Saved! Cleaning up dir: " + self.tempdir) self.ses.remove_torrent(self.handle) shutil.rmtree(self.tempdir) From aeb9c6c08bee28e112f0366008dcb45f7a976c5e Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 28 Jun 2016 22:33:02 +0100 Subject: [PATCH 17/26] Rename to the same as the class name --- Magnet_To_Torrent2.py => Magnet2Torrent.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Magnet_To_Torrent2.py => Magnet2Torrent.py (100%) diff --git a/Magnet_To_Torrent2.py b/Magnet2Torrent.py similarity index 100% rename from Magnet_To_Torrent2.py rename to Magnet2Torrent.py From df150025f615841d5b9784a27063e4bb793588f7 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 28 Jun 2016 22:42:42 +0100 Subject: [PATCH 18/26] Tidy argument parser --- Magnet2Torrent.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index 357e61b..e78c5e5 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -55,7 +55,6 @@ def __init__(self, magnet, output_name=None): self.tempdir = tempfile.mkdtemp() self.ses = lt.session() - # add 'url'. for add_torrent() params = { 'url': magnet, 'save_path': self.tempdir, @@ -76,15 +75,14 @@ def run(self): Raises: KeyboardInterrupt: This error caused by user to stop this. - When downloading metada from magnet link, - it require additional step before the error reraised again. + When downloading metadata from magnet link, + it requires an additional step before the error reraised again. """ print("Downloading Metadata (this may take a while)") - # used to control "Maybe..." and "or the" msgs - # after sleep(1) + + # used to control "Maybe..." and "or the" msgs after sleep(1) wait_time = 1 soft_limit = 120 - while not self.handle.has_metadata(): try: sleep(1) @@ -117,6 +115,7 @@ def run(self): with open(output, "wb") as outfile: torcontent = lt.bencode(torfile.generate()) outfile.write(torcontent) + print("Saved! Cleaning up dir: " + self.tempdir) self.ses.remove_torrent(self.handle) shutil.rmtree(self.tempdir) @@ -134,29 +133,30 @@ def open_default_app(filepath): subprocess.call(('xdg-open', filepath)) -def main(): - """main function.""" - # parsing the argument. +def parse_args(args): + """parse some commandline arguments""" description = "A command line tool that converts magnet links in to .torrent files" parser = ArgumentParser(description=description) parser.add_argument('-m', '--magnet', help='The magnet url', required=True) parser.add_argument('-o', '--output', help='The output torrent file name') - # rewrite file option parser.add_argument('--rewrite-file', help='Rewrite torrent file if exist(default)', dest='rewrite_file', action='store_true') parser.add_argument('--no-rewrite-file', help='Create a new filename if torrent exist.', dest='rewrite_file', action='store_false') parser.set_defaults(rewrite_file=True) - # Skip file if exist option parser.add_argument('--skip-file', help='Skip file if file already exist.', - dest='skip_file', action='store_true') - parser.set_defaults(skip_file=False) - # open file after creating torrent file + dest='skip_file', action='store_true', default=False) parser.add_argument('--open-file', help='Open file after converting.', - dest='open_file', action='store_true') - parser.set_defaults(open_file=False) + dest='open_file', action='store_true', default=False) args = parser.parse_args(sys.argv[1:]) + return parser.parse_args(args) + + +def main(): + """main function.""" + # parsing the argument. + args = parse_args(sys.argv[1:]) output_name = args.output magnet = args.magnet From fb3fbab9aac066d99d4dc6e840588bdad08ccd4d Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Tue, 28 Jun 2016 23:00:39 +0100 Subject: [PATCH 19/26] Some comment/output message tidys --- Magnet2Torrent.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index e78c5e5..dcb5cf4 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -87,7 +87,7 @@ def run(self): try: sleep(1) if wait_time > soft_limit: - print("Download is taking a long time, maybe there is an " + print("Downloading is taking a while, maybe there is an " "issue with the magnet link or your network connection") soft_limit += 30 wait_time += 1 @@ -107,7 +107,8 @@ def run(self): if self.output_name: if pt.isdir(self.output_name): - output = pt.abspath(pt.join(self.output_name, torinfo.name() + ".torrent")) + output = pt.abspath(pt.join(self.output_name, + torinfo.name() + ".torrent")) elif pt.isdir(pt.dirname(pt.abspath(self.output_name))): output = pt.abspath(self.output_name) @@ -135,17 +136,19 @@ def open_default_app(filepath): def parse_args(args): """parse some commandline arguments""" - description = "A command line tool that converts magnet links in to .torrent files" + description = ("A command line tool that converts " + "magnet links into .torrent files") parser = ArgumentParser(description=description) parser.add_argument('-m', '--magnet', help='The magnet url', required=True) parser.add_argument('-o', '--output', help='The output torrent file name') - parser.add_argument('--rewrite-file', help='Rewrite torrent file if exist(default)', + parser.add_argument('--rewrite-file', + help='Rewrite torrent file if already exists(default)', dest='rewrite_file', action='store_true') parser.add_argument('--no-rewrite-file', - help='Create a new filename if torrent exist.', + help='Create a new filename if torrent exists.', dest='rewrite_file', action='store_false') parser.set_defaults(rewrite_file=True) - parser.add_argument('--skip-file', help='Skip file if file already exist.', + parser.add_argument('--skip-file', help='Skip file if it already exists.', dest='skip_file', action='store_true', default=False) parser.add_argument('--open-file', help='Open file after converting.', dest='open_file', action='store_true', default=False) @@ -155,28 +158,27 @@ def parse_args(args): def main(): """main function.""" - # parsing the argument. args = parse_args(sys.argv[1:]) output_name = args.output magnet = args.magnet # guess the name if output name is not given. - # in magnet link it is between'&dn' and '&tr' + # in a magnet link it is between '&dn' and '&tr' if output_name is None: output_name = magnet.split('&dn=')[1].split('&tr')[0] if '+' in output_name: output_name = unquote(output_name) output_name += '.torrent' - # return if user want to skip existing file. + # return if user wants to skip existing file. if pt.isfile(output_name) and args.skip_file: - print('File [{}] is already exist.'.format(output_name)) - # still open file if file already existed. + print('File [{}] already exists.'.format(output_name)) + # still open file if file already exists. if args.open_file: open_default_app(output_name) return - # create fullname if file exist. + # create fullname if file exists. if pt.isfile(output_name) and not args.rewrite_file: new_output_name = output_name counter = 1 @@ -189,11 +191,10 @@ def main(): counter += 1 output_name = new_output_name - # encode magnet link if it appear url decoded. + # encode magnet link if it's url decoded. if magnet != unquote(magnet): magnet = unquote(magnet) - # run the converter conv = Magnet2Torrent(magnet, output_name) conv.run() From f6faa497d30a61d2bc16fb0cae23bf1d4f8ebde6 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Wed, 29 Jun 2016 01:01:10 +0100 Subject: [PATCH 20/26] Only import os/subprocess when used --- Magnet2Torrent.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index dcb5cf4..147c45d 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -21,10 +21,8 @@ """ -import os import os.path as pt import shutil -import subprocess import sys import tempfile from argparse import ArgumentParser @@ -126,6 +124,9 @@ def run(self): def open_default_app(filepath): """open filepath with default application for each operating system.""" + import os + import subprocess + if sys.platform.startswith('darwin'): subprocess.call(('open', filepath)) elif os.name == 'nt': From 11bef31bf212f9a87dfe7c6699b0e19853774148 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Wed, 29 Jun 2016 01:04:16 +0100 Subject: [PATCH 21/26] Readme pass --- Magnet2Torrent.py | 2 +- README.md | 34 ++++++++++++++++++---------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index 147c45d..e20c795 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -143,7 +143,7 @@ def parse_args(args): parser.add_argument('-m', '--magnet', help='The magnet url', required=True) parser.add_argument('-o', '--output', help='The output torrent file name') parser.add_argument('--rewrite-file', - help='Rewrite torrent file if already exists(default)', + help='Rewrite torrent file if it already exists(default)', dest='rewrite_file', action='store_true') parser.add_argument('--no-rewrite-file', help='Create a new filename if torrent exists.', diff --git a/README.md b/README.md index b32b6fa..1f85924 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,38 @@ # Magnet2Torrent -A command line tool that converts magnet links in to .torrent files. +A command line tool that converts magnet links into .torrent files. ## Requirements * python2.7/3.5 * python-libtorrent (libtorrent-rasterbar version 0.16 or later) for python 2.7 or python3-libtorrent for python 3.5 -## How to Use +### To install libtorrent-python on Mac - usage: Magnet_To_Torrent2.py [-h] -m MAGNET [-o OUTPUT] [--rewrite-file] + brew install libtorrent-rasterbar --with-python + +## Usage + + usage: Magnet2Torrent.py [-h] -m MAGNET [-o OUTPUT] [--rewrite-file] [--no-rewrite-file] [--skip-file] [--open-file] -A command line tool that converts magnet links in to .torrent files +A command line tool that converts magnet links into .torrent files -optional arguments: +Optional arguments: - -h, --help show this help message and exit + -h, --help Show this help message and exit. -m MAGNET, --magnet MAGNET - The magnet url + The magnet url. -o OUTPUT, --output OUTPUT - The output torrent file name - --rewrite-file Rewrite torrent file if exist(default) - --no-rewrite-file Create a new filename if torrent exist. - --skip-file Skip file if file already exist. - --open-file Open file after conferting. + The output torrent file name. + --rewrite-file Rewrite torrent file if it already exists (default). + --no-rewrite-file Create a new filename if torrent exists. + --skip-file Skip file if it already exists. + --open-file Open file after converting. -## To install libtorrent-python on Mac -`brew install libtorrent-rasterbar --with-python` +## Example -### Example -`python Magnet_To_Torrent2.py -m "magnet:?xt=urn:btih:49fbd26322960d982da855c54e36df19ad3113b8&dn=ubuntu-12.04-desktop-i386.iso&tr=udp%3A%2F%2Ftracker.openbittorrent.com" -o ubunut12-04.iso` + python Magnet2Torrent.py -m "magnet:?xt=urn:btih:49fbd26322960d982da855c54e36df19ad3113b8&dn=ubuntu-12.04-desktop-i386.iso&tr=udp%3A%2F%2Ftracker.openbittorrent.com" -o ubunut12-04.iso ## Licenses All code is licensed under the [GPL version 3](http://www.gnu.org/licenses/gpl.html) From 8edd5c2bf85bc62e75873f05fe2382d76a2bd3c2 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 2 Jul 2016 20:57:25 +0100 Subject: [PATCH 22/26] Fix arg parser --- Magnet2Torrent.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index e20c795..dcfc00d 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -153,7 +153,6 @@ def parse_args(args): dest='skip_file', action='store_true', default=False) parser.add_argument('--open-file', help='Open file after converting.', dest='open_file', action='store_true', default=False) - args = parser.parse_args(sys.argv[1:]) return parser.parse_args(args) From ccb5bfd11df2f6f561790b361796bec6e7a7f09b Mon Sep 17 00:00:00 2001 From: Szero Date: Sat, 13 May 2017 16:44:22 +0200 Subject: [PATCH 23/26] unquote filename from magnet on % symbol --- Magnet2Torrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index dcfc00d..c0009bd 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -166,7 +166,7 @@ def main(): # in a magnet link it is between '&dn' and '&tr' if output_name is None: output_name = magnet.split('&dn=')[1].split('&tr')[0] - if '+' in output_name: + if '%' in output_name: output_name = unquote(output_name) output_name += '.torrent' From d9ff0a0c690900a7aa5e5214c6b939f70cb09933 Mon Sep 17 00:00:00 2001 From: Szero Date: Sat, 13 May 2017 20:03:55 +0200 Subject: [PATCH 24/26] get filename from torrent handle if magnet doesn't have dn field --- Magnet2Torrent.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index c0009bd..8259ff2 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -109,6 +109,8 @@ def run(self): torinfo.name() + ".torrent")) elif pt.isdir(pt.dirname(pt.abspath(self.output_name))): output = pt.abspath(self.output_name) + else: + output = pt.abspath(torinfo.name() + ".torrent") print("Saving torrent file here : " + output + " ...") with open(output, "wb") as outfile: @@ -165,13 +167,16 @@ def main(): # guess the name if output name is not given. # in a magnet link it is between '&dn' and '&tr' if output_name is None: - output_name = magnet.split('&dn=')[1].split('&tr')[0] - if '%' in output_name: - output_name = unquote(output_name) - output_name += '.torrent' + try: + output_name = magnet.split('&dn=')[1].split('&tr')[0] + if '%' in output_name: + output_name = unquote(output_name) + output_name += '.torrent' + except IndexError: + pass # return if user wants to skip existing file. - if pt.isfile(output_name) and args.skip_file: + if output_name is not None and pt.isfile(output_name) and args.skip_file: print('File [{}] already exists.'.format(output_name)) # still open file if file already exists. if args.open_file: @@ -179,7 +184,7 @@ def main(): return # create fullname if file exists. - if pt.isfile(output_name) and not args.rewrite_file: + if output_name is not None and pt.isfile(output_name) and not args.rewrite_file: new_output_name = output_name counter = 1 while pt.isfile(new_output_name): From bca11021ac4f0ce72adc6fb7ce959f26acabc888 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Sat, 10 Jun 2017 17:44:24 +0800 Subject: [PATCH 25/26] chg: dev: update with patch from @Szero - use python3 interpreter - use unquote_plus instead of unquote --- Magnet2Torrent.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index 8259ff2..a447fde 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """convert magnet link to torrent file. Created on Apr 19, 2012 @author: dan, Faless @@ -28,9 +28,9 @@ from argparse import ArgumentParser from time import sleep try: - from urllib.parse import unquote + from urllib.parse import unquote_plus except ImportError: - from urllib import unquote + from urllib import unquote_plus import libtorrent as lt @@ -90,7 +90,7 @@ def run(self): soft_limit += 30 wait_time += 1 except KeyboardInterrupt: - print("Aborting...") + print("\nAborting...") self.ses.pause() print("Cleanup dir " + self.tempdir) shutil.rmtree(self.tempdir) @@ -166,14 +166,13 @@ def main(): # guess the name if output name is not given. # in a magnet link it is between '&dn' and '&tr' - if output_name is None: - try: + try: + if output_name is None: output_name = magnet.split('&dn=')[1].split('&tr')[0] - if '%' in output_name: - output_name = unquote(output_name) + output_name = unquote_plus(output_name) output_name += '.torrent' - except IndexError: - pass + except IndexError: + pass # return if user wants to skip existing file. if output_name is not None and pt.isfile(output_name) and args.skip_file: @@ -197,8 +196,8 @@ def main(): output_name = new_output_name # encode magnet link if it's url decoded. - if magnet != unquote(magnet): - magnet = unquote(magnet) + if magnet != unquote_plus(magnet): + magnet = unquote_plus(magnet) conv = Magnet2Torrent(magnet, output_name) conv.run() From 35d8b5a674b652debe33f4b737fd773d6fa37211 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Sat, 10 Jun 2017 17:48:04 +0800 Subject: [PATCH 26/26] chg: dev: log when index error. --- Magnet2Torrent.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Magnet2Torrent.py b/Magnet2Torrent.py index a447fde..501e458 100755 --- a/Magnet2Torrent.py +++ b/Magnet2Torrent.py @@ -21,6 +21,7 @@ """ +import logging import os.path as pt import shutil import sys @@ -172,7 +173,7 @@ def main(): output_name = unquote_plus(output_name) output_name += '.torrent' except IndexError: - pass + logging.error('magnet: {}'.format(magnet)) # return if user wants to skip existing file. if output_name is not None and pt.isfile(output_name) and args.skip_file: