Esempio n. 1
0
def search(search_str="", hd="", orderby="relevance", limit=40, extended=True, page="", filters=None, media_type="video"):
    """
    returns ItemList according to search term, filters etc.
    """
    params = {"part": "id,snippet",
              "maxResults": limit,
              "type": media_type,
              "order": orderby,
              "pageToken": page,
              "hd": str(hd and not hd == "false"),
              "q": search_str.replace('"', '')}
    results = get_data(method="search",
                       params=utils.merge_dicts(params, filters if filters else {}))
    if not results:
        return None
    if media_type == "video":
        listitems = handle_videos(results["items"], extended=extended)
    elif media_type == "playlist":
        listitems = handle_playlists(results["items"])
    elif media_type == "channel":
        listitems = handle_channels(results["items"])
    listitems.total_pages = results["pageInfo"]["resultsPerPage"]
    listitems.totals = results["pageInfo"]["totalResults"]
    listitems.next_page_token = results.get("nextPageToken", "")
    listitems.prev_page_token = results.get("prevPageToken", "")
    return listitems
Esempio n. 2
0
 def to_windowprops(self, prefix="", window_id=10000):
     window = xbmcgui.Window(window_id)
     window.setProperty('%slabel' % (prefix), self.label)
     window.setProperty('%slabel2' % (prefix), self.label2)
     window.setProperty('%spath' % (prefix), self.path)
     dct = utils.merge_dicts(self.get_properties(), self.get_artwork(),
                             self.get_infos())
     for k, v in dct.iteritems():
         window.setProperty('%s%s' % (prefix, k), unicode(v))
Esempio n. 3
0
 def to_windowprops(self, prefix="", window_id=10000):
     window = xbmcgui.Window(window_id)
     window.setProperty('%slabel' % (prefix), self.label)
     window.setProperty('%slabel2' % (prefix), self.label2)
     window.setProperty('%spath' % (prefix), self.path)
     dct = utils.merge_dicts(self.get_properties(),
                             self.get_artwork(),
                             self.get_infos())
     for k, v in dct.iteritems():
         window.setProperty('%s%s' % (prefix, k), unicode(v))
