def getTivoNames(): dir = MediaContainer('art-default.jpg', title1="TiVo") myMAC = Prefs.Get("MAC") if myMAC == None: myMAC = "" if (len(myMAC) == 10): p1 = Popen(["mDNS", "-B", "_tivo-videos._tcp", "local"], stdout=PIPE) p2 = Popen(["colrm", "1", "74"], stdin=p1.stdout, stdout=PIPE) p3 = Popen(["grep", "-v", "Instance Name"], stdin=p2.stdout, stdout=PIPE) p4 = Popen(["sort"], stdin=p3.stdout, stdout=PIPE) p5 = Popen(["uniq"], stdin=p4.stdout, stdout=PIPE) sleep(2) kill(p1.pid, SIGTERM) tivolist = p5.communicate()[0] for line in tivolist.split('\n'): curtivo = line.lstrip().rstrip() if len(curtivo) > 0: Log.Add("Adding %s" % curtivo) dir.AppendItem( DirectoryItem( TIVO_PLUGIN_PREFIX + "/" + TIVO_BY_NAME + "/" + curtivo, curtivo, "")) dir.AppendItem( SearchDirectoryItem(TIVO_PLUGIN_PREFIX + "/" + TIVO_PREFS + "/MAC", "Set your Media Access Key", "Set your Media Access Key [" + myMAC + "] ", "")) return dir.ToXML()
def RecentVideos(): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=TEXT_RECENT_VIDEOS) first = True for row in LoadUrl(URL_ALL, CACHE_INT_RECENT).xpath(XPATH_RECENT_VIDEOS): if first: # Need to skip header row (Hey IGN, use a thead like the rest of us!) first = False continue url = row.find("td//a").get("href") name = row.find("td//a").text.strip() # Need to label category icon = row.find("td/img").get( "src") # Again, IGN, how about some alt text? begin = icon.find("icon_") + 5 end = icon.find(".gif") label = icon[begin:end] if label == "video": nameLabeled = name else: nameLabeled = "[" + _L(label) + "] " + name dir.AppendItem(DirectoryItem(_E(url) + "||" + name, nameLabeled, None)) return dir.ToXML()
def VideoSeries(all=False): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=TEXT_VIDEO_SERIES) if all: # From Video Series page for series in LoadUrl( URL_VIDEO_SERIES, CACHE_INT_SERIES_LIST).xpath(XPATH_ALL_VIDEO_SERIES): thumb = series.find("a/img").get("src") title = series.find("a/img").get("alt") url = series.find("a").get("href") dir.AppendItem( DirectoryItem(_E(url) + "||" + _E(title), title, thumb)) else: # From Home page for series in HomePageXml().xpath(XPATH_VIDEO_SERIES): url = series.get("href") name = series.find("img").get("alt") thumb = series.find("img").get("src") dir.AppendItem( DirectoryItem(_E(url) + "||" + _E(name), name, thumb)) dir.AppendItem(DirectoryItem("all", TEXT_ALL_SERIES, None)) return dir.ToXML()
def SimpleHomePagePlaylist(query, title): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=title) for video in HomePageXml().xpath(query): videoPage = video.get("href") thumbUrl = video.find("img").get("src") dir.AppendItem(CreateVideoItemFromPage(videoPage, thumbUrl)) return dir.ToXML()
def populateFromFeed(url, secondTitle=None, firstTitle=None): if not firstTitle: firstTitle = "Channels" dir = MediaContainer('art-default.jpg', None, firstTitle, secondTitle) dir.SetViewGroup("InfoList") if USE_CACHE == True: feed = RSS.Parse(HTTP.GetCached(url, CACHE_INTERVAL)) else: feed = RSS.Parse(url) added = 0 for e in feed["items"]: try: id = e.enclosures[0]["href"] media_type = e.enclosures[0]["type"] if media_type == "application/x-shockwave-flash" or media_type.find( "vmv") > -1 or media_type == "": continue try: description = XML.ElementFromString(e.description, True).text_content() except: description = "" try: thumbnail = e["media_thumbnail"][0]["url"] except: thumbnail = "" try: content_url = e["media_content"][0]["url"] except: content_url = "" duration = "" title = e.title if secondTitle and title.find(secondTitle) == 0: title = title[len(secondTitle) + 1:] videoItem = VideoItem(id, title, description, duration + content_url, thumbnail) # TODO: Set the metadata! # videoItem.SetTelevisonMetadata(1,2,3) dir.AppendItem(videoItem) added = added + 1 Log.Add("Read data for: " + title) except: Log.Add("Skipping item due to an error.") Log.Add("Total Videos: " + str(added)) return dir.ToXML()
def RecentVideosPage(url, title): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=title) for link in LoadUrl(url, CACHE_INT_RECENT).xpath(XPATH_RECENT_VIDEOS_PAGE): url = link.get("href") name = link.find("img").get("alt") thumb = link.find("img").get("src") dir.AppendItem(CreateVideoItemFromPage(url, thumb, "", name)) return dir.ToXML()
def SelectedHit(index, title): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=title) for video in HomePageXml().xpath(XPATH_SELECTED_HIT % index): desc = "" # video.find("p") Why doesn't this return all of the p tags? url = video.find("a").get("href") thumb = video.find("a/img").get("src") title = video.find("h5/a").text dir.AppendItem(CreateVideoItemFromPage(url, thumb, desc, title)) return dir.ToXML()
def Latest(): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=TEXT_LATEST_VIDEOS) for video in HomePageXml().xpath(XPATH_LATEST_VIDEOS): videoPage = video.get("href") # Latest Videos are just a list, no thumbs dir.AppendItem(CreateVideoItemFromPage(videoPage)) return dir.ToXML()
def TopVideos(): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=TEXT_TOP_VIDEOS) for video in HomePageXml().xpath(XPATH_TOP_VIDEOS): videoPage = video.find('div/a').get("href") thumbUrl = video.find('div/a/img').get("src") dir.AppendItem(CreateVideoItemFromPage(videoPage, thumbUrl)) return dir.ToXML()
def HitList(): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=TEXT_HIT_LIST) count = 0 for hit in HomePageXml().xpath(XPATH_HIT_LIST): count = count + 1 dir.AppendItem( DirectoryItem(str(count) + "||" + hit.text, hit.text, None)) return dir.ToXML()
def SelectedVideoSeries(url, title, limit=9999): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN, title2=_D(title)) xml = LoadUrl(url, CACHE_INT_VIDEO_SERIES) for episode in xml.xpath(XPATH_VIDEO_SERIES_EP): limit = limit - 1 if limit < 0: dir.AppendItem( DirectoryItem(_E(url) + "||" + title, TEXT_ALL_EPISODES, None)) break thumb = episode.find("a/img").get("src") desc = episode.find("a/img").get("alt") epUrl = episode.find("a").get("href") dir.AppendItem(CreateVideoItemFromPage(epUrl, thumb, desc)) return dir.ToXML()
def HandleVideosRequest(pathNouns, count): dir = MediaContainer("art-default.png", "", "") if count == 0: dir = Index() elif count > 3: if pathNouns[1] == "parties": if pathNouns[3] == "all_years": dir = GetFeedDirectory("lastreleased&party=" + pathNouns[2]) else: dir = GetFeedDirectory("lastreleased&party=" + pathNouns[2] + "&yearofparty=" + pathNouns[3]) elif count > 2: if pathNouns[1] == "groups": dir = GetFeedDirectory("lastreleased&group=" + pathNouns[2]) elif pathNouns[1] == "parties": dir = GetPartyYears(pathNouns[2]); elif count > 1: Debug("pathNouns, count", pathNouns[0] +"/"+ pathNouns[1] +", "+ str(count)) if pathNouns[1] == "lastadded": dir = GetFeedDirectory("lastadded") elif pathNouns[1] == "lastreleased": dir = GetFeedDirectory("lastreleased") elif pathNouns[1] == "topweek": dir = GetFeedDirectory("topweek") elif pathNouns[1] == "topmonth": dir = GetFeedDirectory("topmonth") elif pathNouns[1] == "alltimetop": dir = GetFeedDirectory("alltimetop") elif pathNouns[1] == "toprating": dir = GetFeedDirectory("alltimetop") elif pathNouns[1] == "groups": dir = GetList("listofgroups") elif pathNouns[1] == "parties": dir = GetList("listofparties") return dir.ToXML()
def Index(): dir = MediaContainer(FILE_DEFAULT_ART, title1=TEXT_IGN) xml = HomePageXml() # "Exclusive" video is not always there exclusiveLinks = xml.xpath('//div[@id="video_exclusive"]//a') if len(exclusiveLinks) > 1: videoPage = exclusiveLinks[1].get("href") thumbUrl = xml.xpath('//div[@id="video_exclusive"]//a[1]/img')[0].get( "src") dir.AppendItem(CreateVideoItemFromPage(videoPage, thumbUrl)) dir.AppendItem(DirectoryItem(PATH_TOP_VIDEOS, TEXT_TOP_VIDEOS, "")) dir.AppendItem(DirectoryItem(PATH_LATEST_VIDEOS, TEXT_LATEST_VIDEOS, "")) dir.AppendItem(DirectoryItem(PATH_VIDEO_SERIES, TEXT_VIDEO_SERIES, "")) dir.AppendItem(DirectoryItem(PATH_HIT_LIST, TEXT_HIT_LIST, "")) dir.AppendItem(DirectoryItem(PATH_GAME_TRAILERS, TEXT_GAME_TRAILERS, "")) dir.AppendItem(DirectoryItem(PATH_MOVIE_TRAILERS, TEXT_MOVIE_TRAILERS, "")) dir.AppendItem(DirectoryItem(PATH_REVIEWS, TEXT_REVIEWS, "")) dir.AppendItem(DirectoryItem(PATH_PREVIEWS, TEXT_PREVIEWS, "")) dir.AppendItem(DirectoryItem(PATH_RECENT_VIDEOS, TEXT_RECENT_VIDEOS, "")) return dir.ToXML()
def HandleRequest(pathNouns, count): user_id = Prefs.Get("user_id") device_code = Prefs.Get("device_code") Log.Add("Handling request for paths " + (",".join(pathNouns))) if count == 0: dir = MediaContainer('art-default.jpg', None, "Channels") dir.AppendItem( DirectoryItem("most_watched_week", "Most Watched This Week", "")) dir.AppendItem( DirectoryItem("most_watched_all", "Most Watched All Time", "")) dir.AppendItem( DirectoryItem("most_watched_month", "Most Watched This Month", "")) dir.AppendItem( DirectoryItem("newest_videos_week", "Newest Videos This Week", "")) dir.AppendItem( DirectoryItem("newest_videos_today", "Newest Videos Today", "")) dir.AppendItem( SearchDirectoryItem("search", "Search", "Search Channels.com", Plugin.ExposedResourcePath("search.png"))) dir.AppendItem(DirectoryItem("my_feed", "My Feed", "")) if user_id != None: dir.AppendItem( SearchDirectoryItem( "pref^user_id", "Change Channels User Id [" + user_id + "]", "Change your Channels User ID.", "")) else: dir.AppendItem( SearchDirectoryItem( "pref^user_id", "Set your User ID", "Go to Edit Profile - Tools and see your user ID.", "")) if device_code != None: dir.AppendItem( SearchDirectoryItem( "pref^device_code", "Change Channels Device Code [" + device_code + "]", "Change your Channels Device Code.", "")) else: dir.AppendItem( SearchDirectoryItem( "pref^device_code", "Set your Device Code", "Go to Edit Profile - Tools and see your Device Code.", "")) return dir.ToXML() elif pathNouns[0] == "most_watched_week": url = CHANNELS_URL + "popular/videos/week?format=rss" Log.Add("Loading " + url) return populateFromFeed(url, "Most Watched This Week") elif pathNouns[0] == "most_watched_month": url = CHANNELS_URL + "popular/videos/month?format=rss" Log.Add("Loading " + url) return populateFromFeed(url, "Most Watched This Month") elif pathNouns[0] == "most_watched_all": url = CHANNELS_URL + "popular/videos/all?format=rss" Log.Add("Loading " + url) return populateFromFeed(url, "Most Watched All Time") elif pathNouns[0] == "newest_videos_today": url = CHANNELS_URL + "newest/videos/today?format=rss" Log.Add("Loading " + url) return populateFromFeed(url, "Newest Videos Today") elif pathNouns[0] == "newest_videos_week": url = CHANNELS_URL + "newest/videos/week?format=rss" Log.Add("Loading " + url) return populateFromFeed(url, "Newest Videos This Week") elif pathNouns[0] == "my_feed": Log.Add("Handling my feed only if user_id and device_code are there.") if user_id != None and device_code != None: url = CHANNELS_URL + "device_feed?format=rss&user_id=" + user_id + "&device_code=" + device_code Log.Add("Loading " + url) return populateFromFeed(url, "My Feed") elif pathNouns[0].startswith("pref"): if count == 2: field = pathNouns[0].split("^")[1] Prefs.Set(field, pathNouns[1]) if field == "user_id": dir.SetMessage("Channels Preferences", "Channels User ID Set.") else: dir.SetMessage("Channels Preferences", "Channels Device Code Set") elif pathNouns[0] == "search": if count > 1: query = pathNouns[1] if count > 2: for i in range(2, len(pathNouns)): query += "/%s" % pathNouns[i] return populateFromFeed( CHANNELS_SEARCH_URL + urllib.quote_plus(query), "Query: " + query)