def upgrade_data_format(show_dict, from_ver): if from_ver > MAIN_DB_VER: log("### ERROR: found DB version that is too new for this script to handle (%d > %d)" % (from_ver, MAIN_DB_VER), level=0) sys.exit() log("### upgrading DB from version %d to %d" % (from_ver, MAIN_DB_VER), level=1) daymap = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, 'Friday': 4, 'Saturday': 5, 'Sunday': 6} for tid, show in show_dict.iteritems(): if from_ver < 2: # Convert Started into isoformat date: started = '' for fmt in ('%b/%d/%Y', '%a, %b %d, %Y', '%Y-%m-%d'): try: started = strftime('%Y-%m-%d', strptime(show['Started'], fmt)) break except: pass show['Started'] = started # Convert airtime into HH:MM (never AM/PM): airtime = TheTVDB.convert_time(show['Airtime']) show['Airtime'] = airtime.strftime('%H:%M') if airtime is not None else '' for ep in show['episodes']: if from_ver < 3 and 'wday' in ep: # Convert wday from a string to an index: ep['wday'] = daymap[ep['wday']]
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
network = normalize(show, 'Network', 'Unknown') country = self.country_dict.get(network, 'Unknown') # XXX TODO allow the user to specify an override country that gets the local timezone. tzone = CountryLookup.get_country_timezone(country, self.in_dst) if not tzone: tzone = '' tz_re = re.compile(r"([-+])(\d\d):(\d\d)") m = tz_re.match(tzone) if m: tz_offset = (int(m.group(2)) * 3600) + (int(m.group(3)) * 60) if m.group(1) == '-': 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'] = ""