mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Add fixEncoding()
This commit is contained in:
18
spotdl.py
18
spotdl.py
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from shutil import copyfileobj
|
from shutil import copyfileobj
|
||||||
@@ -10,6 +10,7 @@ import requests
|
|||||||
import pafy
|
import pafy
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
import pathlib
|
||||||
#import spotipy.util as util
|
#import spotipy.util as util
|
||||||
|
|
||||||
# Python 3 compatibility
|
# Python 3 compatibility
|
||||||
@@ -126,7 +127,7 @@ def getYouTubeTitle(content, number):
|
|||||||
return str(number) + '. ' + title
|
return str(number) + '. ' + title
|
||||||
|
|
||||||
def generateFileName(content):
|
def generateFileName(content):
|
||||||
return (content.title).replace("\\", "_").replace("/", "_").replace(":", "_").replace("*", "_").replace("?", "_").replace('"', "_").replace("<", "_").replace(">", "_").replace("|", "_").replace(" ", "_")
|
return fixEncoding((content.title).replace("\\", "_").replace("/", "_").replace(":", "_").replace("*", "_").replace("?", "_").replace('"', "_").replace("<", "_").replace(">", "_").replace("|", "_").replace(" ", "_"))
|
||||||
|
|
||||||
def downloadSong(content):
|
def downloadSong(content):
|
||||||
music_file = generateFileName(content)
|
music_file = generateFileName(content)
|
||||||
@@ -134,7 +135,6 @@ def downloadSong(content):
|
|||||||
link.download(filepath="Music/" + music_file + ".m4a")
|
link.download(filepath="Music/" + music_file + ".m4a")
|
||||||
|
|
||||||
def convertToMP3(music_file):
|
def convertToMP3(music_file):
|
||||||
music_file = music_file.encode('utf-8')
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
os.system('Scripts\\avconv.exe -loglevel 0 -i "' + 'Music/' + music_file + '.m4a" -ab 192k "' + 'Music/' + music_file + '.mp3"')
|
os.system('Scripts\\avconv.exe -loglevel 0 -i "' + 'Music/' + music_file + '.m4a" -ab 192k "' + 'Music/' + music_file + '.mp3"')
|
||||||
else:
|
else:
|
||||||
@@ -205,9 +205,16 @@ def grabSingle(raw_song, number):
|
|||||||
print('Fixing meta-tags')
|
print('Fixing meta-tags')
|
||||||
fixSong(music_file, meta_tags)
|
fixSong(music_file, meta_tags)
|
||||||
|
|
||||||
|
def fixEncoding(query):
|
||||||
|
if version_info > (3,0):
|
||||||
|
return query
|
||||||
|
else:
|
||||||
|
return query.encode('utf-8')
|
||||||
|
|
||||||
def grabList(file):
|
def grabList(file):
|
||||||
lines = open(file, 'r').read()
|
lines = open(file, 'r').read()
|
||||||
lines = lines.splitlines()
|
lines = lines.splitlines()
|
||||||
|
# Do not take blank lines in list into account
|
||||||
try:
|
try:
|
||||||
lines.remove('')
|
lines.remove('')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -236,7 +243,7 @@ def graceQuit():
|
|||||||
print('Exitting..')
|
print('Exitting..')
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def main():
|
while True:
|
||||||
for m in os.listdir('Music/'):
|
for m in os.listdir('Music/'):
|
||||||
if m.endswith('.m4a.temp'):
|
if m.endswith('.m4a.temp'):
|
||||||
os.remove('Music/' + m)
|
os.remove('Music/' + m)
|
||||||
@@ -247,6 +254,3 @@ def main():
|
|||||||
initializeInput(command)
|
initializeInput(command)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
graceQuit()
|
graceQuit()
|
||||||
|
|
||||||
while True:
|
|
||||||
main()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user