forked from edit4ever/script.module.sd4tvh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.py
142 lines (130 loc) · 5.58 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from subprocess import Popen
from xbmcswift2 import Plugin
import StringIO
import os
import re
import requests
import sys
import xbmc,xbmcaddon,xbmcvfs,xbmcgui,xbmcplugin
import zipfile
import operator
import HTMLParser
from sdAPI import SdAPI
import hashlib
import datetime,time
from utils import *
import sqlite3
import cgi
plugin = Plugin()
def log(v):
xbmc.log(repr(v))
def get_icon_path(icon_name):
addon_path = xbmcaddon.Addon().getAddonInfo("path")
return os.path.join(addon_path, 'resources', 'img', icon_name+".png")
def remove_formatting(label):
label = re.sub(r"\[/?[BI]\]",'',label)
label = re.sub(r"\[/?COLOR.*?\]",'',label)
return label
@plugin.route('/add_provider')
def add_provider():
user = plugin.get_setting('User')
passw = plugin.get_setting('Pass')
passw = hashlib.sha1(passw.encode('utf-8')).hexdigest()
sd = SdAPI(user=user, passw=passw)
if not sd.logged_in:
#TODO popup settings
return
#global sd
status = 'You have %d / %d lineups' % (len(sd.lineups), sd.max_lineups)
if sd.max_lineups - len(sd.lineups) < 1:
xbmcgui.Dialog().ok(
xbmcaddon.Addon().getAddonInfo('name'), status,
'To add a new one you need to first remove one of your lineups')
return
country_list = sd.get_countries()
countries = []
for country in country_list:
countries.append(country['fullName'])
countries = sorted(countries, key=lambda s: s.lower())
sel = xbmcgui.Dialog().select('Select country - %s' % status, list=countries)
if sel >= 0:
name = countries[sel]
sel_country = [x for x in country_list if x["fullName"] == name]
if len(sel_country) > 0:
sel_country = sel_country[0]
keyb = xbmc.Keyboard(sel_country['postalCodeExample'], 'Enter Post Code')
keyb.doModal()
if keyb.isConfirmed():
lineup_list = sd.get_lineups(country=sel_country["shortName"], postcode=keyb.getText())
lineups = []
saved_lineups = sd.lineups
for lineup in lineup_list:
if lineup['lineup'] not in saved_lineups:
lineups.append(lineup['name'])
lineups = sorted(lineups, key=lambda s: s.lower())
sel = xbmcgui.Dialog().select('Select lineup - not showing already selected...',
list=lineups)
if sel >= 0:
name = lineups[sel]
sel_lineup = [x for x in lineup_list if x["name"] == name]
if len(sel_lineup) > 0:
sel_lineup = sel_lineup[0]
xbmcgui.Dialog().notification(xbmcaddon.Addon().getAddonInfo('name'), 'Saving lineup...',
os.path.join(xbmcaddon.Addon().getAddonInfo('path'), 'icon.png'), 3000)
if sd.save_lineup(sel_lineup['lineup']):
xbmcgui.Dialog().notification(xbmcaddon.Addon().getAddonInfo('name'),
'Lineup "%s" saved' % name,
os.path.join(xbmcaddon.Addon().getAddonInfo('path'), 'icon.png'), 5000)
else:
raise SourceException('Lineup could not be saved! '
'Check the log for details.')
@plugin.route('/remove_provider')
def remove_provider():
user = plugin.get_setting('User')
passw = plugin.get_setting('Pass')
passw = hashlib.sha1(passw.encode('utf-8')).hexdigest()
sd = SdAPI(user=user, passw=passw)
#global sd, database
lineup_list = sd.get_user_lineups()
if len(lineup_list) == 0:
return
lineups = []
for lineup in lineup_list:
lineups.append(lineup['name'])
lineups = sorted(lineups, key=lambda s: s.lower())
sel = xbmcgui.Dialog().select('Current lineups - Click to delete...', list=lineups)
if sel >= 0:
name = lineups[sel]
sel_lineup = [x for x in lineup_list if x["name"] == name]
if len(sel_lineup) > 0:
sel_lineup = sel_lineup[0]
yes_no = xbmcgui.Dialog().yesno(xbmcaddon.Addon().getAddonInfo('name'),
'[COLOR red]Deleting a lineup will also remove all '
'channels associated with it![/COLOR]',
'Do you want to continue?')
if yes_no:
xbmcgui.Dialog().notification(xbmcaddon.Addon().getAddonInfo('name'), 'Deleting lineup...',
os.path.join(xbmcaddon.Addon().getAddonInfo('path'), 'icon.png'), 3000)
if sd.delete_lineup(sel_lineup['lineup']):
#TODO
#database.deleteLineup(close, sel_lineup['lineup'])
xbmcgui.Dialog().notification(xbmcaddon.Addon().getAddonInfo('name'), 'Lineup "%s" deleted' % name,
os.path.join(xbmcaddon.Addon().getAddonInfo('path'), 'icon.png'), 5000)
@plugin.route('/')
def index():
items = []
items.append(
{
'label': 'Add TV Provider',
'path': plugin.url_for('add_provider'),
'thumbnail':get_icon_path('settings'),
})
items.append(
{
'label': 'Remove TV Provider',
'path': plugin.url_for('remove_provider'),
'thumbnail':get_icon_path('settings'),
})
return items
if __name__ == '__default__':
plugin.run()