Beispiel #1
0
 def get(self, **kwargs):
     """
         Reads in the json feed and updates _raw attribute
     """
     client = Client(access_token=self.access_token)
     self.tracks = client.get(self.endpoint, limit=kwargs.get('limit', 200), offset=kwargs.get('offset', 0))
     return self.tracks
def test_put_metadata_with_track_uri():
    cl = Client(client_id=CLIENT_ID,
                client_secret=CLIENT_SECRET,
                access_token=ACCESS_TOKEN)
    res = cl.get("/tracks/%s" % TRACK_ID)
    res = cl.put(res.uri, metadata={"title": "updated with track.uri"})
    assert res.status_code == 200
Beispiel #3
0
 def get(pk, auth):
     client = Client(client_id=auth.key, client_secret=auth.secret)
     response = client.get(
         '/tracks/' + pk,
     )
     response = json.loads(response.raw_data)
     return response
def test_get_tracks():
    cl = Client(client_id=CLIENT_ID,
                client_secret=CLIENT_SECRET,
                access_token=ACCESS_TOKEN)
    res = cl.get("/me/tracks")
    assert res.status_code == 200

    track_ids = [track.id for track in res]
    print(track_ids)
Beispiel #5
0
 def get(self, **kwargs):
     """
         Reads in the json feed and updates _raw attribute
     """
     client = Client(access_token=self.access_token)
     self.tracks = client.get(self.endpoint,
                              limit=kwargs.get('limit', 200),
                              offset=kwargs.get('offset', 0))
     return self.tracks
Beispiel #6
0
    def post(self, request, *args, **kwargs):

        #client = Client(client_id=CLIENT_ID,
         #               client_secret=CLIENT_SECRET,
          #              redirect_uri=REDIRECT_URL)


        client = Client(client_id=YOUR_CLIENT_ID)
        tracks = client.get('/tracks', limit=10)

        HttpResponseRedirect(client.authorize_url())
Beispiel #7
0
    def list(params, auth):
        if params['page_token'] == '':
            params['page_token'] = 1

        client = Client(client_id=auth.key, client_secret=auth.secret)
        response = client.get(
            '/tracks/',
            q=params['query'],
            limit=params['page_size'],
            offset=(int(params['page_token']) - 1) * int(params['page_size']),
        )
        return json.loads(response.raw_data)
Beispiel #8
0
    def list(params, auth):
        if params['page_token'] == '':
            params['page_token'] = 1

        client = Client(client_id=auth.key, client_secret=auth.secret)
        response = client.get(
            '/tracks/',
            q=params['query'],
            limit=params['page_size'],
            offset=(int(params['page_token']) - 1) * int(params['page_size']),
        )
        return json.loads(response.raw_data)
Beispiel #9
0
def test(access_token):
    client = Client(access_token=access_token)
    username = client.get("/me").username
    print("Hi, {username}! You've successfully authenticated.".format(username=username))
Beispiel #10
0
if not os.path.exists(TRACKS_DIR):
    os.makedirs(TRACKS_DIR)

client = Client(client_id=CLIENT_ID,
                client_secret=CLIENT_SECRET,
                username=USERNAME,
                password=PASSWORD)
now = datetime.datetime.now(pytz.utc)

for set_url in sys.argv[1:]:
    fg = FeedGenerator()
    fg.load_extension('podcast', atom=True, rss=True)

    try:
        res = client.get('/resolve', url=set_url)
    except Exception as err:
        print('error resolving url %s' % set_url)
        continue

    fg.id(set_url)

    if res.kind == 'user':
        fg.title(res.username)
        fg.description(res.username)
        fg.logo(res.avatar_url)
        fg.author({'name': res.username})
    elif res.kind == 'playlist':
        fg.title(res.title)
        fg.description(res.title)
        fg.logo(res.user['avatar_url'])
Beispiel #11
0
    def get(self, request, *args, **kwargs):
        client = Client(client_id=CLIENT_ID)
        tracks = client.get('/tracks', limit=10)

        context = locals()
        return render(request, self.template_name, context)
