def set_episode_info(self, label, prefix, when, ep): if ep and ep['id']: name = ep['name'] number = ep['number'] aired = self.nice_date(TheTVDB.convert_date(ep['aired'][:10])) else: name = number = aired = '' num_array = number.split('x') num_array.extend(['']) label.setProperty(prefix + when + 'Date', aired) label.setProperty(prefix + when + 'Title', name) label.setProperty(prefix + when + 'Number', number) label.setProperty(prefix + when + 'SeasonNumber', num_array[0]) label.setProperty(prefix + when + 'EpisodeNumber', num_array[1])
def set_labels(self, infolabel, item, want_ep_ndx = None): art = item["art"] must_have = None if infolabel == 'listitem': label = xbmcgui.ListItem() prefix = '' label.setLabel(item["localname"]) label.setThumbnailImage(item.get("thumbnail", "")) try: must_have = LISTITEM_ART[int(__addon__.getSetting("ThumbType"))] except: pass else: label = xbmcgui.Window(10000) if infolabel == "windowproperty": prefix = 'NextAired.' elif infolabel == "windowpropertytoday": prefix = 'NextAired.' + str(self.count) + '.' label.setProperty("NextAired.ShowAllTVShows", __addon__.getSetting("ShowAllTVShowsOnHome")) else: return # Impossible... label.setProperty(prefix + "Label", item["localname"]) label.setProperty(prefix + "Thumb", item.get("thumbnail", "")) if want_ep_ndx: next_ep = item['episodes'][want_ep_ndx] latest_ep = item['episodes'][want_ep_ndx-1] airdays = [ next_ep['wday'] ] else: ep_len = len(item['episodes']) next_ep = item['episodes'][1] if ep_len > 1 else None latest_ep = item['episodes'][0] airdays = [] if ep_len > 1: date_limit = (TheTVDB.convert_date(item['episodes'][1]['aired'][:10]) + timedelta(days=6)).isoformat() for ep in item['episodes'][1:]: if ep['aired'][:10] > date_limit: break airdays.append(ep['wday']) airdays.sort() daynums = ', ' . join([str(wday) for wday in airdays]) airdays = ', ' . join([self.weekdays[wday] for wday in airdays]) is_today = 'True' if next_ep and next_ep['aired'][:10] == self.datestr else 'False' started = TheTVDB.convert_date(item["Started"]) airtime = TheTVDB.convert_time(item["Airtime"]) if airtime is not None: airtime = airtime.strftime('%I:%M %p' if self.ampm else '%H:%M') else: airtime = '??:??' status = item.get("Status", "") if status == 'Continuing': ep = next_ep if next_ep else latest_ep if latest_ep else None if not ep or not ep['id'] or NEW_REGEX.match(ep['number']): status_id = '4' # New else: status_id = '0' # Returning elif status == 'Ended': if next_ep: status_id = '6' # Final Season else: status_id = '1' # Cancelled/Ended elif status == '': status_id = '2' # TBD/On the bubble else: status_id = '-1' # An unknown value shouldn't be possible... if status_id != '-1': status = STATUS[status_id] label.setProperty(prefix + "AirTime", airdays + ": " + airtime if airdays != "" else airtime) label.setProperty(prefix + "Path", item.get("path", "")) label.setProperty(prefix + "Library", item.get("dbid", "")) label.setProperty(prefix + "Status", status) label.setProperty(prefix + "StatusID", status_id) label.setProperty(prefix + "Network", item.get("Network", "")) label.setProperty(prefix + "Started", self.nice_date(started, force_year = True)) # XXX Note that Classification is always unset at the moment! label.setProperty(prefix + "Classification", item.get("Classification", "")) label.setProperty(prefix + "Genre", item.get("Genres", "")) label.setProperty(prefix + "Premiered", str(item.get("Premiered", ""))) label.setProperty(prefix + "Country", item.get("Country", "")) label.setProperty(prefix + "Runtime", str(item.get("Runtime", ""))) # Keep old fanart property for backwards compatibility label.setProperty(prefix + "Fanart", art.get("fanart", "")) # New art properties for art_type in ('fanart', 'poster', 'banner', 'landscape', 'clearlogo', 'characterart', 'clearart'): art_url = art.get(art_type, "") if must_have and art_url == "" and art_type == must_have: try: url = "http://opencoder.net/next-aired-missing/" + art_type + "/" + urllib.quote(item["localname"]) art_url = "image://%s.png/" % urllib.quote(url, '') except: pass label.setProperty("%sArt(%s)" % (prefix, art_type), art_url) label.setProperty(prefix + "Today", is_today) label.setProperty(prefix + "AirDay", airdays) label.setProperty(prefix + "AirDayNum", daynums) label.setProperty(prefix + "ShortTime", airtime) # This sets NextDate, NextTitle, etc. self.set_episode_info(label, prefix, 'Next', next_ep) # This sets LatestDate, LatestTitle, etc. self.set_episode_info(label, prefix, 'Latest', latest_ep) if infolabel == 'listitem': return label
tz_offset *= -1 else: tz_offset = 1 * 3600 # Default to +01:00 try: airtime = TheTVDB.convert_time(show.get('Airs_Time', "")) except: airtime = None local_airtime = airtime if airtime is not None else TheTVDB.convert_time('00:00') local_airtime = datetime.combine(self.date, local_airtime).replace(tzinfo=tz.tzoffset(None, tz_offset)) if airtime is not None: # Don't backtrack an assumed midnight time (for an invalid airtime) into the prior day. local_airtime = local_airtime.astimezone(tz.tzlocal()) current_show['Show Name'] = normalize(show, 'SeriesName') first_aired = show.get('FirstAired', None) if first_aired: first_aired = TheTVDB.convert_date(first_aired) current_show['Premiered'] = first_aired.year current_show['Started'] = first_aired.isoformat() else: current_show['Premiered'] = current_show['Started'] = "" current_show['Country'] = country current_show['Status'] = normalize(show, 'Status') current_show['Genres'] = normalize(show, 'Genre').strip('|').replace('|', ' | ') current_show['Network'] = network current_show['Airtime'] = local_airtime.strftime('%H:%M') if airtime is not None else '' current_show['Runtime'] = maybe_int(show, 'Runtime', '') can_re = re.compile(r"canceled|ended", re.IGNORECASE) if can_re.search(current_show['Status']): current_show['canceled'] = True elif 'canceled' in current_show:
def load(self, node, mirror_url, series=None): Episode.sqlmeta.lazyUpdate = True self.episode_id = node.findtext("id") self.tvdb_show_id = node.findtext("seriesid") self.name = node.findtext("EpisodeName") self.overview = node.findtext("Overview") self.season_number = int(node.findtext("SeasonNumber")) self.episode_number = int(node.findtext("EpisodeNumber")) self.director = node.findtext("Director") self.guest_stars = node.findtext("GuestStars") self.language = node.findtext("Language") self.production_code = node.findtext("ProductionCode") self.rating = node.findtext("Rating") self.writer = node.findtext("Writer") self.show = series # set the season try: self.season = Season.select((Season.q.season == self.season_number) & (Season.q.show == self.show)).getOne() # self.season = Season.get(series=series, season=self.season_number) except Exception as e: print "XXXXXXXX" print e self.season = Season(show=series, season=self.season_number) # Air date from thetvdbapi import TheTVDB self.first_aired = TheTVDB.convert_date(node.findtext("FirstAired")) # DVD Information self.dvd_chapter = node.findtext("DVD_chapter") self.dvd_disc_id = node.findtext("DVD_discid") self.dvd_episode_number = node.findtext("DVD_episodenumber") self.dvd_season = node.findtext("DVD_season") # Artwork/screenshot self.image = node.findtext("filename") if self.image is not None: self.poster_url = "%s/banners/%s" % (mirror_url, self.image) else: self.poster_url = "" # Episode ordering information (normally for specials) self.airs_after_season = node.findtext("airsafter_season") self.airs_before_season = node.findtext("airsbefore_season") self.airs_before_episode = node.findtext("airsbefore_episode") # Unknown self.combined_episode_number = node.findtext("combined_episode_number") self.combined_season = node.findtext("combined_season") self.absolute_number = node.findtext("absolute_number") self.season_id = node.findtext("seasonid") self.ep_img_flag = node.findtext("EpImgFlag") # External references self.imdb_id = node.findtext("IMDB_ID") # When this episode was last updated self.last_updated = datetime.datetime.fromtimestamp(int(node.findtext("lastupdated"))) # Handling play history self.watched = False self.pos = 0 self.syncUpdate() Episode.sqlmeta.lazyUpdate = False