Пример #1
0
def get_xml(link):
    import time
    xml_cache_spec = {
        "columns": {
            "xml": "TEXT",
            "link": "TEXT",
            "created": "TEXT",
            "changed": "TEXT"
        },
        "constraints": {
            "unique": "link"
        }
    }
    koding.Create_Table("xml_cache", xml_cache_spec)

    url = replace_url(link)
    req = requests.get(url, verify=False)
    changed = req.headers["Last-Modified"]
    result = koding.Get_From_Table("xml_cache", {"link": link})
    if result:
        if result[0]["changed"] == changed:
            return result[0]["xml"]
        else:
            koding.Remove_From_Table("xml_cache", {"link": link})
    xml = req.content
    koding.Add_To_Table("xml_cache", {
        "xml": xml,
        "link": link,
        "created": time.time(),
        "changed": changed
    })
    return xml
Пример #2
0
def get_xml(link):
    import time
    xml_cache_spec = {
        "columns":
        {
            "xml": "TEXT",
            "link": "TEXT",
            "created": "TEXT",
            "changed": "TEXT"
        },
        "constraints":
        {
            "unique": "link"
        }
    }
    koding.Create_Table("xml_cache", xml_cache_spec)

    url = replace_url(link)
    req = requests.get(url)
    changed = req.headers["Last-Modified"]
    result = koding.Get_From_Table("xml_cache", {"link": link})
    if result:
        if result[0]["changed"] == changed:
            return result[0]["xml"]
        else:
            koding.Remove_From_Table("xml_cache", {"link": link})
    xml = req.content
    koding.Add_To_Table("xml_cache", {"xml": xml, "link": link,
                                      "created": time.time(),
                                      "changed": changed})
    return xml
Пример #3
0
    def __init__(self, url, cached=True):
        if cached:
            xml = run_hook("get_xml", url)
        else:
            xml = run_hook("get_xml_uncached", url)
        if not xml:
            if url.endswith(".xml") or url.startswith("http"):
                try:
                    xml = requests.get(url).content
                except Exception as e:
                    xml = None
                    koding.dolog("error: " + repr(e))
                    koding.dolog("url: " + repr(url))
                    koding.dolog("#####################")
            else:
                xml = url
        if xml:
            self.xml = xml
            self.content = ""

            self.list = JenList.list_pattern.findall(xml)
            info = JenItem(xml.split('<item>')[0].split('<dir>')[0])
            intro = info.get("intro", "")
            if intro:
                import resources.lib.sources as sources
                sources.get_sources(intro)
            self.playlister = info.get('poster', '0')
            self.list_image = replace_url(info.get("animated_thumbnail", ""))
            if not self.list_image:
                self.list_image = replace_url(
                    info.get('thumbnail', ADDON.getAddonInfo('icon')))
            self.list_fanart = replace_url(info.get("animated_fanart", ""))
            if not self.list_fanart:
                self.list_fanart = replace_url(info.get('fanart', "0"))
            if self.list_fanart == "0":
                theme = xbmcaddon.Addon().getSetting('theme')
                if theme and theme != 'DEFAULT' and theme != 'none':
                    self.list_fanart = self.set_theme(theme)
                else:
                    self.list_fanart = xbmcaddon.Addon().getAddonInfo('fanart')
            self.metadata = {}
        else:
            self.list = []
Пример #4
0
 def __init__(self, url, cached=True):
     if cached:
         xml = run_hook("get_xml", url)
     else:
         xml = run_hook("get_xml_uncached", url)
     if not xml:
         if url.endswith(".xml") or url.startswith("http"):
             try:
                 xml = requests.get(url).content
             except Exception as e:
                 xml = None
                 koding.dolog("error: " + repr(e))
                 koding.dolog("url: " + repr(url))
                 koding.dolog("#####################")
         else:
             xml = url
     if xml:
         self.xml = xml
         self.content = ""
         self.list = JenList.list_pattern.findall(xml)
         info = JenItem(xml.split('<item>')[0].split('<dir>')[0])
         intro = info.get("intro", "")
         if intro:
             import resources.lib.sources as sources
             sources.get_sources(intro)
         self.playlister = info.get('poster', '0')
         self.list_image = replace_url(info.get("animated_thumbnail", ""))
         if not self.list_image:
             self.list_image = replace_url(
                 info.get('thumbnail', ADDON.getAddonInfo('icon')))
         self.list_fanart = replace_url(info.get("animated_fanart", ""))
         if not self.list_fanart:
             self.list_fanart = replace_url(info.get('fanart', "0"))
         if self.list_fanart == "0":
             theme = xbmcaddon.Addon().getSetting('theme')
             if theme and theme != 'DEFAULT' and theme != 'none':
                 self.list_fanart = self.set_theme(theme)
             else:
                 self.list_fanart = xbmcaddon.Addon().getAddonInfo('fanart')
         self.metadata = {}
     else:
         self.list = []
Пример #5
0
 def __init__(self, url):
     if url.endswith(".xml"):
         request = urllib2.Request(replace_url(url))
         response = urllib2.urlopen(request)
         xml = response.read()
         response.close()
     else:
         xml = url
     if xml:
         self.xml = xml
         self.content = ""
         self.list = JenList.list_pattern.findall(xml)
         info = JenItem(xml.split('<item>')[0].split('<dir>')[0])
         self.playlister = info.get('poster', '0')
         self.list_image = replace_url(
             info.get('thumbnail', ADDON.getAddonInfo('icon')))
         self.list_fanart = replace_url(info.get('fanart', "0"))
         if self.list_fanart == "0":
             self.list_fanart = xbmcaddon.Addon().getAddonInfo('fanart')
         self.metadata = {}
     else:
         self.list = []
Пример #6
0
 def process_item(self, item_xml):
     if "<podcast>" in item_xml:
         item = JenItem(item_xml)
         result_item = {
             'label': item["title"],
             'icon': replace_url(item.get("thumbnail", addon_icon)),
             'fanart': replace_url(item.get("fanart", addon_fanart)),
             'mode': "podcast",
             'url': item.get("podcast", ""),
             'folder': True,
             'imdb': "0",
             'content': "files",
             'season': "0",
             'episode': "0",
             'info': {},
             'year': "0",
             'context': get_context_items(item),
             "summary": item.get("summary", None)
         }
         result_item["properties"] = {'fanart_image': result_item["fanart"]}
         result_item['fanart_small'] = result_item["fanart"]
         return result_item
Пример #7
0
    def set_theme(theme):
        """set jen theme"""
        import random
        theme_list = run_hook("get_theme_list")

        if theme.lower() == "user":
            user_theme_folder = os.path.join(
                xbmc.translatePath(
                    xbmcaddon.Addon().getSetting("cache_folder")), "theme")
            if os.path.isdir(user_theme_folder):
                user_files = []
                for ufile in os.listdir(user_theme_folder):
                    if os.path.isfile(os.path.join(user_theme_folder, ufile)):
                        user_files.append(
                            os.path.join(user_theme_folder, ufile))
                theme_list["user"] = user_files
            else:
                koding.dolog("huh?: " + repr(theme))
                return xbmcaddon.Addon().getAddonInfo('fanart')
        return replace_url(random.choice(theme_list[theme.lower()]))
Пример #8
0
    def set_theme(theme):
        """set jen theme"""
        import random
        theme_list = run_hook("get_theme_list")

        if theme.lower() == "user":
            user_theme_folder = os.path.join(
                xbmc.translatePath(
                    xbmcaddon.Addon().getSetting("cache_folder")),
                "theme")
            if os.path.isdir(user_theme_folder):
                user_files = []
                for ufile in os.listdir(user_theme_folder):
                    if os.path.isfile(os.path.join(user_theme_folder, ufile)):
                        user_files.append(
                            os.path.join(user_theme_folder, ufile))
                theme_list["user"] = user_files
            else:
                koding.dolog("huh?: " + repr(theme))
                return xbmcaddon.Addon().getAddonInfo('fanart')
        return replace_url(random.choice(theme_list[theme.lower()]))
Пример #9
0
    def process_item(self, item_xml):
        try:
            is_widget = __builtin__.JEN_WIDGET
        except:
            is_widget = False
        item = JenItem(item_xml)
        enable_gifs = xbmcaddon.Addon().getSetting('enable_gifs') == "true"
        if item.item_string.startswith("<item>"):
            title = item["title"]
            if title == "":
                title = item["name"]
            try:
                title = xbmcaddon.Addon().getLocalizedString(int(title))
            except ValueError:
                pass
            is_playable = True
            mode = "get_sources"
            link = item_xml
        elif item.item_string.startswith("<dir>"):
            title = item["name"]
            if title == "":
                title = item["title"]
            try:
                title = xbmcaddon.Addon().getLocalizedString(int(title))
            except ValueError:
                pass

            if item["link"].startswith("message"):
                is_playable = True
                mode = "message"
                link = item["link"].replace("message(", "")[:-1]
                if link.startswith("http"):
                    text = koding.Open_URL(replace_url(link))
                    link = text
            else:
                is_playable = False
                mode = "get_list"
                link = item["link"]
        elif item.item_string.startswith("<plugin>"):
            link = item["link"]
            title = item["name"]
            if title == "":
                title = item["title"]
            try:
                title = xbmcaddon.Addon().getLocalizedString(int(title))
            except ValueError:
                pass
            if link.endswith("openSettings"):
                is_playable = True
                link = ""
                mode = "Settings"
            elif link.endswith("developer"):
                is_playable = False
                link = '{"file_name":"testings.xml"}'
                mode = "Testings"
                path = xbmcaddon.Addon().getAddonInfo('profile')
                profile_path = xbmc.translatePath(path).decode('utf-8')
                test_file = os.path.join(profile_path, "testings.xml")
                if not os.path.exists(test_file):
                    return
            else:
                if "youtube" in link and ("user" in link
                                          or "playlist" in link):
                    is_playable = True
                    mode = 'get_sources'
                    link = item_xml
                else:
                    is_playable = True
                    mode = 'get_sources'
                    link = item_xml
        else:
            xbmc.log("other: " + repr(item), xbmc.LOGDEBUG)
            raise Exception()

        # filter out "unreleased"
        if title == "" or " /title" in title or "/ title" in title:
            return

        if is_widget:
            if mode == "message":
                return

        context = get_context_items(item)

        content = item["content"]
        if content == "boxset":
            content = "set"
        if content != '':
            self.content = content
        imdb = item["imdb"]
        season = item["season"] or '0'
        episode = item["episode"] or '0'
        year = item["year"] or '0'
        fanart = None
        if enable_gifs:
            fan_url = item.get("animated_fanart", "")
            if fan_url and fan_url != "0":
                fanart = replace_url(fan_url)
        if not fanart:
            fanart = replace_url(item.get("fanart", self.list_fanart),
                                 replace_gif=False)
        thumbnail = None
        if enable_gifs:
            thumb_url = item.get("animated_thumbnail", "")
            if thumb_url and thumb_url != "0":
                thumbnail = replace_url(thumb_url)
        if not thumbnail:
            thumbnail = replace_url(item.get("thumbnail", self.list_image),
                                    replace_gif=False)

        premiered = item.get("premiered", "")
        if premiered:
            try:
                today_tt = datetime.date.today().timetuple()
                premiered_tt = time.strptime(premiered, "%Y-%m-%d")
                if today_tt < premiered_tt:
                    title = "[COLORyellow]" + title + "[/COLOR]"
            except:
                xbmc.log("wrong premiered format")
                pass
        result_item = {
            'label': title,
            'icon': thumbnail,
            'fanart': fanart,
            'mode': mode,
            'url': link,
            'folder': not is_playable,
            'imdb': imdb,
            'content': content,
            'season': season,
            'episode': episode,
            'info': {},
            'year': year,
            'context': context
        }
        if fanart:
            result_item["properties"] = {'fanart_image': fanart}
            result_item['fanart_small'] = fanart

        if content in ['movie', 'episode']:
            # only add watched data for applicable items
            result_item['info']['watched'] = 0
        return result_item
