def GetPartyYears(id): result = GetJsonQuery("partyyears&id_party=" + id) dir = MediaContainer("art-default.png", title1="demoscene.tv", title2=GetJsonQueryTitle("partyyears&id_party=" + id)) dir.AppendItem(DirectoryItem("all_years", "all years", _R("icon-default.png"), "all years")) for item in result["items"]: dir.AppendItem(DirectoryItem(item, item, _R("icon-default.png"), item)) return dir
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 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 Index(): dir = MediaContainer("art-default.png", "Details", "demoscene.tv") dir.AppendItem(DirectoryItem("cat/lastadded", GetJsonQueryTitle("lastadded"), _R("icon-default.png"), GetJsonQueryDescription("lastadded"))) dir.AppendItem(DirectoryItem("cat/lastreleased", GetJsonQueryTitle("lastreleased"), _R("icon-default.png"), GetJsonQueryDescription("lastreleased"))) dir.AppendItem(DirectoryItem("cat/topweek", GetJsonQueryTitle("topweek"), _R("icon-default.png"), GetJsonQueryDescription("topweek"))) dir.AppendItem(DirectoryItem("cat/topmonth", GetJsonQueryTitle("topmonth"), _R("icon-default.png"), GetJsonQueryDescription("topmonth"))) dir.AppendItem(DirectoryItem("cat/alltimetop", GetJsonQueryTitle("alltimetop"), _R("icon-default.png"), GetJsonQueryDescription("alltimetop"))) dir.AppendItem(DirectoryItem("cat/toprating", GetJsonQueryTitle("toprating"), _R("icon-default.png"), GetJsonQueryDescription("toprating"))) dir.AppendItem(DirectoryItem("cat/groups", GetJsonQueryTitle("listofgroups"), _R("icon-default.png"), GetJsonQueryDescription("listofgroups"))) dir.AppendItem(DirectoryItem("cat/parties", GetJsonQueryTitle("listofparties"), _R("icon-default.png"), GetJsonQueryDescription("listofparties"))) dir.AppendItem(WhatIsDemoScene()) return dir
def GetFeedDirectory(feed): feed = GetJsonQuery(feed, DTV_FEED_LENGTH) dir = MediaContainer("art-default.png", title1="demoscene.tv", title2=re.sub(TITLE_CUT_PHRASE, "", GetValue("title", feed))) for item in feed["items"]: try: # mandatory data title = re.sub(TITLE_CUT_PHRASE, "", GetValue("title", item)) videoUrl = GetValue("videofile", item) thumbUrl = GetValue("screenshot", item) desc = "n/a"; # optional metadata creator = GetValue("creator", item) category = GetValue("category", item) type = GetValue("type", item) event = GetValue("event", item) year_event = GetValue("year_event", item) released_date = GetValue("released_date", item) added_date = GetValue("added_date", item) viewed = GetValue("viewed", item) # build description fom metadata desc = "Demogroup:\t"+ creator +"\n\nParty/Event:\t"+ event +" "+ year_event +"\n\nType:\t"+ type +"\nPlatform:\t"+ category +"\nReleased:\t"+ released_date +"\n\nAdded to DTV:\t"+ added_date +"\nViewed on DTV:\t"+ viewed dir.AppendItem(VideoItem(videoUrl, title, desc, "", thumbUrl)) except: Log.Add("Failed to load entry!") return dir
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 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 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 GetList(listname): result = GetJsonQuery(listname) list = result["items"] dir = MediaContainer("art-default.png", title1="demoscene.tv", title2=GetJsonQueryTitle(listname)) for id, name in list: Debug("item: ", id +"->" + name) dir.AppendItem(DirectoryItem(id, name, _R("icon-default.png"), name)) return dir
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 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 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 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 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 HandlePhotosRequest(pathNouns, count): dir_ = MediaContainer("art-default.jpg", "InfoList", "dinosaurcomics") global archived if archived == "new": archived = XML.ElementFromString(HTTP.GetCached(BASE_URL + "/archive.php", CACHE_TIME), True).xpath('//a[contains(@href, "www.qwantz.com/index.php?comic=")]') for item in archived[count*10:count*10+10]: try: title = item.text imgHTML = XML.ElementFromString(HTTP.GetCached(item.get("href"), CACHE_TIME), True).xpath('//img[contains(@class, "comic")]')[0] img = imgHTML.get("src") desc = imgHTML.get("title") ph = PhotoItem(img, title, desc, img) dir_.AppendItem(ph) except Exception, e: Log.Add("Exception caught when trying to fetch comic:") Log.Add("\t" + str(e)) Log.Add("\t" + item.get("href"))
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)