From f112c9977963edfca2ddba6de2ef83f0d8979cf4 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 5 Dec 2021 14:56:02 +0800 Subject: Roll Pineapple Cloud Music to c1dd09c. --- libs/music/player.d/cgi-bin/pcm.cgi | 76 +++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 28 deletions(-) (limited to 'libs/music/player.d/cgi-bin/pcm.cgi') diff --git a/libs/music/player.d/cgi-bin/pcm.cgi b/libs/music/player.d/cgi-bin/pcm.cgi index 2d5eaca..a1dc27f 100755 --- a/libs/music/player.d/cgi-bin/pcm.cgi +++ b/libs/music/player.d/cgi-bin/pcm.cgi @@ -1,34 +1,54 @@ #!/usr/bin/python3 import sys,os,cgi,json from urllib.parse import quote,unquote -d=cgi.parse(fp=sys.stdin) -print('Status: 200 OK',end='\r\n') -print('Content-type: application/json',end='\r\n') -print(end='\r\n') +def getfilelist(d): + fmt='ogg' if 'fmt' not in d else d['fmt'] -fmt='ogg' if 'fmt' not in d else d['fmt'] + ro={'status':200,'message':'OK'} + if 'folder' not in d or d['folder']=='': + plp=os.environ['DOCUMENT_ROOT']+'/libs/music/player.d/playlists/playlists' + alblist=list() + with open(plp,mode='r',encoding='utf-8') as f: + for line in f: + line=line.strip() + if len(line)>0:alblist.append(quote(line)) + rro={'type':'fileList','data':{'subFolderList':alblist}} + ro['result']=rro + print(json.dumps(ro)) + else: + alp=os.environ['DOCUMENT_ROOT']+'/libs/music/player.d/playlists/'+unquote(d['folder'][0]).strip('/')+'.playlist' + alblist=list() + with open(alp,mode='r',encoding='utf-8') as f: + for line in f: + line=line.strip() + if len(line)>0: + #hard code this for now, until pcm api stabilizes + alblist.append({'fileName':quote(line+'.ogg'),'fileSize':0,'modifiedTime':0}) + rro={'type':'fileList','data':{'musicList':alblist[1:],'subFolderList':list()}} + ro['result']=rro + print(json.dumps(ro)) + +def getserverinfo(d): + ro={'status': 200, 'message': 'OK'} + ro['result']={ + 'serverName': 'Pineapple Cloud Music', + 'serverShortName': 'PCM', + 'baseFolderNameHint': '', + 'preferredFormatsHint': 'ogg', + 'apiVersion': 1, + 'mediaRootUrl': '//filestorage.chrisoft.org/music/ogg/' + } + print(json.dumps(ro)) + +if __name__ == '__main__': + d=cgi.parse(fp=sys.stdin) + + print('Status: 200 OK',end='\r\n') + print('Content-type: application/json',end='\r\n') + print(end='\r\n') + + actionmap={'getserverinfo':getserverinfo, 'getfilelist':getfilelist} + if d['do'][0] in actionmap: + actionmap[d['do'][0]](d) -ro={'status':200,'message':'OK'} -if 'folder' not in d or d['folder']=='': - plp=os.environ['DOCUMENT_ROOT']+'/libs/music/player.d/playlists/playlists' - alblist=list() - with open(plp,mode='r',encoding='utf-8') as f: - for line in f: - line=line.strip() - if len(line)>0:alblist.append(quote(line)) - rro={'type':'fileList','data':{'subFolderList':alblist}} - ro['result']=rro - print(json.dumps(ro)) -else: - alp=os.environ['DOCUMENT_ROOT']+'/libs/music/player.d/playlists/'+unquote(d['folder'][0]).strip('/')+'.playlist' - alblist=list() - with open(alp,mode='r',encoding='utf-8') as f: - for line in f: - line=line.strip() - if len(line)>0: -#hard code this for now, until pcm api stabilizes - alblist.append({'fileName':quote(line+'.ogg'),'fileSize':0,'modifiedTime':0}) - rro={'type':'fileList','data':{'musicList':alblist[1:],'subFolderList':list()}} - ro['result']=rro - print(json.dumps(ro)) -- cgit v1.2.3