mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Add comments
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
# Usual import stuff
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from shutil import copyfileobj
|
from shutil import copyfileobj
|
||||||
from sys import path, version_info
|
from sys import path, version_info
|
||||||
@@ -26,12 +27,14 @@ def getInputLink(links):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
print('Choose a valid number!')
|
print('Choose a valid number!')
|
||||||
|
|
||||||
|
# Check if input song is Spotify URL or just a song name
|
||||||
def isSpotify(raw_song):
|
def isSpotify(raw_song):
|
||||||
if (len(raw_song) == 22 and raw_song.replace(" ", "%20") == raw_song) or (raw_song.find('spotify') > -1):
|
if (len(raw_song) == 22 and raw_song.replace(" ", "%20") == raw_song) or (raw_song.find('spotify') > -1):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# [Artist] - [Song Name]
|
||||||
def generateSongName(raw_song):
|
def generateSongName(raw_song):
|
||||||
if isSpotify(raw_song):
|
if isSpotify(raw_song):
|
||||||
tags = generateMetaTags(raw_song)
|
tags = generateMetaTags(raw_song)
|
||||||
@@ -93,6 +96,7 @@ def getYouTubeTitle(content, number):
|
|||||||
else:
|
else:
|
||||||
return str(number) + '. ' + title
|
return str(number) + '. ' + title
|
||||||
|
|
||||||
|
# Generate name for the song to be downloaded
|
||||||
def generateFileName(content):
|
def generateFileName(content):
|
||||||
return fixEncoding((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(" ", "_"))
|
||||||
|
|
||||||
@@ -133,6 +137,7 @@ def checkExists(music_file, raw_song, islist):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Remove song from list.txt once downloaded
|
||||||
def trimSong(file):
|
def trimSong(file):
|
||||||
with open(file, 'r') as fin:
|
with open(file, 'r') as fin:
|
||||||
data = fin.read().splitlines(True)
|
data = fin.read().splitlines(True)
|
||||||
@@ -151,6 +156,7 @@ def fixSong(music_file, meta_tags):
|
|||||||
audiofile.tag.images.set(3,albumart,"image/jpeg")
|
audiofile.tag.images.set(3,albumart,"image/jpeg")
|
||||||
audiofile.tag.save(version=(2,3,0))
|
audiofile.tag.save(version=(2,3,0))
|
||||||
|
|
||||||
|
# Logic behind preparing the song to download to finishing meta-tags
|
||||||
def grabSingle(raw_song, number):
|
def grabSingle(raw_song, number):
|
||||||
if number:
|
if number:
|
||||||
islist = True
|
islist = True
|
||||||
@@ -172,6 +178,7 @@ def grabSingle(raw_song, number):
|
|||||||
print('Fixing meta-tags')
|
print('Fixing meta-tags')
|
||||||
fixSong(music_file, meta_tags)
|
fixSong(music_file, meta_tags)
|
||||||
|
|
||||||
|
# Fix python2 encoding issues
|
||||||
def fixEncoding(query):
|
def fixEncoding(query):
|
||||||
if version_info > (3,0):
|
if version_info > (3,0):
|
||||||
return query
|
return query
|
||||||
@@ -181,7 +188,7 @@ def fixEncoding(query):
|
|||||||
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
|
# Ignore blank lines in list.txt (if any)
|
||||||
try:
|
try:
|
||||||
lines.remove('')
|
lines.remove('')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
Reference in New Issue
Block a user