[radioob] radioob can now download full album
This commit is contained in:
parent
8667a8c43b
commit
2f0643085e
1 changed files with 30 additions and 6 deletions
|
|
@ -161,20 +161,43 @@ class Radioob(ReplApplication):
|
||||||
|
|
||||||
def do_download(self, line):
|
def do_download(self, line):
|
||||||
"""
|
"""
|
||||||
download ID [FILENAME]
|
download ID [DIRECTORY]
|
||||||
|
|
||||||
Download an audio file
|
Download an audio file
|
||||||
"""
|
"""
|
||||||
_id, dest = self.parse_command_args(line, 2, 1)
|
_id, dest = self.parse_command_args(line, 2, 1)
|
||||||
audio = self.get_object(_id, 'get_audio', ['url'])
|
|
||||||
if not audio:
|
obj = self.retrieve_obj(_id)
|
||||||
print('Audio file not found: %s' % _id, file=self.stderr)
|
|
||||||
|
if obj is None:
|
||||||
|
print('No object matches with this id:', _id, file=self.stderr)
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
if not audio.url:
|
if isinstance(obj, BaseAudio):
|
||||||
|
streams = [obj]
|
||||||
|
|
||||||
|
else:
|
||||||
|
streams = obj.tracks_list
|
||||||
|
|
||||||
|
if len(streams) == 0:
|
||||||
|
print('Radio or Audio file not found:', _id, file=self.stderr)
|
||||||
|
return 3
|
||||||
|
|
||||||
|
for stream in streams:
|
||||||
|
self.download_file(stream, dest)
|
||||||
|
|
||||||
|
def download_file(self, audio, dest):
|
||||||
|
_obj = self.get_object(audio.id, 'get_audio', ['url', 'title'])
|
||||||
|
if not _obj:
|
||||||
|
print('Audio file not found: %s' % audio.id, file=self.stderr)
|
||||||
|
return 3
|
||||||
|
|
||||||
|
if not _obj.url:
|
||||||
print('Error: the direct URL is not available.', file=self.stderr)
|
print('Error: the direct URL is not available.', file=self.stderr)
|
||||||
return 4
|
return 4
|
||||||
|
|
||||||
|
audio.url = _obj.url
|
||||||
|
|
||||||
def check_exec(executable):
|
def check_exec(executable):
|
||||||
with open('/dev/null', 'w') as devnull:
|
with open('/dev/null', 'w') as devnull:
|
||||||
process = subprocess.Popen(['which', executable], stdout=devnull)
|
process = subprocess.Popen(['which', executable], stdout=devnull)
|
||||||
|
|
@ -187,7 +210,8 @@ class Radioob(ReplApplication):
|
||||||
ext = _audio.ext
|
ext = _audio.ext
|
||||||
if not ext:
|
if not ext:
|
||||||
ext = 'audiofile'
|
ext = 'audiofile'
|
||||||
return '%s.%s' % (re.sub('[?:/]', '-', _audio.id), ext)
|
title = _audio.title if _audio.title else _audio.id
|
||||||
|
return '%s.%s' % (re.sub('[?:/]', '-', title), ext)
|
||||||
|
|
||||||
if dest is not None and os.path.isdir(dest):
|
if dest is not None and os.path.isdir(dest):
|
||||||
dest += '/%s' % audio_to_file(audio)
|
dest += '/%s' % audio_to_file(audio)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue