-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·58 lines (46 loc) · 1.68 KB
/
main.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# coding=utf-8
import webapp2
import httplib
class DefaultHandler(webapp2.RequestHandler):
def get(self):
app_url = self.request.application_url
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
self.response.write('KBS 클래식FM: %s/kbs1\n' % app_url)
self.response.write('KBS 쿨FM: %s/kbs2\n' % app_url)
self.response.write('KBS 1라디오: %s/kbs1r\n' % app_url)
self.response.write('KBS 2라디오: %s/kbs2r\n' % app_url)
self.response.write('KBS 3라디오: %s/kbs3r\n' % app_url)
self.response.write('KBS 한민족방송: %s/kbsscr\n' % app_url)
self.response.write('KBS 월드 라디오: %s/kbsrki\n' % app_url)
class KbsHandler(webapp2.RequestHandler):
CHANNELS = {
'kbs1': 1,
'kbs2': 2,
'kbs1r': 3,
'kbs2r': 4,
'kbs3r': 5,
# Perhaps 6 is for DMB...
'kbsscr': 7,
'kbsrki': 8,
}
BASE_URL = \
'http://kong.kbs.co.kr/live_player/channelMini.php' \
+ '?id=juoradio' \
+ '&channel=%d'
def get(self, channel):
try:
channel_num = self.CHANNELS[channel]
self.redirect(self.getAddress(channel_num))
except KeyError:
self.redirect('/')
def getAddress(self, channel_num):
conn = httplib.HTTPConnection('kbs_radio_stream', 80)
conn.request('GET', self.BASE_URL % channel_num)
responseString = conn.getresponse().read()
conn.close()
startIndex = responseString.find('mms:')
return responseString[startIndex:]
app = webapp2.WSGIApplication(routes=[
('/', DefaultHandler),
(r'/(.+)', KbsHandler),
])