예제 #1
0
    def play(self,
             content_id=None,
             url=None,
             license_key=None,
             license_headers="",
             start_offset=0.0,
             content_type='',
             duration=0,
             start_paused=False):
        PROTOCOL = 'mpd'
        DRM = 'com.widevine.alpha'
        user_agent = utils.get_user_agent()

        play_item = xbmcgui.ListItem(path=url)
        play_item.setContentLookup(False)
        play_item.setMimeType('application/dash+xml')
        play_item.setProperty('inputstreamaddon', "inputstream.adaptive")
        play_item.setProperty('inputstream.adaptive.stream_headers',
                              "%s&Connection=keep-alive" % (user_agent))
        play_item.setProperty('inputstream.adaptive.manifest_type', PROTOCOL)

        if license_key != None:
            is_helper = inputstreamhelper.Helper(PROTOCOL, drm=DRM)
            if not is_helper.check_inputstream():
                Dialogs.show_dialog(utils.get_local_string(30063))
                return
            play_item.setProperty('inputstream.adaptive.license_type', DRM)
            play_item.setProperty(
                'inputstream.adaptive.license_key',
                license_key + '|' + license_headers + '|R{SSM}|')

            start_offset = int(start_offset)
            duration = int(duration)
            if start_offset >= 10 and duration - start_offset > 30:
                if not utils.get_setting("always_resume"):
                    xbmc.executebuiltin("Dialog.Close(all,true)")
                    dialog_title = utils.get_local_string(30050)
                    message = utils.get_local_string(30051) % (
                        utils.get_timestring_from_seconds(start_offset))
                    start_offset = start_offset if Dialogs.ask(
                        message, dialog_title) else 0
            else:
                start_offset = 0

            utils.call_service(
                "set_playing_item", {
                    "url": url,
                    "contentId": content_id,
                    "time": start_offset,
                    "videoType": content_type,
                    "duration": duration,
                    "paused": start_paused
                })
            xbmcplugin.setResolvedUrl(handle=self.plugin_handle,
                                      succeeded=True,
                                      listitem=play_item)
        else:
            xbmc.Player().play(item=url, listitem=play_item)
예제 #2
0
 def play_trailer(self, content_id, trailer_type):
     url = None
     if trailer_type == "MOVIE":
         url = utils.call_service("get_movie_trailer",
                                  {"contentId": content_id})
     elif trailer_type == "TVSHOW":
         url = utils.call_service("get_season_trailer",
                                  {"contentId": content_id})
     if url != None:
         self.play(url=url)
     else:
         dialog_title = utils.get_local_string(30036)
         dialog_msg = utils.get_local_string(30037)
         Dialogs.show_message(dialog_msg, dialog_title)
예제 #3
0
    def create_category_page(self, page_id, ha_elenco=False, category_name=''):
        if ha_elenco:
            list_item = xbmcgui.ListItem(label='Elenco completo')
            xbmcplugin.addDirectoryItem(
                handle=self.plugin_handle,
                url=utils.url_join(
                    self.plugin_dir,
                    "?action=full_list&category=%s" % (category_name)),
                listitem=list_item,
                isFolder=True)

        pages = utils.call_service("get_page", {"page": str(page_id)})
        if pages != None:
            pages = [
                page for page in pages
                if page["layout"] in ["SMALL_CARDS", "KIDS_COLLECTIONS"]
            ]
            for page in pages:
                if page["metadata"]["label"] == "TUTTI I TITOLI":
                    continue
                list_item = xbmcgui.ListItem(
                    label=page["metadata"]["label"].lower().capitalize())
                url = utils.url_join(
                    self.plugin_dir, "?action=open_page&uri=%s" %
                    (urllib.quote_plus(page["retrieveItems"]["uri"])))
                xbmcplugin.addDirectoryItem(handle=self.plugin_handle,
                                            isFolder=True,
                                            listitem=list_item,
                                            url=url)
        xbmcplugin.endOfDirectory(handle=self.plugin_handle)
        return
예제 #4
0
 def __update_tvshows_library(self):
     tvshows = utils.call_service("load_all_contents", {
         "begin": 0,
         "category": "Serie"
     })
     if tvshows == None or len(tvshows) == 0:
         return
     self.empty_tvshows_library()
     base_series_folder = os.path.join(self.library_folder,
                                       self.tvshows_folder)
     items = TimVisionObjects.parse_collection(tvshows)
     for tvshow in items:
         title_normalized = self.__normalize_path(tvshow.title)
         if len(title_normalized) == 0:
             # TODO: FIX ME
             continue  #skip shows with unicode characters/empty title
         Logger.kodi_log("Library (TV): %s" % (title_normalized))
         normalized_show_name = "%s (%d)" % (title_normalized, tvshow.year)
         show_folder = os.path.join(base_series_folder,
                                    normalized_show_name)
         xbmcvfs.mkdir(show_folder)
         seasons_json = utils.call_service(
             "get_show_content", {
                 "contentId": tvshow.content_id,
                 "contentType": TimVisionAPI.TVSHOW_CONTENT_TYPE_SEASONS
             })
         seasons = TimVisionObjects.parse_collection(seasons_json)
         for season in seasons:
             episodes_json = utils.call_service(
                 "get_show_content", {
                     "contentId": season.content_id,
                     "contentType":
                     TimVisionAPI.TVSHOW_CONTENT_TYPE_EPISODES
                 })
             episodes = TimVisionObjects.parse_collection(episodes_json)
             for episode in episodes:
                 filename = "%s S%02dE%02d" % (
                     normalized_show_name, episode.season, episode.episode)
                 url = "plugin://plugin.video.timvision/?action=play_item&contentId=%s&videoType=%s&has_hd=%s&startPoint=%s&duration=%s" % (
                     str(episode.content_id), episode.mediatype,
                     str(episode.is_hd_available), str(
                         episode.bookmark), str(episode.duration))
                 self.write_strm(
                     os.path.join(show_folder, filename + ".strm"),
                     filename, url)
예제 #5
0
 def verifica_login(self, count=0):
     logged = utils.call_service("is_logged")
     if not logged:
         email = utils.get_setting("username")
         password = utils.get_setting("password")
         if email != "" and password != "":
             logged = utils.call_service("login", {
                 "username": email,
                 "password": password
             })
         if not logged:
             if count == 0:
                 utils.set_setting(
                     "username",
                     Dialogs.get_text_input(utils.get_local_string(30001)))
                 utils.set_setting("password", Dialogs.get_password_input())
                 return self.verifica_login(count + 1)
     return logged
예제 #6
0
 def send_keep_alive(self):
     ka_resp = utils.call_service("keep_alive", {"contentId": self.current_content_id})
     if ka_resp != None:
         Logger.log_write("Keep Alive OK!", Logger.LOG_PLAYER)
         self.keep_alive_limit = int(ka_resp["resultObj"]["keepAlive"])
         self.keep_alive_token = ka_resp["resultObj"]["token"]
         return True
     Logger.log_write("Keep Alive FAILED!", Logger.LOG_PLAYER)
     return False
예제 #7
0
 def check_time(self):
     time_elapsed = 0
     self.current_time = int(self.getTime())
     while self.current_time > self.total_time or self.current_time < 0:
         xbmc.sleep(200)
     self.onCorrectTimeLoaded()
     
     while not self.playback_thread_stop_event.isSet():
         # keep live check
         self.current_time = int(self.getTime())
         self.playback_thread_stop_event.wait(2)
         time_elapsed += 2
         if time_elapsed >= self.keep_alive_limit and self.send_keep_alive():
             time_elapsed = 0
     
     # out of while
     complete_percentage = self.current_time * 100.0 / self.total_time
     Logger.log_write("Stopping (%s) - %.3f%%" % (self.current_content_id, complete_percentage), Logger.LOG_PLAYER)
     if complete_percentage >= 97.5:
         utils.call_service("set_content_seen", {"contentId":self.current_content_id, "duration": int(self.total_time)})
     elif self.current_time > 10:
         utils.call_service("stop_content", {"contentId":str(self.current_content_id), "time":int(self.current_time), "threshold": int(self.threshold)})
     self.reset_player()
