Skip to content

Commit

Permalink
Fix windows cli script
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgio.tropiano committed Feb 19, 2021
1 parent 444a421 commit ba71cdf
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 79 deletions.
75 changes: 0 additions & 75 deletions bin/nts

This file was deleted.

4 changes: 4 additions & 0 deletions nts/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .cli import main

if __name__ == '__main__':
main()
77 changes: 77 additions & 0 deletions nts/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python3
import os
import re
import sys
from optparse import OptionParser
from nts import downloader as nts


def main():
episode_regex = r'.*nts\.live\/shows.+(\/episodes)\/.+'
show_regex = r'.*nts\.live\/shows\/([^/]+)$'

# defaults to darwin
download_dir = '~/Downloads'
if sys.platform.startswith('win32'):
download_dir = '%USERPROFILE%\\Downloads\\'
# expand it
download_dir = os.path.expanduser('~/Downloads')

usage = "Usage: %prog [options] args"
parser = OptionParser(usage=usage)
parser.add_option("-o", "--out-dir", dest="output_directory", default=download_dir, action="store", type="string",
help="where the files will be downloaded, defaults to ~/Downloads on macOS and %USERPROFILE%\\Downloads", metavar="DIR")
parser.add_option("-v", "--version", default=False,
dest="version", action="store_true",
help="print the version number and quit")
parser.add_option("-q", "--quiet", default=False,
dest="quiet", action="store_true",
help="only print errors")

(options, args) = parser.parse_args()

if options.version:
print(f'nts {nts.__version__}')
exit(0)

if len(args) < 1:
print("please pass an URL or a file containing a list of urls.\n")
parser.print_help()
exit(1)

download_dir = os.path.expanduser(options.output_directory)
download_dir = os.path.abspath(options.output_directory)

def url_matcher(url):
if isinstance(url, str):
url = url.strip()
match_ep = re.match(episode_regex, url)
match_sh = re.match(show_regex, url)

if match_ep:
nts.download(url=url, quiet=options.quiet,
save_dir=download_dir)
elif match_sh:
episodes = nts.get_episodes_of_show(match_sh.group(1))
for ep in episodes:
url_matcher(ep)
else:
print(f'{url} is not an NTS url.\n')
parser.print_help()
exit(1)

for arg in args:
if os.path.isfile(arg):
# check if file
file = ""
with open(arg, 'r') as f:
file = f.read()
lines = filter(None, file.split('\n'))
for line in lines:
url_matcher(line)
else:
url_matcher(arg)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion nts/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from bs4 import BeautifulSoup


__version__ = '1.1.5'
__version__ = '1.1.6'


# defaults to darwin
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="nts-everdrone",
version="1.1.5",
version="1.1.6",
author="Giorgio Tropiano",
author_email="giorgiotropiano@gmail.com",
description="NTS Radio downloader tool",
Expand All @@ -16,11 +16,14 @@
"Operating System :: OS Independent",
],
license='MIT',
scripts=['bin/nts'],
entry_points={
'console_scripts': ['nts=nts.cli:main']
},
install_requires=[
'youtube_dl',
'beautifulsoup4',
'mutagen'
'mutagen',
'requests'
],
python_requires='>=3.7.5',
)

0 comments on commit ba71cdf

Please sign in to comment.