Пример #10
0
# -*- coding: utf-8 -*-
Пример #11
0
# -*- coding: utf-8 -*-
Пример #12
0
    def process_item(self, item_xml):
        hook_result = run_hook("process_item", item_xml)
        if hook_result:
            if hook_result.get("content", ""):
                self.content = hook_result["content"]
            return hook_result
        try:
            is_widget = __builtin__.JEN_WIDGET
        except:
            is_widget = False
        item = JenItem(item_xml)
        enable_gifs = xbmcaddon.Addon().getSetting('enable_gifs') == "true"
        if item.item_string.startswith("<item>"):
            title = item["title"]
            if title == "":
                title = item["name"]
                koding.dolog("depricated: <name>")
                koding.dolog("name: " + repr(title))
                koding.dolog("Use <title> instead of <name> in your xml")
                koding.dolog("#####################")
            try:
                title = xbmcaddon.Addon().getLocalizedString(int(title))
            except ValueError:
                pass
            is_playable = True
            mode = "get_sources"
            link = item_xml
        elif item.item_string.startswith("<dir>"):
            title = item["name"]
            if title == "":
                title = item["title"]
            try:
                title = xbmcaddon.Addon().getLocalizedString(int(title))
            except ValueError:
                pass
            if item["link"].startswith("message"):
                is_playable = True
                mode = "message"
                link = item["link"].replace("message(", "")[:-1]
                if link.startswith("http"):
                    text = requests.request("GET", replace_url(link), verify=False).content
                    link = text
            else:
                is_playable = False
                mode = "get_list"
                link = item["link"]
        elif item.item_string.startswith("<plugin>"):
            link = item["link"]
            title = item["name"]
            if title == "":
                title = item["title"]
            try:
                title = xbmcaddon.Addon().getLocalizedString(int(title))
            except ValueError:
                pass
            if link.endswith("openSettings"):
                is_playable = True
                link = ""
                mode = "Settings"
            elif link.endswith("developer"):
                import os
                is_playable = False
                link = '{"file_name":"testings.xml"}'
                mode = "Testings"
                path = xbmcaddon.Addon().getAddonInfo('profile')
                profile_path = xbmc.translatePath(path).decode('utf-8')
                test_file = os.path.join(profile_path, "testings.xml")
                if not os.path.exists(test_file):
                    return
            elif link.endswith("search"):
                is_playable = False
                link = ""
                mode = "Search"
            else:
                if "youtube" in link and ("user" in link or "playlist" in link):
                    is_playable = True
                    mode = 'get_sources'
                    link = item_xml
                else:
                    is_playable = True
                    mode = 'get_sources'
                    link = item_xml
        else:
            koding.dolog("other: " + repr(item), xbmc.LOGDEBUG)
            raise Exception()

        # filter out "unreleased"
        if title == "" or " /title" in title or "/ title" in title:
            return

        if is_widget:
            if mode == "message":
                return

        context = get_context_items(item)

        content = item["content"]
        if content == "boxset":
            content = "set"
        if content != '':
            self.content = content
        imdb = item["imdb"]
        season = item["season"] or '0'
        episode = item["episode"] or '0'
        year = item["year"] or '0'
        fanart = None
        if enable_gifs:
            fan_url = item.get("animated_fanart", "")
            if fan_url and fan_url != "0":
                fanart = replace_url(fan_url)
        if not fanart:
            fanart = replace_url(
                item.get("fanart", self.list_fanart), replace_gif=False)
        thumbnail = None
        if enable_gifs:
            thumb_url = item.get("animated_thumbnail", "")
            if thumb_url and thumb_url != "0":
                thumbnail = replace_url(thumb_url)
        if not thumbnail:
            thumbnail = replace_url(
                item.get("thumbnail", self.list_image), replace_gif=False)

        premiered = item.get("premiered", "")
        if premiered:
            try:
                today_tt = datetime.date.today().timetuple()
                premiered_tt = time.strptime(premiered, "%Y-%m-%d")
                if today_tt < premiered_tt:
                    title = "[COLORyellow]" + title + "[/COLOR]"
            except:
                koding.dolog("wrong premiered format")
                pass
        result_item = {
            'label': title,
            'icon': thumbnail,
            'fanart': fanart,
            'mode': mode,
            'url': link,
            'folder': not is_playable,
            'imdb': imdb,
            'content': content,
            'season': season,
            'episode': episode,
            'info': {},
            'year': year,
            'context': context,
            'plot': item.get("summary", None),
            "summary": item.get("summary", None)
        }
        if fanart:
            result_item["properties"] = {'fanart_image': fanart}
            result_item['fanart_small'] = fanart

        if content in ['movie', 'episode']:
            # only add watched data for applicable items
            result_item['info']['watched'] = 0
        return result_item
