forked from primaeval/plugin.video.iptv.recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.py
65 lines (55 loc) · 2.25 KB
/
default.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
import xbmc,xbmcgui,xbmcaddon,xbmcvfs,xbmcplugin
import sys
import time,datetime
import sqlite3
import pytz
import tzlocal
import re
import urllib
def log(x):
xbmc.log(repr(x),xbmc.LOGERROR)
def remove_formatting(label):
label = re.sub(r"\[/?[BI]\]", '', label, flags=re.I)
label = re.sub(r"\[/?COLOR.*?\]", '', label, flags=re.I)
return label
#log(sys.argv)
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")
#channel = urllib.quote_plus(channel)
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'), detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = conn.cursor()
try:
#log(channel)
channel_id = cursor.execute('SELECT tvg_id FROM streams WHERE name=?',(channel,)).fetchone()[0]
if not channel_id:
channel_id = cursor.execute('SELECT tvg_id FROM streams WHERE tvg_name=?',(channel,)).fetchone()[0]
#log(channel_id)
if channel_id:
program_id = cursor.execute('SELECT uid FROM programmes WHERE channelid=? AND start=?',(channel_id,start_time)).fetchone()[0]
#log((channel_id, program_id, start_time))
if program_id:
channel = channel.encode("utf8")
channel = urllib.quote_plus(channel)
xbmc.executebuiltin("ActivateWindow(videos,plugin://plugin.video.iptv.recorder/broadcast/%s/%s,return)" % (program_id,channel))
except Exception as e:
#log(e)
xbmcgui.Dialog().notification("IPTV Recorder","program not found",xbmcgui.NOTIFICATION_WARNING)