Beispiel #12
0
class SoundcloudObject:
    def __init__(self, user, pw):
        self.auth(user, pw)
        """ Authentification """
        client = Client(client_id='00d3fbad6f8ab649c131d0e558f8387d',
                        client_secret='8b7d292013c5f4ddbbacccfee6059a54',
                        username=str(user),
                        password=str(pw))

    def auth(self, user, pw):
        self.client = Client(client_id='00d3fbad6f8ab649c131d0e558f8387d',
                             client_secret='8b7d292013c5f4ddbbacccfee6059a54',
                             username=str(user),
                             password=str(pw))

    def favorites(self, limit):
        tracks = self.client.get('/me/favorites', limit=limit)
        return tracks

    def username(self):
        return self.client.get('/me').username

    def user(self, url):
        user = self.client.get('/resolve', url=url)
        artist_username = str(user.username)
        global mypath
        mypath = "C:\\Users\\" + wuser + "\\Music\\" + artist_username
        if not path.exists(mypath): makedirs(mypath)
        id = str(user.id)
        request = '/users/' + id + '/tracks'
        tracks = self.client.get(request)
        return tracks

    def download(self):
        thread = threading.Thread(target=self.dl_thread)
        thread.start()

    def dl_thread(self):
        for track in tracks:
            no = tracks.index(track)
            if not no in to_dl:
                continue
            global title
            title_c = str(no) + "_title_label"
            title = container[title_c].label.cget("text")
            info.configure(text='Downloading  ' + title)
            global artist
            artist_c = str(no) + "_artist_label"
            artist = container[artist_c].label.cget("text")
            cover_url = track.artwork_url  #low-res
            global cover
            cover = cover_url.replace("large", "t500x500")  #high-res
            stream_url = self.client.get(track.stream_url,
                                         allow_redirects=False)
            global url
            url = stream_url.location.replace('https', 'http')
            filename = title + format
            global fullfilename
            fullfilename = path.join(mypath, filename)
            #             while progressbar["value"] < 99 :
            #                 pass
            urllib.request.urlretrieve(url,
                                       fullfilename,
                                       reporthook=self.progress)
            self.add_tags(title, artist, cover, fullfilename)
            info.configure(text='Done.')
            progressbar["value"] = 0

    def progress(self, count, blocksize, totalsize):
        """ count : number of blocks downloaded ; blockSize : size of a single block (8192) ; total size of the file. urlretrieve update the content constantly"""

        bytesdownloaded = blocksize * count
        mbdownloaded = bytesdownloaded / 1024 / 1024
        mbsize = float(blocksize) / float(totalsize)
        totalsize = totalsize / 1024 / 1024
        percent = mbsize * 100
        progressbar.step(percent)

    def add_tags(self, title, artist, cover, fullfilename):
        file = MP3(fullfilename, ID3=ID3)

        try:
            file.add_tags()
        except error:
            pass
        #Cover
        file.tags.add(
            APIC(
                encoding=3,  # 3 is for utf-8
                mime='image/png',  # image/jpeg or image/png
                type=3,  # 3 is for the cover image
                desc=u'Cover',
                data=urllib.request.urlopen(cover).read()))
        #Title
        file.tags.add(TIT2(encoding=3, text=title))
        #Artist
        file.tags.add(TPE1(encoding=3, text=artist))

        file.save()
import urllib
import os
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error, TIT2, TPE1
from progressbar import FileTransferSpeed, Percentage, ProgressBar
from soundcloud import Client

# Authentification
client = Client(client_id='YOUR_CLIENT_ID',
                client_secret='YOU_CLIENT_SECRET',
                username='******',
                password='******')

# Welcome
print 'Hello %s' % client.get('/me').username

# Directory to download songs to
download_location = 'music/'

# Make music directory if needed
if not os.path.exists(download_location):
    os.makedirs(download_location)

def progress(count, blockSize, totalSize):
    """ count : number of blocks downloaded ; blockSize : size of a single block (8192) ; total size of the file. urlretrieve update the content constantly"""
    total = totalSize//blockSize 		#  number of blocks it will take to download the entire file
    percent = int(100*count//total)     #  current percentage downloaded
    pbar.update(percent)   				#  update the progress bar by 1% if reached

# Get the favorites and go!
favorites = client.get('/me/favorites', limit=1000)
Beispiel #14
0
 def get(pk, auth):
     client = Client(client_id=auth.key, client_secret=auth.secret)
     response = client.get('/tracks/' + pk, )
     response = json.loads(response.raw_data)
     return response
# -*- coding: utf-8 -*-
import urllib
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error, TIT2, TPE1
from progressbar import FileTransferSpeed,Percentage,ProgressBar
from soundcloud import Client

# Authentification

client = Client(client_id='YOUR_CLIENT_ID',
                client_secret='YOU_CLIENT_SECRET',
                username='******',
                password='******')

print ('Hello',client.get('/me').username,',','showing your recently favorited songs :')

                           
favorites = client.get('/me/favorites', limit=30)   # shows a list with your last 30 favorited songs
for track in favorites:
    a=str(1+favorites.index(track))+'.'
    title = track.title
    artist = track.user["username"]    
    print(a,title,' by ',username)
    
print()
n = int(input('How many songs would you like to download ?'))
print()
numbers = input('Songs to be excluded: ').split(",")

def progress(count, blockSize, totalSize):
    """ count : number of blocks downloaded ; blockSize : size of a single block (8192) ; total size of the file. urlretrieve update the content constantly"""
def test_get_track_detail():
    cl = Client(client_id=CLIENT_ID,
                client_secret=CLIENT_SECRET,
                access_token=ACCESS_TOKEN)
    res = cl.get("/tracks/%s" % TRACK_ID)
    assert res.status_code == 200