예제 #8
0
 def create_context_menu(self, list_item):
     actions = []
     if self.mediatype in [ITEM_MOVIE, ITEM_TVSHOW]:
         is_fav = utils.call_service("is_favourite",
                                     {"contentId": self.content_id})
     if self.mediatype == ITEM_MOVIE:
         actions.extend([("Play Trailer", "RunPlugin(plugin://" +
                          PLUGIN_NAME + "/?action=play_trailer&contentId=" +
                          self.content_id + "&type=MOVIE)")])
         #actions.extend([("Gia' Visto", "RunPlugin("+self.plugin_dir+"?action=set_seen&contentId="+content_id+"&duration="+str(container["metadata"]["duration"])+")")])
         if is_fav:
             actions.extend([(
                 "Rimuovi da preferiti",
                 "RunPlugin(plugin://" + PLUGIN_NAME +
                 "/?action=toogle_favourite&value=False&contentId=%s&mediatype=%s)"
                 % (str(self.content_id), self.mediatype))])
         else:
             actions.extend([(
                 "Aggiungi a preferiti",
                 "RunPlugin(plugin://" + PLUGIN_NAME +
                 "/?action=toogle_favourite&value=True&contentId=%s&mediatype=%s)"
                 % (str(self.content_id), self.mediatype))])
     elif self.mediatype == ITEM_EPISODE:
         actions.extend([
             ("Play Trailer della Stagione", "RunPlugin(plugin://" +
              PLUGIN_NAME + "/?action=play_trailer&contentId=" +
              self.content_id + "&type=TVSHOW)")
         ])
         #actions.extend([("Gia' Visto", "RunPlugin(plugin://"+PLUGIN_NAME+"/?action=play_item&contentId="+self.content_id+"&duration="+str(self.duration)+"&video_type=VOD&has_hd=False&startPoint="+str(int(self.duration)-1)+")")])
     elif self.mediatype == ITEM_TVSHOW:
         if is_fav:
             actions.extend([(
                 "Rimuovi da preferiti (locale)",
                 "RunPlugin(plugin://" + PLUGIN_NAME +
                 "/?action=toogle_favourite&value=False&contentId=%s&mediatype=%s)"
                 % (str(self.content_id), self.mediatype))])
         else:
             actions.extend([(
                 "Aggiungi a preferiti (locale)",
                 "RunPlugin(plugin://" + PLUGIN_NAME +
                 "/?action=toogle_favourite&value=True&contentId=%s&mediatype=%s)"
                 % (str(self.content_id), self.mediatype))])
     elif self.mediatype == ITEM_SEASON:
         actions.extend([("Play Trailer", "RunPlugin(plugin://" +
                          PLUGIN_NAME + "/?action=play_trailer&contentId=" +
                          self.content_id + "&type=TVSHOW)")])
     list_item.addContextMenuItems(items=actions)
     return list_item
예제 #9
0
 def __update_movies_library(self):
     movies = utils.call_service("load_all_contents", {
         "begin": 0,
         "category": "Cinema"
     })
     if movies == None or len(movies) == 0:
         return
     self.empty_movies_library()
     items = TimVisionObjects.parse_collection(movies)
     folder_movies = os.path.join(self.library_folder, self.movies_folder)
     for item in items:
         title = "%s (%d)" % (item.title, item.year)
         url = "plugin://plugin.video.timvision/?action=play_item&contentId=%s&videoType=%s&has_hd=%s&startPoint=%s&duration=%s" % (
             str(item.content_id), item.mediatype, str(
                 item.is_hd_available), str(
                     item.bookmark), str(item.duration))
         filename = os.path.join(folder_movies,
                                 self.__normalize_path(title) + ".strm")
         self.write_strm(filename, title, url)
