This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addon.py
executable file
·263 lines (237 loc) · 9.4 KB
/
addon.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# -*- coding: utf-8 -*-
import CommonFunctions as common
import urllib
import urllib2
import os,sys
import xbmcplugin
import xbmcgui
import xbmcaddon
from core import updater
from core import logger
from providers.r977musiccom import R977Musiccom
from providers.radionet import Radionet
from providers.redmp3cc import Redmp3cc
from providers.fildonet import Fildonet
from core.decoder import Decoder
#import re
##INIT GLOBALS##
addon = xbmcaddon.Addon(id='org.harddevelop.kodi.juke')
home = addon.getAddonInfo('path')
icon = xbmc.translatePath( os.path.join( home, 'icon.png' ) )
MAIN_URL = xbmcplugin.getSetting(int(sys.argv[1]), "remote_repository")
##CONSTANTS PARTS##
BROWSE_CHANNELS = "browse_channels"
MAX = 103
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
def add_dir(name,url,mode,iconimage,provider,page="", thumbnailImage='',lastCookie=''):
type = "Video"
#print url
#print mode
#print page
#name = re.sub('[^A-Za-z0-9]+', '',name)
#print page
u=sys.argv[0]+"?url="+urllib.quote_plus(url.decode('utf-8', 'replace').encode('iso-8859-1', 'replace'))
u+="&cookie="+lastCookie
u+="&mode="+str(mode)+"&page="
try:
u+=str(page)
except:
u+=page
pass
provider = str(provider)
u+="&provider="+provider
ok=True
liz=xbmcgui.ListItem(name, iconImage=iconimage, thumbnailImage=iconimage)
liz.setInfo(type='Video', infoLabels={'Title': name})
if mode == 2 or (mode >=100 and mode<=MAX): #playable, not browser call, needs decoded to be playable or rtmp to be obtained
liz.setProperty("IsPlayable", "true")
liz.setPath(url)
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False) #Playable
else:
liz.setProperty('Fanart_Image', thumbnailImage)
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True) #Folder
return ok
def get_main_dirs():
add_dir(addon.getLocalizedString(10001), BROWSE_CHANNELS, 3, '', icon, 0)
try:
if updater.isUpdatable():
add_dir(addon.getLocalizedString(10011), '', 0, icon, 0)
except:
logger.error("Couldn't add update option: probably server is down!")
def get_dirs(url,name,page):
#print "using url: "+url
response = urllib2.urlopen(url)
html = response.read()
if url.endswith(".xml"): #main channels, it's a list to browse
lists = common.parseDOM(html,"list")
for item in lists:
name = common.parseDOM(item,"name")[0].encode("utf-8")
value = common.parseDOM(item,"url")[0].encode("utf-8")
add_dir(name, value, 1, icon,'', 0)
else: #it's the final list channel, split
bruteChannels = html.split("#EXTINF")
for item in bruteChannels:
item = item[item.find(",")+1:]
name = item[:item.find("\n")]
value = item[item.find("\n")+1:]
value = value[:value.find("\n")]
#print "detected channel: "+name+" with url: "+value
if name <> "" and value <> "": ##check for empty channels, we don't want it in our list
add_dir(name, value, 2, icon, '', name)
def open(url,page):
listitem = xbmcgui.ListItem(page)
listitem.setProperty('IsPlayable','true')
listitem.setPath(url)
listitem.setInfo("video",page)
try:
player = xbmc.Player(xbmc.PLAYER_CORE_AUTO)
if player.isPlaying() :
player.stop()
#xbmc.sleep(1000)
player.showSubtitles(False)
#urlPlayer = urllib.unquote_plus(url.replace("+","@#@")).replace("@#@","+")
#urlPlayer = urllib.unquote_plus(url) ##THIS METHOD FAILS IN SOME CASES SHOWING A POPUP (server petition and ffmpeg internal problem)
#player.play(urlPlayer,listitem) ##THIS METHOD FAILS IN SOME CASES SHOWING A POPUP (server petition and ffmpeg internal problem)
#print 'opening... '+url
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem) ##FIX FOR PREVIEWS LINE##
#xbmc.executebuiltin('Dialog.Close(all, true)') ## could be returned an empty element in a list, so player open the next and shows a invalid popup
except:
pass
#print(traceback.format_exc())
def browse_channels(url,page): #BROWSES ALL PROVIDERS
add_dir("fildo.net", 'fildonet', 4, "http://fildo.net/images/icons/logo2small2.png", 'fildonet', 0)
add_dir("977music.com", '977musiccom', 4, "http://www.977music.com/images11/logo.png", '977musiccom', 0)
add_dir("radio.net", 'radionet', 4, "http://www.aquaradio.net16.net/Media/Logos/radio.net.png", 'radionet', 0)
add_dir("redmp3.cc", 'redmp3cc', 4, "", 'redmp3cc', 0)
def browse_channel(url,page,provider,cookie=''): #MAIN TREE BROWSER IS HERE!
if provider == "977musiccom":
jsonChannels = R977Musiccom.getChannels(page,cookie)
for item in jsonChannels:
mode = 4
image = icon
if item.has_key("thumbnail"):
image = item["thumbnail"]
if item.has_key("finalLink"):
mode = 2
add_dir(item["title"],item["link"],mode,image,"977musiccom",item["link"],'',R977Musiccom.cookie)
elif provider== "radionet":
jsonChannels = Radionet.getChannels(page,cookie)
mode = 102
for item in jsonChannels:
image = icon
if item.has_key("thumbnail"):
image = item["thumbnail"]
add_dir(item["title"],item["link"],mode,image,"radionet",item["link"],'',Radionet.cookie)
elif provider== "redmp3cc":
jsonChannels = Redmp3cc.getChannels(page,cookie)
for item in jsonChannels:
mode = 4
image = icon
if item.has_key("thumbnail"):
image = item["thumbnail"]
if item["link"].find(".html")==-1:
mode = 103
logger.info("detected final link: "+item["link"])
add_dir(item["title"],item["link"],mode,image,"redmp3cc",item["link"],'',Redmp3cc.cookie)
elif provider == 'fildonet':
jsonChannels = Fildonet.getChannels(page,cookie)
for item in jsonChannels:
mode = 4
image = icon
if item.has_key("thumbnail"):
image = item["thumbnail"]
if item["link"].find(".mp3")!=-1:
mode = 2
item["link"] = Fildonet.parseLinkToLoadBalancer(item["link"])
logger.info("detected final file: "+item["link"])
add_dir(item["title"],item["link"],mode,image,"fildonet",item["link"],'',Redmp3cc.cookie)
logger.info(provider)
def open_channel(url,page,provider=""):
finalUrls = R977Musiccom.getChannelUrl(url)
for finalUrl in finalUrls:
add_dir(page+", "+finalUrl["name"],finalUrl["url"],2,provider,page)
def init():
params=get_params()
url=""
mode=None
page=""
cookie=""
try:
page=urllib.unquote_plus(params["page"])
except:
pass
try:
url=urllib.unquote_plus(params["url"])
except:
pass
try:
mode=int(params["mode"])
except:
pass
try:
provider=urllib.unquote_plus(params["provider"])
except:
pass
try:
logger.info("cookie was filled with: "+params["cookie"])
cookie=urllib.unquote_plus(params["cookie"])
except:
pass
#print "Mode: "+str(mode)
print "URL: "+str(url)
print "cookie: "+str(cookie)
if mode==None: #init
get_main_dirs()
elif mode==1: #get channels
get_dirs(url, '', page)
elif mode == 2: #open multimedia file in player
open(url,page)
elif mode == 3:
browse_channels(url,page)
elif mode == 4:
browse_channel(url,page,provider,cookie) #main logic
elif mode == 5:
open_channel(url,page)
elif mode == 0: #update
if xbmcgui.Dialog().yesno(addon.getLocalizedString(10011),updater.getUpdateInfo(), "", "", addon.getLocalizedString(11013), addon.getLocalizedString(11014) ):
updater.update()
get_main_dirs()
elif mode == 100: #decode provider link
logger.info("decoding: "+url)
link = Decoder.decodeLink(url)
logger.info("decoded: "+link)
open(link,page)
elif mode == 101:
jsonChannels = R977Musiccom.getChannels(page,cookie)
url = jsonChannels[0]["link"]
logger.info("found link: "+url+", launching...")
open(url,page) #same that 2, but reserved for rtmp
elif mode == 102:
jsonChannels = Radionet.getChannels(page,cookie)
url = jsonChannels[0]["link"]
logger.info("found link: "+url+", launching...")
open(url,page) #same that 2, but reserved for rtmp
elif mode == 103:
jsonChannels = Redmp3cc.getChannels(url,cookie)
url = jsonChannels[0]["link"]
logger.info("found link: "+url+", launching...")
open(url,page) #same that 2, but reserved for rtmp
logger.info("remove temp: "+url)
#os.remove(url)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
init()