Example #1
0
def getTimeFormat():
    """
    Get global time format.
    Kodi's time format handling is broken right now, as they return incompatible formats for strftime.
    %H%H is being returned for manually set zero-padded values, in case of a regional zero-padded hour component,
    only %H is returned.

    For now, sail around that by testing the current time for padded hour values.

    Tests of the values returned by xbmc.getRegion("time"):
    %I:%M:%S %p = h:mm:ss, non-zero-padded, 12h PM
    %I:%M:%S = 12h, h:mm:ss, non-zero-padded, regional
    %I%I:%M:%S = 12h, zero padded, hh:mm:ss
    %H%H:%M:%S = 24h, zero padded, hh:mm:ss
    %H:%M:%S = 24h, zero padded, regional, regional (central europe)

    :return: tuple of strftime-compatible format, boolean padHour
    """
    origFmt = xbmc.getRegion('time')
    fmt = origFmt.replace("%H%H", "%H").replace("%I%I", "%I")

    # Checking for %H%H or %I%I only would be the obvious way here to determine whether the hour should be padded,
    # but the formats returned for regional settings with padding only have %H in them. This seems like a Kodi bug.
    # Use a fallback.
    currentTime = xbmc.getInfoLabel('System.Time')
    padHour = "%H%H" in origFmt or "%I%I" in origFmt or (
        currentTime[0] == "0" and currentTime[1] != ":")
    return fmt, padHour
Example #2
0
def time_from_zone(timestring, newfrmt="default", in_zone="UTC"):
    try:
        if newfrmt == "default":
            newfrmt = xbmc.getRegion("time").replace(":%S", "")
        in_time = parse(timestring)
        in_time_with_timezone = in_time.replace(tzinfo=gettz(in_zone))
        local_time = in_time_with_timezone.astimezone(local_tzinfo)
        return local_time.strftime(newfrmt)
    except:
        return timestring
if len(sys.argv) == 1:
    xbmc.executebuiltin(
        "ActivateWindow(videos,plugin://plugin.video.iptv.recorder)")
    quit()

channel = sys.argv[1]
channel = channel.decode("utf8")
channel = channel.encode("utf8")

title = sys.argv[2]
date = sys.argv[3]
duration = sys.argv[4]
plot = sys.argv[5]

dateshort_format = xbmc.getRegion('dateshort')
time_format = xbmc.getRegion('time').replace('%H%H', '%H')
format = "%s %s" % (dateshort_format, time_format.replace(':%S', ''))
#log((date,dateshort_format,time_format,format))
start_time = datetime.datetime.fromtimestamp(
    time.mktime(time.strptime(date, format)))
timezone = tzlocal.get_localzone()
start_time = timezone.localize(start_time)
utc = pytz.timezone('utc')
start_time = start_time.astimezone(utc)
start_time = start_time.replace(tzinfo=None)

#log((channel, start_time))

conn = sqlite3.connect(xbmc.translatePath(
    'special://profile/addon_data/plugin.video.iptv.recorder/xmltv.db'),
def getRegion(r):
    return xbmc.getRegion(r)
Example #5
0
def get_format():
    dateFormat = xbmc.getRegion('datelong')
    timeFormat = xbmc.getRegion('time').replace('%H%H',
                                                '%H').replace('%I%I', '%I')
    timeFormat = timeFormat.replace(":%S", "")
    return "{}, {}".format(dateFormat, timeFormat)