mirror of
https://github.com/obskyr/khinsider.git
synced 2025-01-17 12:38:30 +01:00
Fixed downloading songs with Unicode names.
Once and for all, hopefully!
This commit is contained in:
parent
8687d91388
commit
7e07691b3b
17
khinsider.py
17
khinsider.py
@ -132,20 +132,23 @@ def download(ostName, path="", verbose=False):
|
||||
def downloadSong(songUrl, path, name="song", numTries=3, verbose=False):
|
||||
"""Download a single song at `songUrl` to `path`."""
|
||||
if verbose:
|
||||
print("Downloading {}...".format(name))
|
||||
print("Downloading {}...".format(name).encode(
|
||||
sys.stdout.encoding, 'replace'))
|
||||
|
||||
tries = 0
|
||||
while tries < numTries:
|
||||
try:
|
||||
if tries and verbose:
|
||||
print("Couldn't download {}. Trying again...".format(name))
|
||||
print("Couldn't download {}. Trying again...".format(
|
||||
name).encode(sys.stdout.encoding, 'replace'))
|
||||
song = requests.get(songUrl)
|
||||
break
|
||||
except requests.ConnectionError:
|
||||
tries += 1
|
||||
else:
|
||||
if verbose:
|
||||
print("Couldn't download {}. Skipping over.".format(name))
|
||||
print("Couldn't download {}. Skipping over.".format(
|
||||
name).encode(sys.stdout.encoding, 'replace'))
|
||||
return
|
||||
|
||||
try:
|
||||
@ -153,7 +156,8 @@ def downloadSong(songUrl, path, name="song", numTries=3, verbose=False):
|
||||
outfile.write(song.content)
|
||||
except IOError:
|
||||
if verbose:
|
||||
print("Couldn't save {}. Check your permissions.".format(name))
|
||||
print("Couldn't save {}. Check your permissions.".format(
|
||||
name).encode(sys.stdout.encoding, 'replace'))
|
||||
|
||||
def search(term):
|
||||
"""Return a list of OST IDs for the search term `term`."""
|
||||
@ -197,7 +201,10 @@ if __name__ == '__main__':
|
||||
searchTerm = ' '.join(sys.argv[1:]).replace('-', ' ')
|
||||
|
||||
searchResults = search(searchTerm)
|
||||
print("\nThe soundtrack \"{}\" does not seem to exist.".format(ostName))
|
||||
# I don't know, maybe in some crazy circumstance the encoding for
|
||||
# arguments doesn't match stdout's encoding.
|
||||
print("\nThe soundtrack \"{}\" does not seem to exist.".format(
|
||||
ostName).encode(sys.stdout.encoding, 'replace'))
|
||||
|
||||
if searchResults: # aww yeah we gon' do some searchin'
|
||||
print()
|
||||
|
Loading…
x
Reference in New Issue
Block a user