-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_kodi_movies.py
311 lines (235 loc) · 9.2 KB
/
_kodi_movies.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# -*- coding: utf-8 -*-
##################################################################################################
import logging
from _kodi_common import KodiItems
##################################################################################################
log = logging.getLogger("LD."+__name__)
##################################################################################################
class KodiMovies(KodiItems):
def __init__(self, cursor):
self.cursor = cursor
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(idMovie),0) from movie")
kodi_id = self.cursor.fetchone()[0] + 1
return kodi_id
def create_entry_set(self):
self.cursor.execute("select coalesce(max(idSet),0) from sets")
kodi_id = self.cursor.fetchone()[0] + 1
return kodi_id
def create_entry_country(self):
self.cursor.execute("select coalesce(max(country_id),0) from country")
kodi_id = self.cursor.fetchone()[0] + 1
return kodi_id
def get_movie(self, kodi_id):
query = "SELECT * FROM movie WHERE idMovie = ?"
self.cursor.execute(query, (kodi_id,))
try:
kodi_id = self.cursor.fetchone()[0]
except TypeError:
kodi_id = None
return kodi_id
def get_movie_by_title(self, title):
query = "SELECT * FROM movie WHERE c00 = ?"
self.cursor.execute(query, (title,))
try:
movie = self.cursor.fetchone()
except TypeError:
movie = None
return movie
def add_movie(self, *args):
query = (
'''
INSERT INTO movie(
idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07,
c09, c10, c11, c12, c14, c15, c16, c18, c19, c21)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''
)
self.cursor.execute(query, (args))
def add_movie_17(self, *args):
# Create the movie entry
query = (
'''
INSERT INTO movie(
idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07,
c09, c10, c11, c12, c14, c15, c16, c18, c19, c21, premiered)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''
)
self.cursor.execute(query, (args))
def update_movie(self, *args):
query = ' '.join((
"UPDATE movie",
"SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?, c06 = ?,",
"c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?,",
"c16 = ?, c18 = ?, c19 = ?, c21 = ?",
"WHERE idMovie = ?"
))
self.cursor.execute(query, (args))
def update_movie_17(self, *args):
query = ' '.join((
"UPDATE movie",
"SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?, c06 = ?,",
"c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?,",
"c16 = ?, c18 = ?, c19 = ?, c21 = ?, premiered = ?",
"WHERE idMovie = ?"
))
self.cursor.execute(query, (args))
def remove_movie(self, kodi_id, file_id):
self.cursor.execute("DELETE FROM movie WHERE idMovie = ?", (kodi_id,))
self.cursor.execute("DELETE FROM files WHERE idFile = ?", (file_id,))
def get_ratingid(self, media_id):
query = "SELECT rating_id FROM rating WHERE media_type = ? AND media_id = ?"
self.cursor.execute(query, ("movie", 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_id):
query = "SELECT uniqueid_id FROM uniqueid WHERE media_type = ? AND media_id = ?"
self.cursor.execute(query, ("movie", 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_countries(self, kodi_id, countries):
if self.kodi_version > 14:
for country in countries:
country_id = self._get_country(country)
query = (
'''
INSERT OR REPLACE INTO country_link(country_id, media_id, media_type)
VALUES (?, ?, ?)
'''
)
self.cursor.execute(query, (country_id, kodi_id, "movie"))
else:
# TODO: Remove Helix code when Krypton is RC
for country in countries:
query = ' '.join((
"SELECT idCountry",
"FROM country",
"WHERE strCountry = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (country,))
try:
country_id = self.cursor.fetchone()[0]
except TypeError:
# Create a new entry
self.cursor.execute("select coalesce(max(idCountry),0) from country")
country_id = self.cursor.fetchone()[0] + 1
query = "INSERT INTO country(idCountry, strCountry) values(?, ?)"
self.cursor.execute(query, (country_id, country))
log.debug("Add country to media, processing: %s", country)
query = (
'''
INSERT OR REPLACE INTO countrylinkmovie(idCountry, idMovie)
VALUES (?, ?)
'''
)
self.cursor.execute(query, (country_id, kodi_id))
def _add_country(self, country):
country_id = self.create_entry_country()
query = "INSERT INTO country(country_id, name) values(?, ?)"
self.cursor.execute(query, (country_id, country))
log.debug("Add country to media, processing: %s", country)
return country_id
def _get_country(self, country):
query = ' '.join((
"SELECT country_id",
"FROM country",
"WHERE name = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (country,))
try:
country_id = self.cursor.fetchone()[0]
except TypeError:
country_id = self._add_country(country)
return country_id
def add_boxset(self, boxset):
query = ' '.join((
"SELECT idSet",
"FROM sets",
"WHERE strSet = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (boxset,))
try:
set_id = self.cursor.fetchone()[0]
except TypeError:
set_id = self._add_boxset(boxset)
return set_id
def _add_boxset(self, boxset):
set_id = self.create_entry_set()
query = "INSERT INTO sets(idSet, strSet) values(?, ?)"
self.cursor.execute(query, (set_id, boxset))
log.debug("Adding boxset: %s", boxset)
return set_id
def update_boxset(self, set_id, boxset):
query = ' '.join((
"UPDATE sets",
"SET strSet = ?",
"WHERE idSet = ?"
))
self.cursor.execute(query, (boxset, set_id,))
def set_boxset(self, set_id, movie_id):
query = ' '.join((
"UPDATE movie",
"SET idSet = ?",
"WHERE idMovie = ?"
))
self.cursor.execute(query, (set_id, movie_id,))
def remove_from_boxset(self, movie_id):
query = ' '.join((
"UPDATE movie",
"SET idSet = null",
"WHERE idMovie = ?"
))
self.cursor.execute(query, (movie_id,))
def remove_boxset(self, kodi_id):
self.cursor.execute("DELETE FROM sets WHERE idSet = ?", (kodi_id,))