-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMojePolskieRadioPlugin.py
86 lines (79 loc) · 3.47 KB
/
MojePolskieRadioPlugin.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
##########################################################################
# Copyright 2013 Carlos Ribeiro
#
# This file is part of Radio Tray
#
# Radio Tray is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 1 of the License, or
# (at your option) any later version.
#
# Radio Tray is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Radio Tray. If not, see <http://www.gnu.org/licenses/>.
# Author of this plugin: Pawel Szafer, pszafer@gmail.com
#
##########################################################################
from Plugin import Plugin
import gtk
import gobject
import urllib2
from lib import utils
import os
from lib.common import SYSTEM_PLUGIN_PATH, USER_PLUGIN_PATH
import base64, socket
import simplejson as myjson
class MojePolskieRadioPlugin(Plugin):
def __init__(self):
super(MojePolskieRadioPlugin, self).__init__()
def activate(self):
if os.path.exists(os.path.join(USER_PLUGIN_PATH, "mojepolskieradio.glade")):
self.gladefile = utils.load_ui_file(os.path.join(USER_PLUGIN_PATH, "mojepolskieradio.glade"))
elif os.path.exists(os.path.join(SYSTEM_PLUGIN_PATH, "mojepolskieradio.glade")):
self.gladefile = utils.load_ui_file(os.path.join(SYSTEM_PLUGIN_PATH, "mojepolskieradio.glade"))
else:
self.log.error('Error initializing MojePolskieRadio plugin: mojepolskieradio.glade not found')
self.window = self.gladefile.get_object('dialog1')
if (self.window):
self.gladefile.connect_signals(self)
def getName(self):
return self.name
def on_menu(self, data):
self.window.show()
def on_run_clicked(self, widget):
self.putIntoBookmarksMojePolskieRadioStations()
return
def on_close_clicked(self, widget):
self.window.hide()
return True
def putIntoBookmarksMojePolskieRadioStations(self):
groupName = "Moje Polskie Radio"
CHANNELS_URL = 'http://moje.polskieradio.pl/api/?key=%s&output=json'
A_I_K = 'MjJhZmMzNzg2NzQxLWRlZDktMjU4NC02NmViLWZkZjkzNDAy'
parent_group = "root"
self.provider.addGroup(parent_group, groupName)
groupIndex = self.provider.listGroupNames().index(groupName)
aik = base64.b64decode(A_I_K)
u = urllib2.urlopen(CHANNELS_URL % aik[::-1])
jsonString = myjson.loads(u.read())
u.close()
channels = jsonString['channel']
for channel in channels:
name = channel['title']
streams = channel["AlternateStationsStreams"]
for stream in streams:
if stream['name'] == "mp3":
url = stream['link']
break
if len(name) > 0 and len(url) > 0:
if self.provider._radioExists(name):
self.provider.updateRadio(name, name, url)
else:
self.provider.addRadio(name, url, groupName)
self.eventManagerWrapper.notify('Moje Polskie Radio', 'All stations downloaded. Reload bookmarks now!')
def hasMenuItem(self):
return True