예제 #10
0
    def create_main_page(self):
        error = False
        categories = utils.call_service("get_categories")
        if categories is None:
            error = True
        else:
            for cat in categories:
                label = cat["metadata"]["label"]
                if label in ["A NOLEGGIO", "SPORT"]:
                    continue
                list_item = xbmcgui.ListItem(label=label.lower().capitalize())
                uri = cat["actions"][0]["uri"]
                page_id = uri[6:uri.find("?")]
                xbmcplugin.addDirectoryItem(
                    handle=self.plugin_handle,
                    url=utils.url_join(
                        self.plugin_dir,
                        "?page=%s&category_id=%s" % (label, page_id)),
                    isFolder=True,
                    listitem=list_item)
        list_item = xbmcgui.ListItem(label='Preferiti')
        xbmcplugin.addDirectoryItem(handle=self.plugin_handle,
                                    url=utils.url_join(self.plugin_dir,
                                                       "?action=favourites"),
                                    isFolder=True,
                                    listitem=list_item)
        list_item = xbmcgui.ListItem(label="Cerca...")
        xbmcplugin.addDirectoryItem(handle=self.plugin_handle,
                                    url=utils.url_join(self.plugin_dir,
                                                       "?action=search"),
                                    isFolder=True,
                                    listitem=list_item)
        xbmcplugin.endOfDirectory(handle=self.plugin_handle)

        if error:
            dialog_title = utils.get_local_string(30038)
            dialog_msg = utils.get_local_string(30042)
            Dialogs.show_dialog(dialog_msg, dialog_title)
예제 #11
0
 def play_video(self,
                content_id,
                video_type,
                has_hd=False,
                start_offset=0.0,
                duration=0,
                paused=False):
     if not self.verify_version(True):
         return
     license_info = utils.call_service("get_license_video", {
         "contentId": content_id,
         "videoType": video_type,
         "has_hd": has_hd
     })
     if license_info is None:
         dialog_msg = utils.get_local_string(30045)
         Dialogs.show_dialog(dialog_msg)
         return
     user_agent = utils.get_user_agent()
     headers = "%s&AVS_COOKIE=%s&Connection=keep-alive" % (
         user_agent, license_info["avs_cookie"])
     self.play(content_id, license_info["mpd_file"],
               license_info["widevine_url"], headers, start_offset,
               video_type, duration, paused)
