Fix windows issues
parent
30968bc5a1
commit
e9f20970a0
28
scdl/scdl.py
28
scdl/scdl.py
|
@ -74,6 +74,7 @@ from scdl import __version__, CLIENT_ID, ALT_CLIENT_ID
|
||||||
from scdl import client, utils
|
from scdl import client, utils
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import subprocess
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
||||||
logging.getLogger('requests').setLevel(logging.WARNING)
|
logging.getLogger('requests').setLevel(logging.WARNING)
|
||||||
|
@ -173,7 +174,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
logger.error('Invalid path in arguments...')
|
logger.error('Invalid path in arguments...')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
logger.debug('Downloading to '+os.getcwd()+'...')
|
logger.debug('Downloading to ' + os.getcwd() + '...')
|
||||||
|
|
||||||
if arguments['-l']:
|
if arguments['-l']:
|
||||||
parse_url(arguments['-l'])
|
parse_url(arguments['-l'])
|
||||||
|
@ -417,8 +418,8 @@ def get_filename(track, original_filename=None):
|
||||||
|
|
||||||
if arguments['--addtimestamp']:
|
if arguments['--addtimestamp']:
|
||||||
# created_at sample: 2017/03/03 09:29:33 +0000
|
# created_at sample: 2017/03/03 09:29:33 +0000
|
||||||
ts = datetime\
|
ts = datetime \
|
||||||
.strptime(track['created_at'], "%Y/%m/%d %H:%M:%S %z")\
|
.strptime(track['created_at'], "%Y/%m/%d %H:%M:%S %z") \
|
||||||
.timestamp()
|
.timestamp()
|
||||||
|
|
||||||
title = str(int(ts)) + "_" + title
|
title = str(int(ts)) + "_" + title
|
||||||
|
@ -457,15 +458,15 @@ def download_original_file(track, title):
|
||||||
# Write file
|
# Write file
|
||||||
total_length = int(r.headers.get('content-length'))
|
total_length = int(r.headers.get('content-length'))
|
||||||
temp = tempfile.NamedTemporaryFile(delete=False)
|
temp = tempfile.NamedTemporaryFile(delete=False)
|
||||||
received=0
|
received = 0
|
||||||
with temp as f:
|
with temp as f:
|
||||||
for chunk in progress.bar(
|
for chunk in progress.bar(
|
||||||
r.iter_content(chunk_size=1024),
|
r.iter_content(chunk_size=1024),
|
||||||
expected_size=(total_length/1024) + 1,
|
expected_size=(total_length / 1024) + 1,
|
||||||
hide=True if arguments["--hide-progress"] else False
|
hide=True if arguments["--hide-progress"] else False
|
||||||
):
|
):
|
||||||
if chunk:
|
if chunk:
|
||||||
received+=len(chunk)
|
received += len(chunk)
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
|
@ -480,7 +481,7 @@ def download_original_file(track, title):
|
||||||
new = shlex.quote(newfilename)
|
new = shlex.quote(newfilename)
|
||||||
old = shlex.quote(filename)
|
old = shlex.quote(filename)
|
||||||
logger.debug("ffmpeg -i {0} {1} -loglevel fatal".format(old, new))
|
logger.debug("ffmpeg -i {0} {1} -loglevel fatal".format(old, new))
|
||||||
os.system("ffmpeg -i {0} {1} -loglevel fatal".format(old, new))
|
subprocess.call("ffmpeg -i {0} {1} -loglevel fatal".format(old, new))
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
filename = newfilename
|
filename = newfilename
|
||||||
|
|
||||||
|
@ -510,10 +511,10 @@ def download_hls_mp3(track, title):
|
||||||
|
|
||||||
# Get the requests stream
|
# Get the requests stream
|
||||||
url = get_track_m3u8(track)
|
url = get_track_m3u8(track)
|
||||||
os.system(
|
res = subprocess.call(
|
||||||
"ffmpeg -i {0} -c copy {1} -loglevel fatal".format(
|
"ffmpeg -i {0} -c copy {1} -loglevel fatal".format(
|
||||||
shlex.quote(url),
|
'"' + url + '"',
|
||||||
shlex.quote(filename)
|
'"' + filename + '"'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return filename
|
return filename
|
||||||
|
@ -554,7 +555,6 @@ def download_track(track, playlist_name=None, playlist_file=None):
|
||||||
if arguments['--remove']:
|
if arguments['--remove']:
|
||||||
fileToKeep.append(filename)
|
fileToKeep.append(filename)
|
||||||
|
|
||||||
|
|
||||||
if filename.endswith('.mp3') or filename.endswith('.flac'):
|
if filename.endswith('.mp3') or filename.endswith('.flac'):
|
||||||
try:
|
try:
|
||||||
set_metadata(track, filename, playlist_name)
|
set_metadata(track, filename, playlist_name)
|
||||||
|
@ -578,6 +578,7 @@ def can_convert(filename):
|
||||||
ext = os.path.splitext(filename)[1]
|
ext = os.path.splitext(filename)[1]
|
||||||
return 'wav' in ext or 'aif' in ext
|
return 'wav' in ext or 'aif' in ext
|
||||||
|
|
||||||
|
|
||||||
def already_downloaded(track, title, filename):
|
def already_downloaded(track, title, filename):
|
||||||
"""
|
"""
|
||||||
Returns True if the file has already been downloaded
|
Returns True if the file has already been downloaded
|
||||||
|
@ -622,7 +623,7 @@ def in_download_archive(track):
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
track_id = '{0}'.format(track['id'])
|
track_id = '{0}'.format(track['id'])
|
||||||
for line in file:
|
for line in file:
|
||||||
logger.debug('"'+line.strip()+'"')
|
logger.debug('"' + line.strip() + '"')
|
||||||
if line.strip() == track_id:
|
if line.strip() == track_id:
|
||||||
return True
|
return True
|
||||||
except IOError as ioe:
|
except IOError as ioe:
|
||||||
|
@ -643,7 +644,7 @@ def record_download_archive(track):
|
||||||
archive_filename = arguments.get('--download-archive')
|
archive_filename = arguments.get('--download-archive')
|
||||||
try:
|
try:
|
||||||
with open(archive_filename, 'a', encoding='utf-8') as file:
|
with open(archive_filename, 'a', encoding='utf-8') as file:
|
||||||
file.write('{0}'.format(track['id'])+'\n')
|
file.write('{0}'.format(track['id']) + '\n')
|
||||||
except IOError as ioe:
|
except IOError as ioe:
|
||||||
logger.error('Error trying to write to download archive...')
|
logger.error('Error trying to write to download archive...')
|
||||||
logger.debug(ioe)
|
logger.debug(ioe)
|
||||||
|
@ -720,5 +721,6 @@ def signal_handler(signal, frame):
|
||||||
logger.info('\nGood bye!')
|
logger.info('\nGood bye!')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue