summaryrefslogtreecommitdiff
path: root/libs/music/player.d/cgi-bin/m3u8.cgi
blob: 3e463ca725bc37164fedf4b7fb65e9f9141c71da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python3
import cgi
import os
import urllib.parse
d=cgi.parse()
try:
	plist=d['plist'][0]
	f=open(f'{os.environ["DOCUMENT_ROOT"]}/libs/music/player.d/playlists/{plist}.playlist','r',encoding='UTF-8')
except (OSError,KeyError) as e:
	print('Status: 400 Bad Request',end='\r\n')
	print('Content-type: text/plain',end='\r\n')
	print(end='\r\n')
	print('400. Shit.')
	print(e)
	exit()
print('Status: 200 OK',end='\r\n')
print('Content-type: audio/mpegurl',end='\r\n')
print(end='\r\n')
f.readline()
try:
	fmt=d['type'][0] if d['type'][0] in ['vorbis','flac','opus','m4a'] else 'vorbis'
except KeyError:
	fmt='vorbis'
ext='ogg' if fmt == 'vorbis' else fmt
for line in f:
	print(f'https://filestorage.chrisoft.org/music/{fmt}/{urllib.parse.quote(line.strip())}.{ext}')
f.close()