Esempio n. 4
0
        def fetch_data(self, force=False):  # TODO: rewrite
            sort_by = self.sort + "." + self.order
            temp = "tv" if self.type == "tv" else "movies"
            if self.mode == "search":
                self.filter_label = addon.LANG(
                    32146) % self.search_str if self.search_str else ""
                return tmdb.multi_search(search_str=self.search_str,
                                         page=self.page,
                                         cache_days=0 if force else 2)
            elif self.mode == "list":
                xbmc.log("fetching list of movies...........", 2)
                return tmdb.get_list_movies(list_id=self.list_id, force=force)
            elif self.mode == "favorites":
                self.filter_label = addon.LANG(
                    32144) if self.type == "tv" else addon.LANG(32134)
                return tmdb.get_fav_items(media_type=temp,
                                          sort_by=sort_by,
                                          page=self.page)
            elif self.mode == "rating":
                self.filter_label = addon.LANG(
                    32145) if self.type == "tv" else addon.LANG(32135)
                return tmdb.get_rated_media_items(media_type=temp,
                                                  sort_by=sort_by,
                                                  page=self.page,
                                                  cache_days=0)
            else:
                self.set_filter_label()
                params = {
                    "sort_by": sort_by,
                    "language": addon.setting("LanguageID"),
                    "page": self.page,
                    "include_adult": include_adult
                }
                filters = {item["type"]: item["id"] for item in self.filters}
                response = tmdb.get_data(url="discover/%s" % (self.type),
                                         params=utils.merge_dicts(
                                             params, filters),
                                         cache_days=0 if force else 2)

                if not response["results"]:
                    utils.notify(addon.LANG(284))
                    return None
                if self.type == "movie":
                    itemlist = tmdb.handle_movies(results=response["results"],
                                                  local_first=False,
                                                  sortkey=None)
                else:
                    itemlist = tmdb.handle_tvshows(results=response["results"],
                                                   local_first=False,
                                                   sortkey=None)
                itemlist.set_totals(response["total_results"])
                itemlist.set_total_pages(response["total_pages"])
                return itemlist
        def fetch_data(self, force=False):  # TODO: rewrite
            sort_by = self.sort + "." + self.order
            temp = "tv" if self.type == "tv" else "movies"
            if self.mode == "search":
                self.filter_label = addon.LANG(32146) % self.search_str if self.search_str else ""
                return tmdb.multi_search(search_str=self.search_str,
                                         page=self.page,
                                         cache_days=0 if force else 2)
            elif self.mode == "list":
                return tmdb.get_list_movies(list_id=self.list_id,
                                            force=force)
            elif self.mode == "favorites":
                self.filter_label = addon.LANG(32144) if self.type == "tv" else addon.LANG(32134)
                return tmdb.get_fav_items(media_type=temp,
                                          sort_by=sort_by,
                                          page=self.page)
            elif self.mode == "rating":
                self.filter_label = addon.LANG(32145) if self.type == "tv" else addon.LANG(32135)
                return tmdb.get_rated_media_items(media_type=temp,
                                                  sort_by=sort_by,
                                                  page=self.page,
                                                  cache_days=0)
            else:
                self.set_filter_label()
                params = {"sort_by": sort_by,
                          "language": addon.setting("LanguageID"),
                          "page": self.page,
                          "include_adult": include_adult}
                filters = {item["type"]: item["id"] for item in self.filters}
                response = tmdb.get_data(url="discover/%s" % (self.type),
                                         params=utils.merge_dicts(params, filters),
                                         cache_days=0 if force else 2)

                if not response["results"]:
                    utils.notify(addon.LANG(284))
                    return None
                if self.type == "movie":
                    itemlist = tmdb.handle_movies(results=response["results"],
                                                  local_first=False,
                                                  sortkey=None)
                else:
                    itemlist = tmdb.handle_tvshows(results=response["results"],
                                                   local_first=False,
                                                   sortkey=None)
                itemlist.set_totals(response["total_results"])
                itemlist.set_total_pages(response["total_pages"])
                return itemlist
def explore(search_str="", hd="", orderby="recent", limit=40, extended=True, page="", filters=None, media_type="video"):
    params = {"page": page,
              "fields": ",".join(video_infos),
              "limit": limit,
              "sort": orderby,
              "search": search_str}
    params = utils.merge_dicts(params, filters if filters else {})
    params = {k: v for k, v in params.iteritems() if v}
    params = ["%s=%s" % (k, v) for k, v in params.iteritems()]
    params = "&".join(params)
    videos = d.get("/videos?%s" % (params))
    utils.pp(videos)
    listitems = handle_videos(videos["list"])
    totals = videos.get("total", len(listitems))
    listitems.set_totals(totals)
    listitems.set_total_pages(totals / limit)
    return listitems
Esempio n. 7
0
def search(search_str="",
           hd="",
           orderby="relevance",
           limit=40,
           extended=True,
           page="",
           filters=None,
           media_type="video"):
    """
    returns ItemList according to search term, filters etc.
    """
    params = {
        "part": "id,snippet",
        "maxResults": limit,
        "type": media_type,
        "order": orderby,
        "pageToken": page,
        "hd": str(hd and not hd == "false"),
        "q": search_str.replace('"', '')
    }
    results = get_data(method="search",
                       params=utils.merge_dicts(params,
                                                filters if filters else {}))
    if not results:
        return None
    if "error" in results:
        utils.pp(results)
        return None
    if media_type == "video":
        listitems = handle_videos(results["items"], extended=extended)
    elif media_type == "playlist":
        listitems = handle_playlists(results["items"])
    elif media_type == "channel":
        listitems = handle_channels(results["items"])
    listitems.total_pages = results["pageInfo"]["resultsPerPage"]
    listitems.totals = results["pageInfo"]["totalResults"]
    listitems.next_page_token = results.get("nextPageToken", "")
    listitems.prev_page_token = results.get("prevPageToken", "")
    return listitems
Esempio n. 8
0
def search(search_str="",
           hd="",
           orderby="relevance",
           limit=40,
           extended=True,
           page="",
           filters=None,
           media_type="video"):
    params = {
        "part": "id,snippet",
        "maxResults": limit,
        "type": media_type,
        "order": orderby,
        "pageToken": page,
        "hd": str(hd and not hd == "false"),
        "q": search_str.replace('"', '')
    }
    params = utils.merge_dicts(params, filters if filters else {})
    results = get_data(method="search", params=params)
    if not results:
        return {}
    if media_type == "video":
        listitems = handle_videos(results["items"], extended=extended)
    elif media_type == "playlist":
        listitems = handle_playlists(results["items"])
    elif media_type == "channel":
        listitems = handle_channels(results["items"])
    if not listitems:
        return {}
    return {
        "listitems": listitems,
        "results_per_page": results["pageInfo"]["resultsPerPage"],
        "total_results": results["pageInfo"]["totalResults"],
        "next_page_token": results.get("nextPageToken", ""),
        "prev_page_token": results.get("prevPageToken", "")
    }
 def fetch_data(self, force=False):  # TODO: rewrite
     sort_by = self.sort + "." + self.order
     temp = "tv" if self.type == "tv" else "movies"
     if self.mode == "search":
         params = {"query": self.search_str,
                   "include_adult": include_adult,
                   "page": self.page}
         url = "search/multi"
         self.filter_label = addon.LANG(32146) % self.search_str if self.search_str else ""
     elif self.mode == "list":
         params = {"language": addon.setting("LanguageID")}
         url = "list/%s" % (self.list_id)
         # self.filter_label = addon.LANG(32036)
     elif self.mode == "favorites":
         params = {"sort_by": sort_by,
                   "language": addon.setting("LanguageID"),
                   "page": self.page,
                   "session_id": tmdb.Login.get_session_id()}
         url = "account/%s/favorite/%s" % (tmdb.Login.get_account_id(), temp)
         self.filter_label = addon.LANG(32144) if self.type == "tv" else addon.LANG(32134)
     elif self.mode == "rating":
         force = True  # workaround, should be updated after setting rating
         if self.logged_in:
             session_id = tmdb.Login.get_session_id()
             if not session_id:
                 utils.notify("Could not get session id")
                 return {"listitems": [],
                         "results_per_page": 0,
                         "total_results": 0}
             params = {"sort_by": sort_by,
                       "language": addon.setting("LanguageID"),
                       "page": self.page,
                       "session_id": session_id}
             url = "account/%s/rated/%s" % (tmdb.Login.get_account_id(), temp)
         else:
             session_id = tmdb.Login.get_guest_session_id()
             if not session_id:
                 utils.notify("Could not get session id")
                 return {"listitems": [],
                         "results_per_page": 0,
                         "total_results": 0}
             params = {"language": addon.setting("LanguageID")}
             url = "guest_session/%s/rated_movies" % (session_id)
         self.filter_label = addon.LANG(32145) if self.type == "tv" else addon.LANG(32135)
     else:
         self.set_filter_label()
         params = {"sort_by": sort_by,
                   "language": addon.setting("LanguageID"),
                   "page": self.page,
                   "include_adult": include_adult}
         filters = {item["type"]: item["id"] for item in self.filters}
         params = utils.merge_dicts(params, filters)
         url = "discover/%s" % (self.type)
     response = tmdb.get_data(url=url,
                              params=params,
                              cache_days=0 if force else 2)
     if not response:
         return None
     if self.mode == "list":
         info = {"listitems": tmdb.handle_movies(results=response["items"],
                                                 local_first=True,
                                                 sortkey=None),
                 "results_per_page": 1,
                 "total_results": len(response["items"])}
         return info
     if "results" not in response:
         # self.close()
         return {"listitems": [],
                 "results_per_page": 0,
                 "total_results": 0}
     if not response["results"]:
         utils.notify(addon.LANG(284))
     if self.mode == "search":
         listitems = tmdb.handle_multi_search(response["results"])
     elif self.type == "movie":
         listitems = tmdb.handle_movies(results=response["results"],
                                        local_first=False,
                                        sortkey=None)
     else:
         listitems = tmdb.handle_tvshows(results=response["results"],
                                         local_first=False,
                                         sortkey=None)
     info = {"listitems": listitems,
             "results_per_page": response["total_pages"],
             "total_results": response["total_results"]}
     return info
 def fetch_data(self, force=False):  # TODO: rewrite
     sort_by = self.sort + "." + self.order
     temp = "tv" if self.type == "tv" else "movies"
     if self.mode == "search":
         params = {
             "query": self.search_str,
             "include_adult": include_adult,
             "page": self.page
         }
         url = "search/multi"
         self.filter_label = addon.LANG(
             32146) % self.search_str if self.search_str else ""
     elif self.mode == "list":
         params = {"language": addon.setting("LanguageID")}
         url = "list/%s" % (self.list_id)
         # self.filter_label = addon.LANG(32036)
     elif self.mode == "favorites":
         params = {
             "sort_by": sort_by,
             "language": addon.setting("LanguageID"),
             "page": self.page,
             "session_id": tmdb.Login.get_session_id()
         }
         url = "account/%s/favorite/%s" % (tmdb.Login.get_account_id(),
                                           temp)
         self.filter_label = addon.LANG(
             32144) if self.type == "tv" else addon.LANG(32134)
     elif self.mode == "rating":
         force = True  # workaround, should be updated after setting rating
         if self.logged_in:
             session_id = tmdb.Login.get_session_id()
             if not session_id:
                 utils.notify("Could not get session id")
                 return {
                     "listitems": [],
                     "results_per_page": 0,
                     "total_results": 0
                 }
             params = {
                 "sort_by": sort_by,
                 "language": addon.setting("LanguageID"),
                 "page": self.page,
                 "session_id": session_id
             }
             url = "account/%s/rated/%s" % (tmdb.Login.get_account_id(),
                                            temp)
         else:
             session_id = tmdb.Login.get_guest_session_id()
             if not session_id:
                 utils.notify("Could not get session id")
                 return {
                     "listitems": [],
                     "results_per_page": 0,
                     "total_results": 0
                 }
             params = {"language": addon.setting("LanguageID")}
             url = "guest_session/%s/rated_movies" % (session_id)
         self.filter_label = addon.LANG(
             32145) if self.type == "tv" else addon.LANG(32135)
     else:
         self.set_filter_label()
         params = {
             "sort_by": sort_by,
             "language": addon.setting("LanguageID"),
             "page": self.page,
             "include_adult": include_adult
         }
         filters = {item["type"]: item["id"] for item in self.filters}
         params = utils.merge_dicts(params, filters)
         url = "discover/%s" % (self.type)
     response = tmdb.get_data(url=url,
                              params=params,
                              cache_days=0 if force else 2)
     if not response:
         return None
     if self.mode == "list":
         info = {
             "listitems":
             tmdb.handle_movies(results=response["items"],
                                local_first=True,
                                sortkey=None),
             "results_per_page":
             1,
             "total_results":
             len(response["items"])
         }
         return info
     if "results" not in response:
         # self.close()
         return {
             "listitems": [],
             "results_per_page": 0,
             "total_results": 0
         }
     if not response["results"]:
         utils.notify(addon.LANG(284))
     if self.mode == "search":
         listitems = tmdb.handle_multi_search(response["results"])
     elif self.type == "movie":
         listitems = tmdb.handle_movies(results=response["results"],
                                        local_first=False,
                                        sortkey=None)
     else:
         listitems = tmdb.handle_tvshows(results=response["results"],
                                         local_first=False,
                                         sortkey=None)
     info = {
         "listitems": listitems,
         "results_per_page": response["total_pages"],
         "total_results": response["total_results"]
     }
     return info