Esempio n. 1
0
def index_playlist(request):
	if request.method=="GET":
		netease_user = NU('a')
		netease_user.get_discover()
		result_netease = {
			'new_cd' : netease_user.new_cd ,
			'hot_recommend' : netease_user.hot_recommend,
		}
		xiami_user = XU('a')
		xiami_user.get_discover()
		
		#cd做一下去重
		for cd in xiami_user.new_cd:
			for cd_n in netease_user.new_cd:
				if cd.get('title') == cd_n.get('title'):
					xiami_user.new_cd.remove(cd)
					break

		result_xiami = {
			'new_cd' : xiami_user.new_cd ,
			'hot_recommend' : xiami_user.hot_recommend
		}
		results = {
			'result_netease' : result_netease,
			'result_xiami' : result_xiami
		}
		return render(request,'more_playlist.html',{'results':results,})
Esempio n. 2
0
def user_home(request):
	'''展示每日推荐'''
	profile = {'status':True,'titleMsg':'发生错误'}
	if request.method=="GET":
		if request.session.get('is_login',False):
			username = request.session.get('username')
			profile['username'] = username
			user = User.objects.get(username=username)
			bound_xiami = user.bound_xiami
			xiami_type = user.xiami_type
			xiami_username = user.xiami_username
			xiami_headers = user.xiami_headers
			bound_netease = user.bound_netease
			netease_username = user.netease_username
			netease_uid = user.netease_uid
			netease_cookies = user.netease_cookies

			if bound_xiami == False and bound_netease == False:
				profile['bound_xiami'] = False
				profile['bound_netease'] = False

			if bound_xiami : 
				profile['bound_xiami'] = True
				#处理一下xiami cookie 不要加session id
				xiami_headers = xiami_headers.replace('\'','\"')
				dic = json.loads(xiami_headers)
				del dic['__XIAMI_SESSID']
				xu = XU(xiami_username)
				ret = xu.get_personal_taste(dic)

				#print ret
				if ret[0]:
					profile['taste_xiami'] = ret[1]
					profile['taste_xiami_str'] = json.dumps(ret[1])

			if bound_netease : 
				profile['bound_netease'] = True
				netease_cookies  = netease_cookies.replace('\'','\"')
				cookies = json.loads(netease_cookies)
				#个性化推荐 歌单 做不了 是post请求,需要密码。
				#ret = nu.get_personal_customized(cookies)
				#if ret[0]:
				#	profile['customized_netease'] = ret[1]
				#个性化 歌曲(taste)
				nu = NU(netease_username)
				ret = nu.get_personal_taste(cookies)
				if ret[0]:
					profile['taste_netease'] = ret[1]
					profile['taste_netease_str'] = json.dumps(ret[1])
			
			return render(request,'home.html',{'profile':profile,})
			
		else:
			return HttpResponseRedirect('/login/')
		
	return HttpResponseRedirect('/login/')
Esempio n. 3
0
def index(request):
	if request.method=="GET":
		xiami_user = XU('a')
		xiami_user.get_discover()
		
		result_xiami = {
			
			'daxia' : xiami_user.daxia
		}
		results = {
			
			'result_xiami' : result_xiami
		}
		return render(request,'more.html',{'results':results,})
Esempio n. 4
0
def bound_xiami_taobao(request):
	message = {'status':True,'titleMsg':'发生错误'}
	if request.method=="GET":
		if not request.session.get('is_login',False):
			return HttpResponseRedirect('/login/')
		else:
			#已绑定
			username = request.session.get('username')
			user = User.objects.get(username=username)
			if user.bound_xiami:
				return HttpResponseRedirect('/setting/')

	message = {'status':True,'data':{}}
	if request.method=="POST":
		taobao_id = request.POST.get('taobao_id')
		passwd = request.POST.get('passwd')
		captcha = request.POST.get('captcha',None)
		if taobao_id.replace(' ','') == '':
			return render(request,'bound_xiami_taobao.html',{'message':message,})
		if passwd.replace(' ','') == '':
			return render(request,'bound_xiami_taobao.html',{'message':message,})
		if captcha is None :
			captcha = ''
		elif captcha.replace(' ','') == '':
			captcha = ''

		xu = XU(taobao_id)

		message = xu.login_with_taobao(passwd,captcha)
		print message
		if message['status']:
			username = request.session.get('username')
			user = User.objects.get(username=username)
			user.bound_xiami = True
			user.xiami_username = message['nickname']
			user.xiami_uid = message['uid']
			user.xiami_type = 2
			user.xiami_headers = message['xiami_header']
			user.save()
			profile = {
				'username' : username,
				'xiami_username' : message['nickname']
			}
			return HttpResponseRedirect('/setting/')
		
	return render(request,'bound_xiami_taobao.html',{'message':message,})
