mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Avoid use of os.chdir()
This commit is contained in:
@@ -57,7 +57,7 @@ def get_arguments():
|
|||||||
help='Use avconv for conversion otherwise set defaults to ffmpeg',
|
help='Use avconv for conversion otherwise set defaults to ffmpeg',
|
||||||
action='store_true')
|
action='store_true')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-f', '--folder', default='Music/',
|
'-f', '--folder', default=(os.path.join(sys.path[0], 'Music')),
|
||||||
help='path to folder where files will be stored in')
|
help='path to folder where files will be stored in')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-v', '--verbose', default=False, help='show debug output',
|
'-v', '--verbose', default=False, help='show debug output',
|
||||||
@@ -118,7 +118,6 @@ def generate_search_url(song, viewsort=False):
|
|||||||
|
|
||||||
|
|
||||||
def filter_path(path):
|
def filter_path(path):
|
||||||
os.chdir(sys.path[0])
|
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
for temp in os.listdir(path):
|
for temp in os.listdir(path):
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ from slugify import slugify
|
|||||||
import spotipy
|
import spotipy
|
||||||
import pafy
|
import pafy
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -222,11 +221,11 @@ def write_playlist(username, playlist_id):
|
|||||||
username, playlist_id, fields='tracks,next,name')
|
username, playlist_id, fields='tracks,next,name')
|
||||||
text_file = u'{0}.txt'.format(slugify(results['name'], ok='-_()[]{}'))
|
text_file = u'{0}.txt'.format(slugify(results['name'], ok='-_()[]{}'))
|
||||||
|
|
||||||
print(u'Feeding {0} tracks to {1}'.format(results['tracks']['total'], text_file))
|
print(u'Feeding {0} tracks to {1}'.format(results['tracks']['total'], text_file))
|
||||||
tracks = results['tracks']
|
tracks = results['tracks']
|
||||||
write_tracks(text_file, tracks)
|
write_tracks(text_file, tracks)
|
||||||
|
|
||||||
|
|
||||||
def write_album(album):
|
def write_album(album):
|
||||||
tracks = spotify.album_tracks(album['id'])
|
tracks = spotify.album_tracks(album['id'])
|
||||||
text_file = u'{0}.txt'.format(slugify(album['name'], ok='-_()[]{}'))
|
text_file = u'{0}.txt'.format(slugify(album['name'], ok='-_()[]{}'))
|
||||||
@@ -417,9 +416,7 @@ token = misc.generate_token()
|
|||||||
spotify = spotipy.Spotify(auth=token)
|
spotify = spotipy.Spotify(auth=token)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
os.chdir(sys.path[0])
|
|
||||||
args = misc.get_arguments()
|
args = misc.get_arguments()
|
||||||
|
|
||||||
misc.filter_path(args.folder)
|
misc.filter_path(args.folder)
|
||||||
|
|
||||||
if args.song:
|
if args.song:
|
||||||
|
|||||||
Reference in New Issue
Block a user