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
def test_put_track_metadata(): cl = Client(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN) res = cl.put("/tracks/%s" % TRACK_ID, metadata={"title": "hello live test"}) assert res.status_code == 200
def __init__(self): # Initialize the auth - we will want to get a non-expiring token # You can read and see flow here: http://developers.soundcloud.com/docs/api/guide#authentication self.sc = Client(client_id=settings.SOUNDCLOUD_CLIENT, client_secret=settings.SOUNDCLOUD_SECRET, redirect_uri=settings.SOUNDCLOUD_REDIRECT, scope='non-expiring')
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
class SoundCloudAuth(TemplateView): """ Authentication view for SC using OAuth - this is basically just here to generate an access token as they don't have a console like Facebook to quickly create one manually. Since we are likely to need this in future might as well create it in a class view now """ template_name = 'radio/auth.html' def __init__(self): # Initialize the auth - we will want to get a non-expiring token # You can read and see flow here: http://developers.soundcloud.com/docs/api/guide#authentication self.sc = Client(client_id=settings.SOUNDCLOUD_CLIENT, client_secret=settings.SOUNDCLOUD_SECRET, redirect_uri=settings.SOUNDCLOUD_REDIRECT, scope='non-expiring') def get_context_data(self, **kwargs): context = super(SoundCloudAuth, self).get_context_data(**kwargs) context['auth_url'] = self.sc.authorize_url() return context def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) code = request.GET.get('code', None) if code is not None: access_token = self.sc.exchange_token(code) context['access_token'] = access_token return self.render_to_response(context)
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)
def __init__(self): CLIENT_ID = os.environ.get('SOUNDCLOUD_ID') CLIENT_SECRET = os.environ.get('SOUNDCLOUD_SECRET') CLIENT_EMAIL = os.environ.get('SOUNDCLOUD_EMAIL') CLIENT_PASSWORD = os.environ.get('SOUNDCLOUD_PASSWORD') self.client = Client(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username=CLIENT_EMAIL, password=CLIENT_PASSWORD)
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())
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)
def sync(cls): client = Client(client_id=app.config['SOUNDCLOUD_APP_KEY_ID'], client_secret=app.config['SOUNDCLOUD_APP_KEY_SECRET'], username=app.config['SOUNDCLOUD_USERNAME'], password=app.config['SOUNDCLOUD_PASSWORD']) cls.upload_files(client) cls.sync_upload_state(client)
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 __init__(self): # Initialize the auth - we will want to get a non-expiring token # You can read and see flow here: http://developers.soundcloud.com/docs/api/guide#authentication self.sc = Client( client_id=settings.SOUNDCLOUD_CLIENT, client_secret=settings.SOUNDCLOUD_SECRET, redirect_uri=settings.SOUNDCLOUD_REDIRECT, scope='non-expiring' )
def __init__(self): CLIENT_ID = os.environ.get('SOUNDCLOUD_ID') CLIENT_SECRET = os.environ.get('SOUNDCLOUD_SECRET') CLIENT_EMAIL = os.environ.get('SOUNDCLOUD_EMAIL') CLIENT_PASSWORD = os.environ.get('SOUNDCLOUD_PASSWORD') self.client = Client( client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username=CLIENT_EMAIL, password=CLIENT_PASSWORD )
class SoundCloudAuth(TemplateView): """ Authentication view for SC using OAuth - this is basically just here to generate an access token as they don't have a console like Facebook to quickly create one manually. Since we are likely to need this in future might as well create it in a class view now """ template_name = 'radio/auth.html' def __init__(self): # Initialize the auth - we will want to get a non-expiring token # You can read and see flow here: http://developers.soundcloud.com/docs/api/guide#authentication self.sc = Client( client_id=settings.SOUNDCLOUD_CLIENT, client_secret=settings.SOUNDCLOUD_SECRET, redirect_uri=settings.SOUNDCLOUD_REDIRECT, scope='non-expiring' ) def get_context_data(self, **kwargs): context = super(SoundCloudAuth, self).get_context_data(**kwargs) context['auth_url'] = self.sc.authorize_url() return context def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) code = request.GET.get('code', None) if code is not None: access_token = self.sc.exchange_token(code) context['access_token'] = access_token return self.render_to_response(context)
def sc_get_client(): from mixtape.models import SoundCloudInfo from soundcloud import Client from django.conf import settings data = SoundCloudInfo.objects.filter(active=True) if data: data = data[0] creds = { 'client_id': data.client_id, 'client_secret': data.client_secret, 'username': data.username, 'password': data.password, } return Client(**creds) else: return None
class CloudClient(): def __init__(self): CLIENT_ID = os.environ.get('SOUNDCLOUD_ID') CLIENT_SECRET = os.environ.get('SOUNDCLOUD_SECRET') CLIENT_EMAIL = os.environ.get('SOUNDCLOUD_EMAIL') CLIENT_PASSWORD = os.environ.get('SOUNDCLOUD_PASSWORD') self.client = Client(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username=CLIENT_EMAIL, password=CLIENT_PASSWORD) def post_track(self, filepath): track = self.client.post('/tracks', track={ 'title': 'SampleTrack', 'sharing': 'private', 'asset_data': open(filepath, 'rb') })
class CloudClient(): def __init__(self): CLIENT_ID = os.environ.get('SOUNDCLOUD_ID') CLIENT_SECRET = os.environ.get('SOUNDCLOUD_SECRET') CLIENT_EMAIL = os.environ.get('SOUNDCLOUD_EMAIL') CLIENT_PASSWORD = os.environ.get('SOUNDCLOUD_PASSWORD') self.client = Client( client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username=CLIENT_EMAIL, password=CLIENT_PASSWORD ) def post_track(self, filepath): track = self.client.post('/tracks', track={ 'title': 'SampleTrack', 'sharing': 'private', 'asset_data': open(filepath, 'rb') })
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()
def __init__(self): # Initialize the auth - we will want to get a non-expiring token # You can read and see flow here: http://developers.soundcloud.com/docs/api/guide#authentication super(SoundCloudBaseView, self).__init__() self.sc = Client(access_token=settings.SOUNDCLOUD_ACCESS_TOKEN, )
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
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 get_access_token(client_id, client_secret, redirect_url, url_handler, input_code): """Create an access token""" client = Client(client_id=client_id, client_secret=client_secret, redirect_url=redirect_url, scope="") url_handler(client.authorize_url()) code = input_code() return client.exchange_token(code)
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))
print(' 😟') print('error retrieving resolved url %s' % resolved_url) print('retrieving url %s' % resolved_url.url) if os.path.exists(temp): os.remove(temp) # else: # print(' 😊') return file_name 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)
# -*- 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"""
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)
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)
from soundcloud import Client from secrets import soundcloudSecrets # Create a new client that uses the user credentials oauth flow client = Client(client_id=soundcloudSecrets['APP_ID'], client_secret=soundcloudSecrets['APP_SECRET'], username=soundcloudSecrets['USERNAME'], password=soundcloudSecrets['PASSWORD']) def postSoundcloud(barbershopID, audioPath): track = client.post('/tracks', track={ 'title': "BARBERSHOP'D " + str(barbershopID), 'sharing': 'public', 'asset_data': open(audioPath, 'rb') }) soundcloudURL = track.permalink_url return soundcloudURL if __name__ == '__main__': postSoundcloud("TESTID", "../audioOutput.wav")
def auth(self, user, pw): self.client = Client(client_id='00d3fbad6f8ab649c131d0e558f8387d', client_secret='8b7d292013c5f4ddbbacccfee6059a54', username=str(user), password=str(pw))