def getTrackFromTracklist(self, url, artist, track): r = requests.get(self.wwwToApi(url)) cloudcast = json.loads(u.toUtf8(r.text)) if ('sections' in cloudcast): for section in cloudcast['sections']: if ('track' in section): tracklistArtistName = section['track']['artist']['name'] if (u.clean(tracklistArtistName) == u.clean(artist)): trackName = self.getFullName(section['track']['artist']['name'], section['track']['name']) return trackName return None
def search(self, artist, track, offset): limit = 50 counts = {} q = string.join([artist, track]).replace(' ', '+') r = requests.get('http://api.mixcloud.com/search/?q=' + q + '&type=cloudcast&limit=' + str(limit) + '&offset=' + str(offset)) #print u.toUtf8(r.text) j = json.loads(u.toUtf8(r.text)) for d in j['data']: url = d['url'] user = d['user']['url'] ur = requests.get(self.wwwToApi(user)) #print u.toUtf8(ur.text) follower_count = json.loads(u.toUtf8(ur.text))['follower_count'] counts[url] = [d['listener_count'], d['play_count'], d['favorite_count'], d['comment_count'], follower_count] if ('paging' in j): if ('next' in j['paging']): counts.update(self.search(artist, track, offset + limit)) print (str(len(counts)) + ' tracklists were found') return counts
def getNeighboursFromTracklist(self, url, artist, track): r = requests.get(self.wwwToApi(url)) cloudcast = json.loads(u.toUtf8(r.text)) result = [] if ('sections' in cloudcast): sections = cloudcast['sections'] for (i, section) in enumerate(sections): if ('track' in section): tracklistArtistName = section['track']['artist']['name'] tracklistTrackName = section['track']['name'] if (u.clean(tracklistArtistName).find(u.clean(artist)) >= 0 and u.clean(tracklistTrackName).find(u.clean(track)) >= 0): if (i > 0): prev = sections[i - 1] name = u.toName(prev['track']['artist']['name'], prev['track']['name']) result.append(name) if (i < len(sections) - 1): nxt = sections[i + 1] name = u.toName(nxt['track']['artist']['name'], nxt['track']['name']) result.append(name) break return result