forked from bstrdsmkr/1Channel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
164 lines (130 loc) · 4.74 KB
/
utils.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
import re
import sys
import xbmc
import xbmcgui
# from functools import wraps
from t0mm0.common.addon import Addon
addon = Addon('plugin.video.1channel', sys.argv)
def format_label_tvshow(info):
if 'premiered' in info:
year = info['premiered'][:4]
else:
year = ''
title = info['title']
label = addon.get_setting('format-tvshow')
label = label.replace('{t}', title)
label = label.replace('{y}', year)
label = label.replace('{ft}', format_tvshow_title(title))
label = label.replace('{fy}', format_tvshow_year(year))
return label
def format_tvshow_title(title):
title_format = addon.get_setting('format-tvshow-title')
label = re.sub('\{t\}', title, title_format)
return label
def format_tvshow_year(year):
if not year: return ''
year_format = addon.get_setting('format-tvshow-year')
label = re.sub('\{y\}', year, year_format)
return label
def format_tvshow_episode(info):
episode_format = addon.get_setting('format-tvshow-episode')
label = re.sub('\{s\}', str(info['season']), episode_format)
label = re.sub('\{e\}', str(info['episode']), label)
label = re.sub('\{t\}', info['title'], label)
label = re.sub('\{st\}', info['TVShowTitle'], label)
return label
def format_label_sub(info):
sub_format = addon.get_setting('format-tvshow-sub')
label = format_label_tvshow(info)
formatted_label = re.sub('\{L\}', label, sub_format)
return formatted_label
def format_label_movie(info):
if 'premiered' in info:
year = info['premiered'][:4]
else:
year = ''
title = info['title']
label = addon.get_setting('format-movie')
label = label.replace('{t}', title)
label = label.replace('{y}', year)
label = label.replace('{ft}', format_movie_title(title))
label = label.replace('{fy}', format_movie_year(year))
return label
def format_movie_title(title):
title_format = addon.get_setting('format-movie-title')
label = re.sub('\{t\}', title, title_format)
return label
def format_movie_year(year):
if not year: return ''
year_format = addon.get_setting('format-movie-year')
label = re.sub('\{y\}', year, year_format)
return label
def format_label_source(info):
label = addon.get_setting('format-source')
label = re.sub('\{q\}', info['quality'], label)
label = re.sub('\{h\}', info['host'], label)
label = re.sub('\{v\}', str(info['views']), label)
if info['multi-part']:
parts = 'part 1'
else:
parts = ''
label = re.sub('\{p\}', parts, label)
if info['verified']: label = format_label_source_verified(label)
return label
def format_label_source_verified(label):
ver_format = addon.get_setting('format-source-verified')
formatted_label = re.sub('\{L\}', label, ver_format)
return formatted_label
def format_label_source_parts(info, part_num):
label = addon.get_setting('format-source-parts')
label = re.sub('\{q\}', info['quality'], label)
label = re.sub('\{h\}', info['host'], label)
label = re.sub('\{v\}', str(info['views']), label)
parts = 'part %s' % part_num
label = re.sub('\{p\}', parts, label)
if info['verified']: label = format_label_source_verified(label)
return label
def has_upgraded():
old_version = addon.get_setting('old_version').split('.')
new_version = addon.get_version().split('.')
current_oct = 0
for octant in old_version:
if int(new_version[current_oct]) > int(octant):
addon.log('New version found')
return True
current_oct += 1
return False
class TextBox:
# constants
WINDOW = 10147
CONTROL_LABEL = 1
CONTROL_TEXTBOX = 5
def __init__(self, *args, **kwargs):
# activate the text viewer window
xbmc.executebuiltin("ActivateWindow(%d)" % ( self.WINDOW, ))
# get window
self.win = xbmcgui.Window(self.WINDOW)
# give window time to initialize
xbmc.sleep(1000)
self.setControls()
def setControls(self):
# set heading
heading = "1Channel v%s" % (addon.get_version())
self.win.getControl(self.CONTROL_LABEL).setLabel(heading)
# set text
root = addon.get_path()
faq_path = os.path.join(root, 'help.faq')
f = open(faq_path)
text = f.read()
self.win.getControl(self.CONTROL_TEXTBOX).setText(text)
# import cProfile
# def profiled(func):
# def wrapper(*args, **kwargs):
# datafn = func.__name__ + ".profile" # Name the data file sensibly
# datapath = os.path.join(addon.get_profile(), datafn)
# prof = cProfile.Profile()
# retval = prof.runcall(func, *args, **kwargs)
# prof.dump_stats(datapath)
# return retval
# return wrapper