|
@@ -1,9 +1,11 @@
|
|
|
#!/usr/bin/env python3
|
|
|
+# pip install lxml requests
|
|
|
import os
|
|
|
from argparse import ArgumentParser
|
|
|
from subprocess import check_output
|
|
|
from collections import OrderedDict
|
|
|
import re
|
|
|
+import urllib.request
|
|
|
|
|
|
from lxml import html
|
|
|
import requests
|
|
@@ -108,11 +110,23 @@ def get_parser():
|
|
|
p.add_argument('--slotsize', help='Seconds between each audio', type=int)
|
|
|
p.add_argument('--group', help='Group articles', default=False,
|
|
|
action='store_true')
|
|
|
+ p.add_argument('--copy', help='Copy files to $TMPDIR', default=False,
|
|
|
+ action='store_true')
|
|
|
p.add_argument('--debug', help='Debug messages', default=False,
|
|
|
action='store_true')
|
|
|
p.add_argument('url')
|
|
|
return p
|
|
|
|
|
|
+def put(audio, copy=False):
|
|
|
+ if not copy:
|
|
|
+ print(audio.url)
|
|
|
+ else:
|
|
|
+ destdir = (os.environ.get('TMPDIR', '.'))
|
|
|
+ dest = os.path.join(destdir, audio.url.split('/')[-1])
|
|
|
+ os.makedirs(destdir, exist_ok=True)
|
|
|
+ fname, headers = urllib.request.urlretrieve(audio.url, dest)
|
|
|
+ print(fname)
|
|
|
+
|
|
|
|
|
|
def main():
|
|
|
args = get_parser().parse_args()
|
|
@@ -139,7 +153,7 @@ def main():
|
|
|
if args.debug:
|
|
|
print(repr(audio))
|
|
|
else:
|
|
|
- print(audio)
|
|
|
+ put(audio, args.copy)
|
|
|
if args.slotsize is not None:
|
|
|
duration = audio.durata
|
|
|
if duration < args.slotsize:
|
|
@@ -149,7 +163,7 @@ def main():
|
|
|
if args.debug:
|
|
|
print(repr(audios[-1]))
|
|
|
else:
|
|
|
- print(audios[-1])
|
|
|
+ put(audios[-1], args.copy)
|
|
|
# else: # grouping; TODO: support slotsize
|
|
|
# for item in groups:
|
|
|
# if args.debug:
|