-
Notifications
You must be signed in to change notification settings - Fork 29
/
contextEPG.py
79 lines (59 loc) · 2.62 KB
/
contextEPG.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import locale
import time
from datetime import datetime
import urllib
import xbmc
import xbmcgui
DATE_FORMAT = "%Y-%m-%d %H:%M:00"
def log(x):
xbmc.log(repr(x), xbmc.LOGERROR)
def escape(value):
value = value.decode("utf8")
value = value.encode("utf8")
return urllib.quote_plus(value)
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)
def extract_date(dateLabel, timeLabel):
date = xbmc.getInfoLabel(dateLabel)
timeString = xbmc.getInfoLabel(timeLabel)
fullDate = "{}, {}".format(date, timeString)
# https://bugs.python.org/issue27400
try:
parsedDate = datetime.strptime(fullDate, fullFormat)
except TypeError:
parsedDate = datetime(*(time.strptime(fullDate, fullFormat)[0:6]))
return datetime.strftime(parsedDate, DATE_FORMAT)
def get_language():
try:
language = xbmc.getLanguage(xbmc.ISO_639_1, True)
languageParts = language.split("-")
return "{}_{}.UTF-8".format(languageParts[0], languageParts[1])
except:
return ""
try:
usedLocale = locale.setlocale(locale.LC_TIME, get_language())
except:
usedLocale = locale.setlocale(locale.LC_TIME, "")
log("Used locale: " + usedLocale)
fullFormat = get_format()
channel = escape(xbmc.getInfoLabel("ListItem.ChannelName"))
title = escape(xbmc.getInfoLabel("ListItem.Label"))
try:
start = extract_date("ListItem.StartDate", "ListItem.StartTime")
stop = extract_date("ListItem.EndDate", "ListItem.EndTime")
try:
cmd = "PlayMedia(plugin://plugin.video.iptv.recorder/record_epg/%s/%s/%s/%s)" % (channel,
title,
start,
stop)
xbmc.executebuiltin(cmd)
message = "{}: {} ({} to {})'".format(xbmc.getInfoLabel("ListItem.ChannelName"), xbmc.getInfoLabel("ListItem.Label"), start, stop)
xbmcgui.Dialog().notification("IPTV Recorder - Scheduled record", message, xbmcgui.NOTIFICATION_INFO, 10000, sound=False)
except:
xbmcgui.Dialog().notification("IPTV Recorder", "Could not schedule recording", xbmcgui.NOTIFICATION_WARNING)
except Exception as e:
xbmcgui.Dialog().notification("IPTV Recorder", "Error parsing dates", xbmcgui.NOTIFICATION_ERROR)
log("IPTV Recorder: Error parsing dates ({})".format(e))