cleanup
parent
1b18d94200
commit
48faf8ac54
86
scdl.py
86
scdl.py
|
@ -4,7 +4,7 @@
|
||||||
Usage:
|
Usage:
|
||||||
scdl.py -l <track_url> [--hidewarnings]
|
scdl.py -l <track_url> [--hidewarnings]
|
||||||
scdl.py --me [--hidewarnings]
|
scdl.py --me [--hidewarnings]
|
||||||
scdl.py --myprofile [--hidewarnings]
|
scdl.py --mystream [--hidewarnings]
|
||||||
scdl.py --allmytrack [--hidewarnings]
|
scdl.py --allmytrack [--hidewarnings]
|
||||||
scdl.py -h | --help
|
scdl.py -h | --help
|
||||||
scdl.py --version
|
scdl.py --version
|
||||||
|
@ -51,11 +51,11 @@ def main():
|
||||||
if arguments["-l"]:
|
if arguments["-l"]:
|
||||||
parse_url(arguments["<track_url>"])
|
parse_url(arguments["<track_url>"])
|
||||||
elif arguments["--me"]:
|
elif arguments["--me"]:
|
||||||
my_stream()
|
who_am_i()
|
||||||
elif arguments["--myprofile"]:
|
elif arguments["--mystream"]:
|
||||||
my_profile()
|
download_my_stream()
|
||||||
elif arguments["--allmytrack"]:
|
elif arguments["--allmytrack"]:
|
||||||
allmytrack()
|
download_all_profile_track()
|
||||||
|
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
|
@ -69,7 +69,24 @@ def get_config():
|
||||||
path = config['scdl']['path']
|
path = config['scdl']['path']
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
|
|
||||||
def allmytrack():
|
def who_am_i():
|
||||||
|
"""
|
||||||
|
display to who the current token correspond, check if the token is valid
|
||||||
|
"""
|
||||||
|
client = soundcloud.Client(access_token=token)
|
||||||
|
|
||||||
|
# make an authenticated call
|
||||||
|
try:
|
||||||
|
current_user = client.get('/me')
|
||||||
|
except:
|
||||||
|
print('Invalid token...')
|
||||||
|
sys.exit(0)
|
||||||
|
print('Hello',current_user.username, '!')
|
||||||
|
|
||||||
|
def download_all_profile_track():
|
||||||
|
"""
|
||||||
|
Download artist track &/or repost
|
||||||
|
"""
|
||||||
offset=0
|
offset=0
|
||||||
client = soundcloud.Client(access_token=token)
|
client = soundcloud.Client(access_token=token)
|
||||||
# make an authenticated call
|
# make an authenticated call
|
||||||
|
@ -77,27 +94,17 @@ def allmytrack():
|
||||||
response = wget.download("https://api.sndcdn.com/e1/users/%s/sounds.json?limit=1&offset=%d&client_id=9dbef61eb005cb526480279a0cc868c4" % (user_id, offset))
|
response = wget.download("https://api.sndcdn.com/e1/users/%s/sounds.json?limit=1&offset=%d&client_id=9dbef61eb005cb526480279a0cc868c4" % (user_id, offset))
|
||||||
print(response)
|
print(response)
|
||||||
|
|
||||||
def my_stream():
|
def download_my_stream():
|
||||||
|
"""
|
||||||
|
Download the stream of the current user
|
||||||
|
|
||||||
|
"""
|
||||||
client = soundcloud.Client(access_token=token)
|
client = soundcloud.Client(access_token=token)
|
||||||
# make an authenticated call
|
# make an authenticated call
|
||||||
current_user = client.get('/me')
|
current_user = client.get('/me')
|
||||||
print('Hello',current_user.username, '!')
|
activities = client.get('/me/activities')
|
||||||
activities = client.get('/me/sounds')
|
|
||||||
print(activities.type)
|
print(activities.type)
|
||||||
|
|
||||||
def settags(track):
|
|
||||||
"""
|
|
||||||
Set the tags to the mp3
|
|
||||||
"""
|
|
||||||
print("Settings tags...")
|
|
||||||
user = client.get('/users/' + str(track.user_id), allow_redirects=False)
|
|
||||||
audiofile = my_eyed3.load(filename)
|
|
||||||
audiofile.tag.artist = user.username
|
|
||||||
audiofile.tag.album = track.title
|
|
||||||
audiofile.tag.title = track.title
|
|
||||||
|
|
||||||
audiofile.tag.save()
|
|
||||||
|
|
||||||
def get_item(track_url):
|
def get_item(track_url):
|
||||||
"""
|
"""
|
||||||
Fetches metadata for an track or playlist
|
Fetches metadata for an track or playlist
|
||||||
|
@ -124,19 +131,14 @@ def parse_url(track_url):
|
||||||
download_track(item)
|
download_track(item)
|
||||||
elif item.kind == 'user':
|
elif item.kind == 'user':
|
||||||
print("Found an user profile")
|
print("Found an user profile")
|
||||||
download_user(item)
|
download_user_favorites(item)
|
||||||
elif item.kind == "playlist":
|
elif item.kind == "playlist":
|
||||||
print("Found a playlist")
|
print("Found a playlist")
|
||||||
for track_raw in item.tracks:
|
download_playlist(item)
|
||||||
mp3_url = get_item(track_raw["permalink_url"])
|
|
||||||
if item:
|
|
||||||
download_track(mp3_url)
|
|
||||||
else:
|
|
||||||
print("Could not find track " + track_raw["title"])
|
|
||||||
else:
|
else:
|
||||||
print("Unknown item type")
|
print("Unknown item type")
|
||||||
|
|
||||||
def download_user(user):
|
def download_user_favorites(user):
|
||||||
"""
|
"""
|
||||||
Fetch users data
|
Fetch users data
|
||||||
"""
|
"""
|
||||||
|
@ -153,6 +155,17 @@ def download_user(user):
|
||||||
end_of_tracks =True
|
end_of_tracks =True
|
||||||
offset += 10
|
offset += 10
|
||||||
|
|
||||||
|
def download_playlist(playlist):
|
||||||
|
"""
|
||||||
|
Download a playlist
|
||||||
|
"""
|
||||||
|
for track_raw in playlist.tracks:
|
||||||
|
mp3_url = get_item(track_raw["permalink_url"])
|
||||||
|
if item:
|
||||||
|
download_track(mp3_url)
|
||||||
|
else:
|
||||||
|
print("Could not find track " + track_raw["title"])
|
||||||
|
|
||||||
def download_track(track):
|
def download_track(track):
|
||||||
"""
|
"""
|
||||||
Downloads a track
|
Downloads a track
|
||||||
|
@ -183,6 +196,19 @@ def download_track(track):
|
||||||
print('')
|
print('')
|
||||||
print(title + ' Downloaded.')
|
print(title + ' Downloaded.')
|
||||||
|
|
||||||
|
def settags(track):
|
||||||
|
"""
|
||||||
|
Set the tags to the mp3
|
||||||
|
"""
|
||||||
|
print("Settings tags...")
|
||||||
|
user = client.get('/users/' + str(track.user_id), allow_redirects=False)
|
||||||
|
audiofile = my_eyed3.load(filename)
|
||||||
|
audiofile.tag.artist = user.username
|
||||||
|
audiofile.tag.album = track.title
|
||||||
|
audiofile.tag.title = track.title
|
||||||
|
|
||||||
|
audiofile.tag.save()
|
||||||
|
|
||||||
def signal_handler(signal, frame):
|
def signal_handler(signal, frame):
|
||||||
"""
|
"""
|
||||||
handle keyboardinterrupt
|
handle keyboardinterrupt
|
||||||
|
|
Loading…
Reference in New Issue