Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command line tool with basic options for parsing torrents #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions PTN/parseTorrentName.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
import argparse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First line for script should be the shebang line.
I.e. #!/usr/bin/python

Then the script can be executable.

import PTN

def main():
parser = argparse.ArgumentParser()
parser.add_argument('torrent_name', help='Torrent name to parse')
parser.add_argument('-j', '--json', dest="json", action='store_true', default=False, help='Output in json format')
parser.add_argument('-y', '--yaml', dest="yaml", action='store_true', default=False, help='Output to YAML')
parser.add_argument('-f', '--file', dest="filename", default=False, help='Output to file as well as command line')
args = parser.parse_args()

info = PTN.parse(args.torrent_name)
if args.yaml:
try:
from ruamel import yaml
output = str(yaml.dump(info, default_flow_style=False))
except ImportError:
print "yaml module required for yaml output!\nInstall with 'pip install ruamel.yaml'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print statement is not compatible with python3 use print() function

exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use sys.exit

elif args.json:
try:
try:
import simplejson as json
except ImportError:
import json
output = json.dumps(info, indent=4, sort_keys=True)
except ImportError:
print "json module required for json output!\nInstall with 'pip install simplejson' or update python to 2.6+"
exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use sys.exit

else:
output = str(info)
if args.filename:
with open(args.filename, 'w') as f:
f.write(output)
print output
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
description='Extract media information from torrent-like filename',
long_description=description,
packages=['PTN'],
entry_points = {
"console_scripts": ['parse-torrent-name = PTN.parseTorrentName:main']
},
install_requires=[
"argparse"
],
keywords=('parse parser torrent torrents name names proper rename '
'movie movies tv show shows series extract find quality '
'group codec audio resolution title season episode year '
Expand Down