forked from Zanzibar82/plugin.video.streamondemand-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channelselector.py
249 lines (202 loc) · 15.5 KB
/
channelselector.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
# -*- coding: utf-8 -*-
# ------------------------------------------------------------
# streamondemand 5
# Copyright 2015 [email protected]
# http://blog.tvalacarta.info/plugin-xbmc/pelisalacarta/
#
# Distributed under the terms of GNU General Public License v3 (GPLv3)
# http://www.gnu.org/licenses/gpl-3.0.html
# ------------------------------------------------------------
# This file is part of streamondemand 5.
#
# pelisalacarta 4 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 3 of the License, or
# (at your option) any later version.
#
# pelisalacarta 4 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 pelisalacarta 4. If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------
import glob
import os
import traceback
import urlparse
from core import channeltools
from core import config
from core import logger
from core.item import Item
def getmainlist(preferred_thumb=""):
logger.info()
itemlist = list()
# Añade los canales que forman el menú principal
itemlist.append( Item(title=config.get_localized_string(30119) , channel="channelselector" , action="getchanneltypes", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_category.png"),viewmode="movie") )
itemlist.append( Item(title=config.get_localized_string(30137) , channel="buscadorall" , action="mainlist" , thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_search.png"),viewmode="movie") )
itemlist.append( Item(title=config.get_localized_string(50002), channel="novedades" , action="mainlist", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "thumb_novedades.png"),viewmode="movie") )
itemlist.append( Item(title=config.get_localized_string(30102) , channel="favoritos" , action="mainlist" , thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_fav.png"),viewmode="movie") )
if config.get_library_support():
itemlist.append( Item(title=config.get_localized_string(30131) , channel="biblioteca" , action="mainlist", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_library.png"),viewmode="movie") )
#itemlist.append( Item(title=config.get_localized_string(30101) , channel="descargas" , action="mainlist", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_download.png"),viewmode="movie") )
if "xbmceden" in config.get_platform():
itemlist.append( Item(title=config.get_localized_string(30100) , channel="configuracion" , action="mainlist", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_conf.png"), folder=False,viewmode="movie") )
else:
itemlist.append( Item(title=config.get_localized_string(30100) , channel="configuracion" , action="mainlist", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_conf.png"),viewmode="movie") )
itemlist.append( Item(title=config.get_localized_string(30138) , channel="update_version" , action="update_from_menu", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_download.png"),viewmode="movie") )
itemlist.append( Item(title=config.get_localized_string(30104) , channel="ayuda" , action="mainlist", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_help.png"),viewmode="movie") )
return itemlist
def get_thumb(preferred_thumb, thumb_name):
return urlparse.urljoin(get_thumbnail_path(preferred_thumb), thumb_name)
def getchanneltypes(preferred_thumb=""):
logger.info()
# Ahora construye el itemlist ordenadamente
itemlist = list()
itemlist.append(Item(title="Top Channels", channel="channelselector", action="filterchannels",
category="top channels", channel_type="top channels", thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_topchannels.png"),
viewmode="movie"))
itemlist.append(Item(title=config.get_localized_string(30122), channel="channelselector", action="filterchannels",
category="movie", channel_type="movie", thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_film.png"), viewmode="movie"))
itemlist.append(Item(title=config.get_localized_string(30123), channel="channelselector", action="filterchannels",
category="serie", channel_type="serie", thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_series.png"), viewmode="movie"))
itemlist.append(Item(title=config.get_localized_string(30124), channel="channelselector", action="filterchannels",
category="anime", channel_type="anime", thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_anime.png"), viewmode="movie"))
itemlist.append(Item(title=config.get_localized_string(30125), channel="channelselector", action="filterchannels",
category="documentary", channel_type="documentary", thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_documentales.png"),
viewmode="movie"))
itemlist.append(Item(title="Cult", channel="channelselector", action="filterchannels",
category="cult", channel_type="cult", thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_filmontv.png"),
viewmode="movie"))
itemlist.append(Item(title=config.get_localized_string(50000), channel="saghe", action="mainlist",
category="saghe", channel_type="saghe", thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_saghe.png")))
itemlist.append( Item(title=config.get_localized_string(50001) , channel="filmontv" , action="mainlist" , thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_filmontv.png"),viewmode="movie") )
#itemlist.append( Item(title=config.get_localized_string(50003) , channel="netflixsrc" , action="mainlist" , thumbnail = os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_series.png"),viewmode="movie") )
itemlist.append( Item( title=config.get_localized_string(30136) , channel="channelselector" , action="filterchannels" , channel_type="vos", category="vos" , thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_vos.png"),viewmode="movie") )
#itemlist.append( Item( title="Torrent" , channel="channelselector" , action="filterchannels" , channel_type="torrent", category="torrent" , thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "cat_menu_torrent.png"),viewmode="movie") )
itemlist.append( Item( title="[COLOR yellow]" + config.get_localized_string(30121) + "[/COLOR]" , channel="channelselector" , action="filterchannels" , channel_type="all", category="all" , thumbnail= os.path.join(config.get_runtime_path() , "resources" , "images", "main_menu_all.png"),viewmode="movie") )
return itemlist
def filterchannels(category, preferred_thumb=""):
logger.info()
channelslist = []
# Si category = "allchannelstatus" es que estamos activando/desactivando canales
appenddisabledchannels = False
if category == "allchannelstatus":
category = "all"
appenddisabledchannels = True
# Lee la lista de canales
channel_path = os.path.join(config.get_runtime_path(), "channels", '*.xml')
logger.info("channel_path="+channel_path)
channel_files = glob.glob(channel_path)
logger.info("channel_files encontrados "+str(len(channel_files)))
channel_language = config.get_setting("channel_language")
logger.info("channel_language="+channel_language)
if channel_language == "":
channel_language = "all"
logger.info("channel_language="+channel_language)
for channel in channel_files:
logger.info("channel="+channel)
try:
channel_parameters = channeltools.get_channel_parameters(channel[:-4])
# si el canal no es compatible, no se muestra
if not channel_parameters["compatible"]:
continue
# Si no es un canal lo saltamos
if not channel_parameters["channel"]:
continue
logger.info("channel_parameters="+repr(channel_parameters))
# Si prefiere el bannermenu y el canal lo tiene, cambia ahora de idea
if preferred_thumb == "bannermenu" and "bannermenu" in channel_parameters:
channel_parameters["thumbnail"] = channel_parameters["bannermenu"]
# Se salta el canal si no está activo y no estamos activando/desactivando los canales
channel_status = config.get_setting("enabled", channel_parameters["channel"])
if channel_status is None:
# si channel_status no existe es que NO HAY valor en _data.json
channel_status = channel_parameters["active"]
# fix temporal para solucionar que enabled aparezca como "true/false"(str) y sea true/false(bool)
# TODO borrar este fix en la versión > 4.2.1, ya que no sería necesario
else:
if isinstance(channel_status, basestring):
if channel_status == "true":
channel_status = True
else:
channel_status = False
config.set_setting("enabled", channel_status, channel_parameters["channel"])
if channel_status != True:
# si obtenemos el listado de canales desde "activar/desactivar canales", y el canal está desactivado
# lo mostramos, si estamos listando todos los canales desde el listado general y está desactivado,
# no se muestra
if appenddisabledchannels != True:
continue
# Se salta el canal para adultos si el modo adultos está desactivado
if channel_parameters["adult"] == True and config.get_setting("adult_mode") == 0:
continue
# Se salta el canal si está en un idioma filtrado
if channel_language != "all" \
and channel_parameters["language"] != config.get_setting("channel_language"):
continue
# Se salta el canal si está en una categoria filtrado
if category != "all" and category not in channel_parameters["categories"]:
continue
# Si tiene configuración añadimos un item en el contexto
context = []
if channel_parameters["has_settings"]:
context.append({"title": "Configurar canal", "channel": "configuracion", "action": "channel_config",
"config": channel_parameters["channel"]})
# Si ha llegado hasta aquí, lo añade
channelslist.append(Item(title=channel_parameters["title"], channel=channel_parameters["channel"],
action="mainlist", thumbnail=channel_parameters["thumbnail"],
fanart=channel_parameters["fanart"], category=channel_parameters["title"],
language=channel_parameters["language"], viewmode="list",
version=channel_parameters["version"], context=context))
except:
logger.error("Se ha producido un error al leer los datos del canal " + channel)
import traceback
logger.error(traceback.format_exc())
channelslist.sort(key=lambda item: item.title.lower().strip())
if category == "all":
if config.get_setting("personalchannel5") == True:
channelslist.insert(0, Item(title=config.get_setting("personalchannelname5"), action="mainlist",
channel="personal5", thumbnail=config.get_setting("personalchannellogo5"),
type="generic", viewmode="list"))
if config.get_setting("personalchannel4") == True:
channelslist.insert(0, Item(title=config.get_setting("personalchannelname4"), action="mainlist",
channel="personal4", thumbnail=config.get_setting("personalchannellogo4"),
type="generic", viewmode="list"))
if config.get_setting("personalchannel3") == True:
channelslist.insert(0, Item(title=config.get_setting("personalchannelname3"), action="mainlist",
channel="personal3", thumbnail=config.get_setting("personalchannellogo3"),
type="generic", viewmode="list"))
if config.get_setting("personalchannel2") == True:
channelslist.insert(0, Item(title=config.get_setting("personalchannelname2"), action="mainlist",
channel="personal2", thumbnail=config.get_setting("personalchannellogo2"),
type="generic", viewmode="list"))
if config.get_setting("personalchannel") == True:
channelslist.insert(0, Item(title=config.get_setting("personalchannelname"), action="mainlist",
channel="personal", thumbnail=config.get_setting("personalchannellogo"),
type="generic", viewmode="list"))
channel_parameters = channeltools.get_channel_parameters("tengourl")
# Si prefiere el bannermenu y el canal lo tiene, cambia ahora de idea
if preferred_thumb == "bannermenu" and "bannermenu" in channel_parameters:
channel_parameters["thumbnail"] = channel_parameters["bannermenu"]
channelslist.insert(0, Item(title="Tengo una URL", action="mainlist", channel="tengourl",
thumbnail=channel_parameters["thumbnail"], type="generic", viewmode="list"))
channel_parameters = channeltools.get_channel_parameters("searchchannel")
channelslist.insert(0, Item(title="[COLOR gray]Cerca canale[/COLOR]", action="search", channel="searchchannel", thumbnail=channel_parameters["thumbnail"], type="generic", viewmode="movie"))
return channelslist
def get_thumbnail_path(preferred_thumb=""):
web_path = ""
if preferred_thumb == "":
thumbnail_type = config.get_setting("thumbnail_type")
if thumbnail_type == "":
thumbnail_type = 2
if thumbnail_type == 0:
web_path = "http://media.tvalacarta.info/pelisalacarta/posters/"
elif thumbnail_type == 1:
web_path = "http://media.tvalacarta.info/pelisalacarta/banners/"
elif thumbnail_type == 2:
web_path = "http://media.tvalacarta.info/pelisalacarta/squares/"
else:
web_path = "http://media.tvalacarta.info/pelisalacarta/" + preferred_thumb + "/"
return web_path