Example #1
0
def get_link(request):
	if request.method=="POST":
		link = '404;404;404'
		is_playable = request.POST.get('is_playable')
		type_ = request.POST.get('type')
		id_ = request.POST.get('id')
		name = request.POST.get('name')
		artist = request.POST.get('artist')
		artist_id = request.POST.get('artist_id')
		album = request.POST.get('album')
		album_id = request.POST.get('album_id')
		cover = request.POST.get('cover')
		if type_=='n' and is_playable=='True':
			link = NS.get_link(id_,album_id,True)
		elif type_=='x' and is_playable=='True':
			#不一定有封面的
			if cover!='cover':
				#有封面
				link = XS.get_link(id_,True)+';'+cover
			else:
				#无封面,无专辑
				link = XS.get_link(id_,False)

		elif type_=='n' and is_playable=='False':
			#解决网易不能播放的问题
			id_ = XS.parse_id(name,artist,' ')
			#print ids
			if id_:
				#虾米有源
				link = XS.get_link(id_,False)
			
		elif type_=='x' and is_playable=='False':
			#解决虾米不能播放的问题
			ids = NS.parse_id(name,artist,' ')
			#print ids
			if ids:
				#网易有源
				link = NS.get_link(str(ids['id']),str(ids['album_id']),False)
			
	#print link
	return HttpResponse(link)
Example #2
0
def xiami_album(request,id_):
	URL = 'http://www.xiami.com/song/playlist/id/%s/type/1' % id_
	headers = {'user-Agent':user_agent,'connection':'keep-alive'}
	xml = requests.get(URL,headers=headers)
	root = ET.fromstring(str(xml.content))
	tracklist = root[0]
	song_list = []
	for track in tracklist:
		name = track[0].text
		mp3Url = XS.decode_link(track[12].text)
		prepend_zero = lambda x : ('0'+x) if (len(x)==1) else x
		duration = int(track[18].text)
		duration = prepend_zero(str(duration/60)) + ':' + prepend_zero(str(duration%60))
		artist_name = track[9].text
		artist_id = track[20].text
		song_id = track[1].text
		album_name = track[3].text
		album_id = track[2].text
		cover = track[17].text
		result = {
				'id' : song_id,
				'name' : name,
				'duration' : duration,
				'artist_name' : artist_name,
				'artist_id' : artist_id,
				'album_name' : album_name,
				'album_id' : album_id,
				'cover' : cover,
				'mp3Url' : mp3Url
		}
		song_list.append(result)
		
	profile = {
		'detail' : song_list,
		'detail_str' : json.dumps(song_list)
	}
	return render(request,'xiami_detail.html',{'profile':profile,})