#!/usr/bin/env python # -*- coding: UTF-8 -*- #author:Wos #simple online music #need modify the value of cookie , ua and sessionid variable import requests import json import os import random import time import urllib import sys stid = [] first = True proxies={} cookie="" #need to modify ua="" #need to modify sessionid="" #need to modify def test_link(url): try: res = urllib.request.urlopen(url,timeout=2).read(12) if str(res).startswith("b\'\\x00\\x00\\x00\\x18ftypM4A"): return True elif str(res).startswith("b\'ID3"): return True else: return False except: return False def get_music(): try: os.system('clear') global stid,first hdr = { "cookie":cookie, "upgrade-insecure-requests": "1", "user-agent":ua } random.seed(time.time()*9) if first: try: sid = stid[0] first = False except: sid = "" first = False else: sid = random.choice(stid) if sid != "": url = "https://www.jango.com/streams/info?&sid="+str(sessionid)+"&stid="+str(sid)+"&ver=304" else: url = "https://www.jango.com/streams/info?&sid="+str(sessionid) res = requests.get(url,headers=hdr,proxies=proxies).json() try: if len(stid) < 9: stid.index(res['similar_stations'][0]['id']) except: stid.append(str(res['similar_stations'][0]['id'])) link = "https:"+res['url'] if not test_link(link): return else: print("artist:"+res['artist']) print("song:"+res['song']) print("^C to change music") cmdline = ("mpv --really-quiet --vid=no \"%s\""%(link)) os.system(cmdline) return except KeyboardInterrupt: pass def get_stid(artist): global stid temp = "" try: temp = "+".join(str(artist).split(" ")) except: temp = artist hdr = { "cookie":cookie, "upgrade-insecure-requests": "1", "user-agent":ua } url = "https://www.jango.com/music/"+str(temp) res = requests.get(url,headers=hdr,proxies=proxies) stid.append(res.text.split("\"station_id\":\"")[1].split("\"")[0]) def get_artist(s): os.system('clear') print("eg:artist1") print("eg:artist1,artist2,...") if s != "": artist = s else: artist = input("artist:") try: i = 0 temp = str(artist).split(",") while i < len(temp): if temp[i].strip() != "": get_stid(temp[i]) i += 1 except: pass def usage(): name = os.path.basename(__file__) print(name+" filename[a singer list,split with comma in a single line]") print(name+" [without parameter]") if __name__ == "__main__": try: if os.path.exists(sys.argv[1]) and len(sys.argv) == 2: f = open(sys.argv[1],"r",encoding="utf-8") line = f.readline().strip() if line: get_artist(line) else: get_artist("") f.close() while True: get_music() else: usage() except: get_artist("") while True: get_music()