-
Notifications
You must be signed in to change notification settings - Fork 2
/
_kodi_tvshows.py
245 lines (179 loc) · 7.2 KB
/
_kodi_tvshows.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# -*- coding: utf-8 -*-
##################################################################################################
import logging
from _kodi_common import KodiItems
##################################################################################################
log = logging.getLogger("LD."+__name__)
##################################################################################################
class KodiTVShows(KodiItems):
def __init__(self, cursor):
self.cursor = cursor
print(cursor.connection)
KodiItems.__init__(self)
def create_entry_uniqueid(self):
self.cursor.execute("select coalesce(max(uniqueid_id),0) from uniqueid")
kodi_id = self.cursor.fetchone()[0] + 1
return kodi_id
def create_entry_rating(self):
self.cursor.execute("select coalesce(max(rating_id),0) from rating")
kodi_id = self.cursor.fetchone()[0] + 1
return kodi_id
def create_entry(self):
self.cursor.execute("select coalesce(max(idShow),0) from tvshow")
kodi_id = self.cursor.fetchone()[0] + 1
return kodi_id
def create_entry_season(self):
self.cursor.execute("select coalesce(max(idSeason),0) from seasons")
kodi_id = self.cursor.fetchone()[0] + 1
return kodi_id
def create_entry_episode(self):
self.cursor.execute("select coalesce(max(idEpisode),0) from episode")
kodi_id = self.cursor.fetchone()[0] + 1
return kodi_id
def get_tvshow(self, kodi_id):
query = "SELECT * FROM tvshow WHERE idShow = ?"
self.cursor.execute(query, (kodi_id,))
try:
kodi_id = self.cursor.fetchone()[0]
except TypeError:
kodi_id = None
return kodi_id
def get_episode(self, kodi_id):
query = "SELECT * FROM episode WHERE idEpisode = ?"
self.cursor.execute(query, (kodi_id,))
try:
kodi_id = self.cursor.fetchone()[0]
except TypeError:
kodi_id = None
return kodi_id
def get_ratingid(self, media_type, media_id):
query = "SELECT rating_id FROM rating WHERE media_type = ? AND media_id = ?"
self.cursor.execute(query, (media_type, media_id,))
try:
ratingid = self.cursor.fetchone()[0]
except TypeError:
ratingid = None
return ratingid
def add_ratings(self, *args):
query = (
'''
INSERT INTO rating(
rating_id, media_id, media_type, rating_type, rating, votes)
VALUES (?, ?, ?, ?, ?, ?)
'''
)
self.cursor.execute(query, (args))
def update_ratings(self, *args):
query = ' '.join((
"UPDATE rating",
"SET media_id = ?, media_type = ?, rating_type = ?, rating = ?, votes = ?",
"WHERE rating_id = ?"
))
self.cursor.execute(query, (args))
def get_uniqueid(self, media_type, media_id):
query = "SELECT uniqueid_id FROM uniqueid WHERE media_type = ? AND media_id = ?"
self.cursor.execute(query, (media_type, media_id,))
try:
uniqueid = self.cursor.fetchone()[0]
except TypeError:
uniqueid = None
return uniqueid
def add_uniqueid(self, *args):
query = (
'''
INSERT INTO uniqueid(
uniqueid_id, media_id, media_type, value, type)
VALUES (?, ?, ?, ?, ?)
'''
)
self.cursor.execute(query, (args))
def update_uniqueid(self, *args):
query = ' '.join((
"UPDATE uniqueid",
"SET media_id = ?, media_type = ?, value = ?, type = ?",
"WHERE uniqueid_id = ?"
))
self.cursor.execute(query, (args))
def add_tvshow(self, *args):
query = (
'''
INSERT INTO tvshow(idShow, c00, c01, c04, c05, c08, c09, c12, c13, c14, c15)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''
)
self.cursor.execute(query, (args))
def update_tvshow(self, *args):
query = ' '.join((
"UPDATE tvshow",
"SET c00 = ?, c01 = ?, c04 = ?, c05 = ?, c08 = ?, c09 = ?,",
"c12 = ?, c13 = ?, c14 = ?, c15 = ?",
"WHERE idShow = ?"
))
self.cursor.execute(query, (args))
def link_tvshow(self, show_id, path_id):
query = "INSERT OR REPLACE INTO tvshowlinkpath(idShow, idPath) values(?, ?)"
self.cursor.execute(query, (show_id, path_id))
def get_season(self, show_id, number, name=None):
query = ' '.join((
"SELECT idSeason",
"FROM seasons",
"WHERE idShow = ?",
"AND season = ?"
))
self.cursor.execute(query, (show_id, number,))
try:
season_id = self.cursor.fetchone()[0]
except TypeError:
season_id = self._add_season(show_id, number)
if self.kodi_version > 15 and name is not None:
query = "UPDATE seasons SET name = ? WHERE idSeason = ?"
self.cursor.execute(query, (name, season_id))
return season_id
def _add_season(self, show_id, number):
season_id = self.create_entry_season()
query = "INSERT INTO seasons(idSeason, idShow, season) values(?, ?, ?)"
self.cursor.execute(query, (season_id, show_id, number))
return season_id
def add_episode(self, *args):
query = (
'''
INSERT INTO episode(
idEpisode, idFile, c00, c01, c03, c04, c05, c09, c10, c12, c13, c14,
idShow, c15, c16)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''
)
self.cursor.execute(query, (args))
def add_episode_16(self, *args):
query = (
'''
INSERT INTO episode(
idEpisode, idFile, c00, c01, c03, c04, c05, c09, c10, c12, c13, c14,
idShow, c15, c16, idSeason)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''
)
self.cursor.execute(query, (args))
def update_episode(self, *args):
query = ' '.join((
"UPDATE episode",
"SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?,",
"c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?, idShow = ?",
"WHERE idEpisode = ?"
))
self.cursor.execute(query, (args))
def update_episode_16(self, *args):
query = ' '.join((
"UPDATE episode",
"SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?,",
"c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?, idSeason = ?, idShow = ?",
"WHERE idEpisode = ?"
))
self.cursor.execute(query, (args))
def remove_tvshow(self, kodi_id):
self.cursor.execute("DELETE FROM tvshow WHERE idShow = ?", (kodi_id,))
def remove_season(self, kodi_id):
self.cursor.execute("DELETE FROM seasons WHERE idSeason = ?", (kodi_id,))
def remove_episode(self, kodi_id, file_id):
self.cursor.execute("DELETE FROM episode WHERE idEpisode = ?", (kodi_id,))
self.cursor.execute("DELETE FROM files WHERE idFile = ?", (file_id,))