Esempio n. 5
0
def add_to_playlist(request):
	#收藏歌曲
	if request.method=="POST":
		username = request.session.get('username')
		if not username:
			return HttpResponse('False')

		user = User.objects.get(username=username)
		
		ret = 'False'

		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')
		type = request.POST.get('type')
		id_ = request.POST.get('id')

		#print name , artist , artist_id , album,album_id,type,id_

		if type=='n':
			if not user.bound_netease:
				return HttpResponse('False')
			playlist_id = user.netease_playlist
			netease_cookies = user.netease_cookies
			netease_cookies  = netease_cookies.replace('\'','\"')
			cookies = json.loads(netease_cookies)
			
			if NU.add_to_playlist(id_,playlist_id,cookies):
				ret = 'True'
		elif type=='x':
			if not user.bound_xiami:
				return HttpResponse('False')
			xiami_headers = user.xiami_headers
			xiami_headers = xiami_headers.replace('\'','\"')
			dic = json.loads(xiami_headers)
			index_s = dic.get('Cookie').find('_xiamitoken')
			index_s = dic.get('Cookie').find('=',index_s)
			index_e = dic.get('Cookie').find(';',index_s)
			if index_e!=-1:
				token = dic.get('Cookie')[index_s+1:index_e]
			else:
				token = dic.get('Cookie')[index_s+1:]
			sessid = dic.get('__XIAMI_SESSID')
			cookie = dic.get('Cookie')
			cookie += ('; __XIAMI_SESSID='+sessid)
			li = cookie.split(';')
			xiami_cookie = {}
			for i in li:
				i_li = i.split('=')
				xiami_cookie[i_li[0]] = i_li[1]
			if XU.set_favor_song(id_,token,xiami_cookie):
				ret = 'True'
			#link = XU.get_link(id_)+';'+cover
		else:
			ret = 'False'
	return HttpResponse(ret)
Esempio n. 6
0
def search(request):
	if request.method=="GET":
		if 'keywords' in request.GET :
			keywords = request.GET.get('keywords',None)
			#print type(keywords)
			if keywords.replace(' ','') :
				results = XU.search(keywords)
				return render(request,'search.html',{'results':results,})
		
	return render(request,'search.html')
Esempio n. 7
0
def user_home_xiami(request,page='1'):
	'''展示虾米收藏'''
	profile = {'status':True,'titleMsg':'发生错误'}
	if request.method=="GET":
		if request.session.get('is_login',False):
			username = request.session.get('username')
			profile['username'] = username
			user = User.objects.get(username=username)
			bound_xiami = user.bound_xiami
			xiami_type = user.xiami_type
			xiami_username = user.xiami_username
			xiami_headers = user.xiami_headers

			if bound_xiami : 
				profile['bound_xiami'] = True
				profile['bound_netease'] = user.bound_netease
				#get 用headers
				xiami_headers = xiami_headers.replace('\'','\"')
				dic = json.loads(xiami_headers)
				del dic['__XIAMI_SESSID']
				xu = XU(xiami_username)
				ret = xu.get_favor_song(dic,page)
				
				profile['favor_song_xiami'] = ret[1]
				profile['page_total_list'] = range(1,int(ret[0])+1)
				profile['page_total'] = int(ret[0])
				if int(ret[0]) < int(page):
					profile['current_page'] = int(ret[0])
				else:
					profile['current_page'] = int(page)
					profile['current_page_pre'] = int(page)-1
					profile['current_page_next'] = int(page)+1

				return render(request,'home_xiami.html',{'profile':profile,})
			else:
				return HttpResponseRedirect('/home/')
			
		else:
			return HttpResponseRedirect('/login/')
		
	return HttpResponseRedirect('/login/')
Esempio n. 8
0
def bound_xiami(request):
	message = {'status':True,'titleMsg':'发生错误'}
	if request.method=="GET":
		if not request.session.get('is_login',False):
			return HttpResponseRedirect('/login/')
		else:
			#已绑定
			username = request.session.get('username')
			user = User.objects.get(username=username)
			if user.bound_xiami:
				return HttpResponseRedirect('/setting/')

	if request.method=="POST":
		#如果已绑定,跳走(还要解绑,检查cookie有效期)
		xiami_id = request.POST.get('xiami_id')
		passwd = request.POST.get('passwd')
		
		if xiami_id.replace(' ','') == '':
			return render(request,'bound_xiami.html',{'message':message,})
		if passwd.replace(' ','') == '':
			return render(request,'bound_xiami.html',{'message':message,})

		xu = XU(xiami_id)
		message = xu.login_with_xiami(passwd)
		#print message
		if message['status']:
			username = request.session.get('username')
			user = User.objects.get(username=username)
			user.bound_xiami = True
			user.xiami_username = message['nickname']
			user.xiami_uid = message['uid']
			user.xiami_headers = message['xiami_header']
			user.save()
			profile = {
				'username' : username,
				'xiami_username' : message['nickname']
			}
			return HttpResponseRedirect('/setting/')
		
	return render(request,'bound_xiami.html',{'message':message,})