Skip to content

Commit ba71cdf

Browse files
author
giorgio.tropiano
committed
Fix windows cli script
1 parent 444a421 commit ba71cdf

5 files changed

Lines changed: 88 additions & 79 deletions

File tree

bin/nts

Lines changed: 0 additions & 75 deletions
This file was deleted.

nts/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .cli import main
2+
3+
if __name__ == '__main__':
4+
main()

nts/cli.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import re
4+
import sys
5+
from optparse import OptionParser
6+
from nts import downloader as nts
7+
8+
9+
def main():
10+
episode_regex = r'.*nts\.live\/shows.+(\/episodes)\/.+'
11+
show_regex = r'.*nts\.live\/shows\/([^/]+)$'
12+
13+
# defaults to darwin
14+
download_dir = '~/Downloads'
15+
if sys.platform.startswith('win32'):
16+
download_dir = '%USERPROFILE%\\Downloads\\'
17+
# expand it
18+
download_dir = os.path.expanduser('~/Downloads')
19+
20+
usage = "Usage: %prog [options] args"
21+
parser = OptionParser(usage=usage)
22+
parser.add_option("-o", "--out-dir", dest="output_directory", default=download_dir, action="store", type="string",
23+
help="where the files will be downloaded, defaults to ~/Downloads on macOS and %USERPROFILE%\\Downloads", metavar="DIR")
24+
parser.add_option("-v", "--version", default=False,
25+
dest="version", action="store_true",
26+
help="print the version number and quit")
27+
parser.add_option("-q", "--quiet", default=False,
28+
dest="quiet", action="store_true",
29+
help="only print errors")
30+
31+
(options, args) = parser.parse_args()
32+
33+
if options.version:
34+
print(f'nts {nts.__version__}')
35+
exit(0)
36+
37+
if len(args) < 1:
38+
print("please pass an URL or a file containing a list of urls.\n")
39+
parser.print_help()
40+
exit(1)
41+
42+
download_dir = os.path.expanduser(options.output_directory)
43+
download_dir = os.path.abspath(options.output_directory)
44+
45+
def url_matcher(url):
46+
if isinstance(url, str):
47+
url = url.strip()
48+
match_ep = re.match(episode_regex, url)
49+
match_sh = re.match(show_regex, url)
50+
51+
if match_ep:
52+
nts.download(url=url, quiet=options.quiet,
53+
save_dir=download_dir)
54+
elif match_sh:
55+
episodes = nts.get_episodes_of_show(match_sh.group(1))
56+
for ep in episodes:
57+
url_matcher(ep)
58+
else:
59+
print(f'{url} is not an NTS url.\n')
60+
parser.print_help()
61+
exit(1)
62+
63+
for arg in args:
64+
if os.path.isfile(arg):
65+
# check if file
66+
file = ""
67+
with open(arg, 'r') as f:
68+
file = f.read()
69+
lines = filter(None, file.split('\n'))
70+
for line in lines:
71+
url_matcher(line)
72+
else:
73+
url_matcher(arg)
74+
75+
76+
if __name__ == '__main__':
77+
main()

nts/downloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from bs4 import BeautifulSoup
1212

1313

14-
__version__ = '1.1.5'
14+
__version__ = '1.1.6'
1515

1616

1717
# defaults to darwin

setup.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setuptools.setup(
44
name="nts-everdrone",
5-
version="1.1.5",
5+
version="1.1.6",
66
author="Giorgio Tropiano",
77
author_email="giorgiotropiano@gmail.com",
88
description="NTS Radio downloader tool",
@@ -16,11 +16,14 @@
1616
"Operating System :: OS Independent",
1717
],
1818
license='MIT',
19-
scripts=['bin/nts'],
19+
entry_points={
20+
'console_scripts': ['nts=nts.cli:main']
21+
},
2022
install_requires=[
2123
'youtube_dl',
2224
'beautifulsoup4',
23-
'mutagen'
25+
'mutagen',
26+
'requests'
2427
],
2528
python_requires='>=3.7.5',
2629
)

0 commit comments

Comments
 (0)