Пример #1
0
def save_to_db(items, url):
    if not items or not url:
        return False
    url2 = clean_url(url)
    koding.reset_db()
    test_spec = {"columns": {"value": "TEXT", "created": "TEXT"}}
    koding.Create_Table(url2, test_spec)
    set_val = base64.b64encode(pickle.dumps(items))
    koding.Add_To_Table(url2, {"value": set_val, "created": time.time()})
    table_name_spec = {
        "columns": {
            "name": "TEXT",
        }
    }
    koding.Create_Table("Table_names", table_name_spec)
    plugin_table_name_spec = {
        "columns": {
            "name": "TEXT",
        }
    }
    koding.Create_Table("Plugin_table_names", plugin_table_name_spec)
    if "PLugin" in url:
        koding.Add_To_Table("Plugin_table_names", {
            "name": url2,
        })
    else:
        koding.Add_To_Table("Table_names", {
            "name": url2,
        })
Пример #2
0
def save_episode_to_db(identifier, season, episode, provider, lang, meta):
    """
    save episode's meta info tp database
    Args:
        identifier: identifier of the item
        season: season number of the episode
        episode: episode number of the episode
        provider: metadata provider to sabe info for
        lang: language to save info for
        meta: metadata
    """
    import time
    import koding

    koding.Remove_From_Table("episode_meta", {
        "identifier": identifier,
        "provider": provider,
        "season": season,
        "episode": episode,
        "lang": lang
    })

    koding.Add_To_Table("episode_meta", {
        "identifier": identifier,
        "provider": provider,
        "season": season,
        "episode": episode,
        "lang": lang,
        "meta": pickle.dumps(meta).replace("\"", "'"),
        "created": time.time()
    })
Пример #3
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
Пример #4
0
def add_search():
    term = str(koding.Keyboard(_("Enter search term")))
    if not term:
        return
    koding.Add_To_Table("search", {"term": term})
    xbmc.executebuiltin("Container.update(%s, replace)" %
                        get_addon_url("do_search", term))
Пример #5
0
 def onPlayBackStopped(self):
     koding.dolog("playback stopped")
     if self.identifier == "0":
         return
     if not self.currentTime > 1:
         return
     koding.Create_Table("watched", self.tablespec)
     try:
         koding.Remove_From_Table(
             "watched", {
                 "identifier": self.identifier,
                 "season": self.season,
                 "episode": self.episode
             })
     except:
         pass
     koding.Add_To_Table(
         "watched", {
             "identifier": self.identifier,
             "season": self.season,
             "episode": self.episode,
             "watched": "0",
             "currentTime": self.currentTime
         })
     return True
Пример #6
0
def CreateSession(apikey):
    Auth, SessionId, StatusMessageSession = BYBAPI.tmdb_session(apikey)
    columns = {
        "columns": {
            "auth": "TEXT",
            "sessionid": "TEXT",
            "statusmessage": "TEXT",
            "sessiontime": "TEXT"
        }
    }
    koding.Create_Table(table, columns)
    if Auth == False:
        BYB.Notify(title=str(addon_name),
                   message='Failed to create session\nBecause ' +
                   str(StatusMessageSession) +
                   '\nPlease check settings if using own API Key')
    else:
        add = {
            "auth": Auth,
            "sessionid": SessionId,
            "statusmessage": StatusMessageSession,
            "sessiontime": DateTimeNow
        }
        koding.Add_To_Table(table, add)
    return Auth, SessionId, StatusMessageSession
Пример #7
0
def save_to_db(identifier, provider, lang, meta):
    """
    save item's meta info tp database
    Args:
        identifier: identifier of the item
        provider: metadata provider to sabe info for
        lang: language to save info for
        meta: metadata
    """
    import time
    import koding

    koding.Remove_From_Table("meta", {
        "identifier": identifier,
        "provider": provider,
        "lang": lang
    })
    koding.Add_To_Table(
        "meta", {
            "identifier": identifier,
            "provider": provider,
            "lang": lang,
            "meta": pickle.dumps(meta).replace("\"", "'"),
            "created": time.time()
        })
Пример #8
0
def save_to_db(item, url):
    koding.reset_db()
    koding.Remove_From_Table("trakt_plugin", {"url": url})

    koding.Add_To_Table("trakt_plugin", {
        "url": url,
        "item": pickle.dumps(item).replace("\"", "'"),
        "created": time.time()
    })
Пример #9
0
def fetch_episode_from_db(identifier, season, episode, provider, lang):
    """
    get episode's meta info from database
    Args:
        identifier: identifier of the item
        season: season number of the episode
        episode: episode number of the episode
        provider: metadata provider to fetch info for
        lang: language to fetch info for
    Returns:
        item's metadata
    """
    import koding

    versionspec = {"columns": {"version": "TEXT"}}
    koding.Create_Table("version", versionspec)
    if not koding.Get_All_From_Table("version"):
        koding.Add_To_Table("version", {"version": "0.0.1"})

    episode_meta_spec = {
        "columns": {
            "identifier": "TEXT",
            "season": "TEXT",
            "episode": "TEXT",
            "provider": "TEXT",
            "lang": "TEXT",
            "meta": "TEXT",
            "created": "TEXT"
        },
        "constraints": {
            "unique": "identifier, provider, lang",
        }
    }
    koding.Create_Table("episode_meta", episode_meta_spec)
    match = koding.Get_From_Table(
        "episode_meta", {
            "identifier": identifier,
            "provider": provider,
            "season": season,
            "episode": episode,
            "lang": lang
        })
    if match:
        match = match[0]
        if not match["meta"]:
            return None, match["created"]
        match_meta = match["meta"].replace("'", "\"")
        try:
            match_meta = match_meta.encode('ascii', 'ignore')
        except:
            match_meta = match_meta.decode('utf-8').encode('ascii', 'ignore')
        return pickle.loads(match_meta), match["created"]
    else:
        return [], None
Пример #10
0
def save_to_db(item, url):
    if not item or not url:
        return False
    item = remove_non_ascii(item)
    koding.reset_db()
    koding.Remove_From_Table("trakt_plugin", {"url": url})

    koding.Add_To_Table("trakt_plugin", {
        "url": url,
        "item": pickle.dumps(item).replace("\"", "'"),
        "created": time.time()
    })
Пример #11
0
def save_to_db(item, url):
    if not item or not url:
        return False
    koding.reset_db()
    koding.Remove_From_Table("tmdb_plugin", {"url": url})

    koding.Add_To_Table(
        "tmdb_plugin", {
            "url": url,
            "item": base64.b64encode(pickle.dumps(item)),
            "created": time.time()
        })
Пример #12
0
def save_view_mode(content):
    viewid = get_view_id()
    skin = xbmc.getSkinDir()
    koding.Create_Table("addonviews", view_spec)
    koding.Remove_From_Table("addonviews", {"skin": skin, "content": content})
    koding.Add_To_Table("addonviews", {
        "skin": skin,
        "content": content,
        "viewid": viewid,
    })
    icon = xbmcaddon.Addon().getAddonInfo('icon')
    xbmcgui.Dialog().notification(xbmcaddon.Addon().getAddonInfo('name'),
                                  "View set for %s" % content, icon)
Пример #13
0
def save_to_db(item, url):
    if not item or not url:
        return False
    try:
        koding.reset_db()
        koding.Remove_From_Table("toonova_com_plugin", {"url": url})

        koding.Add_To_Table("toonova_com_plugin", {
            "url": url,
            "item": base64.b64encode(item),
            "created": time.time()
        })
    except:
        return False
Пример #14
0
def save_to_db(item, url):
    if not item or not url:
        return False
    if type(item) == tuple:
        content_type = item[1]
        item = item[0]
    else:
        content_type = None
    item = remove_non_ascii(item)
    koding.reset_db()
    koding.Remove_From_Table("trakt_plugin", {"url": url})

    koding.Add_To_Table("trakt_plugin", {
        "url": url,
        "item": base64.b64encode(pickle.dumps(item)),
        "content_type": content_type,
        "created": time.time()
    })
Пример #15
0
def add_search():
    term = str(koding.Keyboard("Enter search term"))
    if not term:
        return
    koding.Add_To_Table("search", {"term": term})
    do_search(term)
Пример #16
0
                    except Exception as e:
                        koding.dolog("cache error: " + repr(e))
                        return pickle.loads(match["xml"])
            else:
                koding.dolog("initial load")
                response = requests.get(url, verify=False)
                xml = response.content
                response.close()
        if not xml:
            xbmcgui.Dialog().notification(ADDON.getAddonInfo("name"),
                                          "Server under high load, try again")
            return ""
        info = JenItem(xml.split('<item>')[0].split('<dir>')[0])
        cache_time = int(info.get("cache", 21600))
        koding.dolog("cache_time: " + repr(cache_time))
        created_time = time.mktime(time.gmtime())
        try:
            koding.Remove_From_Table("xml_cache", {
                "url": url,
            })
        except Exception, e:
            koding.dolog("Database error: " + repr(e))
        koding.Add_To_Table(
            "xml_cache", {
                "url": url,
                "xml": pickle.dumps(xml).replace("\"", "'"),
                "cache_time": cache_time,
                "created": created_time
            })
        return xml
Пример #17
0
# -*- coding: utf-8 -*-