Пример #13
0
    def process_item(self, item_xml):
        item = JenItem(item_xml)
        enable_gifs = xbmcaddon.Addon().getSetting('enable_gifs') == "true"
        if item.item_string.startswith("<dir>"):
            title = item["name"]
            if title == "":
                title = item["title"]
            try:
                title = xbmcaddon.Addon().getLocalizedString(int(title))
            except ValueError:
                pass
            if item["link"] == "sport_acesoplisting":
                mode = "sport_acesoplisting"
                is_playable = False
                link = ""
            elif "sport_nhl_games" in item["link"]:
                game_date = item["link"].replace("sport_nhl_games(", "")[:-1]
                if "sport" in game_date:
                    game_date = ""
                mode = "sport_nhl_games"
                is_playable = False
                link = game_date + "a"
            elif "nhl_home_away(" in item["link"]:
                fargs = item["link"].replace("nhl_home_away(",
                                             "")[:-1].split(",")
                mode = "nhl_home_away"
                link = ",".join(fargs)
                is_playable = False
            elif item["link"].startswith("sport_hockeyrecaps"):
                page = item["link"].strip()[18:]
                if page == "":
                    page = "1a"
                mode = "get_hockey_recaps"
                is_playable = False
                link = page
            elif "sport_nfl_games" in item["link"]:
                fargs = item["link"].replace("sport_nfl_games(", "")[:-1]
                if "sport" in fargs:
                    fargs = ""
                else:
                    fargs = fargs.split(",")
                    if len(fargs) != 2:
                        fargs = ""
                mode = "sport_nfl_games"
                is_playable = False
                link = fargs
            elif "sport_nfl_get_game(" in item["link"]:
                farg = item["link"].replace("sport_nfl_get_game(", "")[:-1]
                mode = "get_nfl_game"
                link = farg
            elif "sport_condensed_nfl_games" in item["link"]:
                fargs = item["link"].replace("sport_condensed_nfl_games(",
                                             "")[:-1]
                if "sport" in fargs:
                    fargs = ""
                else:
                    fargs = fargs.split(",")
                    if len(fargs) != 2:
                        fargs = ""
                mode = "sport_condensed_nfl_games"
                is_playable = False
                link = fargs
            elif "sport_condensed_nfl_get_game(" in item["link"]:
                farg = item["link"].replace("sport_condensed_nfl_get_game(",
                                            "")[:-1]
                mode = "sport_condensed_nfl_get_game"
                is_playable = False
                link = farg

            # filter out "unreleased"
            if title == "" or " /title" in title or "/ title" in title:
                return

            context = get_context_items(item)

            content = item["content"]
            if content == "boxset":
                content = "set"
            if content != '':
                self.content = content
            imdb = item["imdb"]
            season = item["season"] or '0'
            episode = item["episode"] or '0'
            year = item["year"] or '0'
            fanart = None
            if enable_gifs:
                fan_url = item.get("animated_fanart", "")
                if fan_url and fan_url != "0":
                    fanart = replace_url(fan_url)
            if not fanart:
                fanart = replace_url(item.get("fanart", ""), replace_gif=False)
            thumbnail = None
            if enable_gifs:
                thumb_url = item.get("animated_thumbnail", "")
                if thumb_url and thumb_url != "0":
                    thumbnail = replace_url(thumb_url)
            if not thumbnail:
                thumbnail = replace_url(item.get("thumbnail", ""),
                                        replace_gif=False)

            premiered = item.get("premiered", "")
            if premiered:
                try:
                    today_tt = datetime.date.today().timetuple()
                    premiered_tt = time.strptime(premiered, "%Y-%m-%d")
                    if today_tt < premiered_tt:
                        title = "[COLORyellow]" + title + "[/COLOR]"
                except Exception, e:
                    koding.dolog("wrong premiered format: " + repr(e))
                    pass
            try:
                result_item = {
                    'label': title,
                    'icon': thumbnail,
                    'fanart': fanart,
                    'mode': mode,
                    'url': link,
                    'folder': not is_playable,
                    'imdb': imdb,
                    'content': content,
                    'season': season,
                    'episode': episode,
                    'info': {},
                    'year': year,
                    'context': context,
                    "summary": item.get("summary", None)
                }
            except:
                return
            if fanart:
                result_item["properties"] = {'fanart_image': fanart}
                result_item['fanart_small'] = fanart

            if content in ['movie', 'episode']:
                # only add watched data for applicable items
                result_item['info']['watched'] = 0
            return result_item
Пример #14
0
# -*- coding: utf-8 -*-
Пример #15
0
# -*- coding: utf-8 -*-