예제 #12
0
    def router(self, parameters):
        if not self.verifica_login():
            utils.open_settings()
            return

        params = utils.get_parameters_dict_from_url(parameters)
        params_count = len(params)
        if params_count == 0:
            self.verify_version()
            self.create_main_page()
        else:
            if params.has_key("page"):
                page = params.get("page")
                category_id = params.get("category_id")
                if page in ["HOME", "INTRATTENIMENTO"]:
                    self.create_category_page(page_id=category_id)
                elif page == "CINEMA":
                    self.create_category_page(page_id=category_id,
                                              ha_elenco=True,
                                              category_name='Cinema')
                elif page == "SERIE TV":
                    self.create_category_page(page_id=category_id,
                                              ha_elenco=True,
                                              category_name='Serie')
                elif page == "BAMBINI":
                    self.create_category_page(page_id=category_id,
                                              ha_elenco=True,
                                              category_name='Kids')

            if params.has_key("action"):
                action = params.get("action")
                if action == "full_list":
                    category = params.get("category")
                    items = utils.call_service("load_all_contents", {
                        "begin": 0,
                        "category": category
                    })
                    self.add_items_to_folder(items)
                elif action == "apri_serie":
                    id_serie = params.get("id_serie")
                    nome_serie = urllib.unquote(params.get("serieNome", ""))
                    items = utils.call_service(
                        "get_show_content", {
                            "contentId": id_serie,
                            "contentType":
                            TimVisionAPI.TVSHOW_CONTENT_TYPE_SEASONS
                        })
                    if len(items) == 1 and utils.get_setting("unique_season"):
                        items = TimVisionObjects.parse_collection(items)
                        items = utils.call_service(
                            "get_show_content", {
                                "contentId":
                                items[0].content_id,
                                "contentType":
                                TimVisionAPI.TVSHOW_CONTENT_TYPE_EPISODES
                            })
                    self.add_items_to_folder(items=items, title=nome_serie)
                elif action == "apri_stagione":
                    id_stagione = params.get("id_stagione")
                    items = utils.call_service(
                        "get_show_content", {
                            "contentId":
                            id_stagione,
                            "contentType":
                            TimVisionAPI.TVSHOW_CONTENT_TYPE_EPISODES
                        })
                    season_no = params.get("seasonNo")
                    self.add_items_to_folder(items=items,
                                             title="Stagione %s" % (season_no))
                elif action == "play_item":
                    content_id = params.get("contentId")
                    video_type = params.get("videoType")
                    has_hd = params.get("has_hd", "false")
                    start_offset = params.get("startPoint")
                    duration = params.get("duration")
                    paused = self.increase_play_video_count()
                    self.play_video(content_id, video_type, has_hd,
                                    start_offset, duration, paused)
                elif action == "open_page":
                    uri = urllib.unquote_plus(params.get("uri")).replace(
                        "maxResults=30",
                        "maxResults=50").replace("&addSeeMore=50", "")
                    items = utils.call_service("get_contents", {"url": uri})
                    items = [x for x in items if x["layout"] != "SEE_MORE"]
                    self.add_items_to_folder(items)
                elif action == "logout":
                    utils.call_service("logout")
                elif action == "play_trailer":
                    content_id = params.get("contentId")
                    content_type = params.get("type")
                    self.play_trailer(content_id, content_type)
                elif action == "set_seen":
                    content_id = params.get("contentId")
                    duration = params.get("duration")
                    utils.call_service("set_content_seen", {
                        "contentId": content_id,
                        "duration": duration
                    })
                    xbmc.executebuiltin("Container.Refresh()")
                elif action == "toogle_favourite":
                    content_id = params.get("contentId")
                    value = utils.get_bool(params.get("value"))
                    mediatype = params.get("mediatype")
                    response = utils.call_service(
                        "set_favourite", {
                            "contentId": content_id,
                            "value": value,
                            "mediatype": mediatype
                        })
                    if response:
                        dialog_title = utils.get_local_string(30033)
                        dialog_msg = utils.get_local_string(
                            30034) if value else utils.get_local_string(30035)
                        Dialogs.show_message(dialog_msg, dialog_title,
                                             xbmcgui.NOTIFICATION_INFO)
                        xbmc.executebuiltin("Container.Refresh()")
                    else:
                        dialog_title = utils.get_local_string(30038)
                        dialog_msg = utils.get_local_string(30039)
                        Dialogs.show_dialog(dialog_msg, dialog_title)
                elif action == "search":
                    keyword = Dialogs.get_text_input(
                        utils.get_local_string(30032))
                    if keyword != None and len(keyword) > 0:
                        items = utils.call_service("search",
                                                   {"keyword": keyword})
                        return self.add_items_to_folder(items)
                elif action == "favourites":
                    items = utils.call_service("get_favourite")
                    return self.add_items_to_folder(items)
                elif action == "donation":
                    self.open_donation_page()
                elif action == "library":
                    library = TimVisionLibrary.TimVisionLibrary()
                    library.update(force=True)
                elif action == "library_kodi":
                    library = TimVisionLibrary.TimVisionLibrary()
                    library.check_db_integrity()
                    pass
예제 #13
0
 def onPlayBackPaused(self):
     if not self.listen:
         return
     Logger.log_write("Paused ("+self.current_content_id+")", mode=Logger.LOG_PLAYER)
     utils.call_service("pause_content", {"contentId":self.current_content_id, "time":int(self.current_time), "threshold":int(self.threshold)})
     self.is_paused = True