PlexKodiConnect/resources/lib/plex_db/movies.py

71 lines
2 KiB
Python
Raw Permalink Normal View History

2018-10-23 22:54:09 +11:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2018-10-25 00:20:25 +11:00
from .. import variables as v
2018-10-23 22:54:09 +11:00
class Movies(object):
def add_movie(self, plex_id, checksum, section_id, kodi_id, kodi_fileid,
2021-01-12 02:21:37 +11:00
kodi_pathid, trailer_synced, last_sync):
2018-10-23 22:54:09 +11:00
"""
Appends or replaces an entry into the plex table for movies
"""
query = '''
INSERT OR REPLACE INTO movie(
plex_id,
checksum,
section_id,
kodi_id,
kodi_fileid,
kodi_pathid,
fanart_synced,
2021-01-12 02:21:37 +11:00
trailer_synced,
2018-10-23 22:54:09 +11:00
last_sync)
2021-01-12 02:21:37 +11:00
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
2018-10-23 22:54:09 +11:00
'''
2018-10-25 00:20:25 +11:00
self.cursor.execute(
2018-10-23 22:54:09 +11:00
query,
(plex_id,
checksum,
section_id,
kodi_id,
kodi_fileid,
kodi_pathid,
0,
2021-01-12 02:21:37 +11:00
trailer_synced,
2018-10-23 22:54:09 +11:00
last_sync))
def movie(self, plex_id):
"""
Returns the show info as a tuple for the TV show with plex_id:
plex_id INTEGER PRIMARY KEY ASC,
checksum INTEGER UNIQUE,
section_id INTEGER,
kodi_id INTEGER,
kodi_fileid INTEGER,
kodi_pathid INTEGER,
fanart_synced INTEGER,
last_sync INTEGER
"""
2018-10-25 00:20:25 +11:00
if plex_id is None:
return
self.cursor.execute('SELECT * FROM movie WHERE plex_id = ? LIMIT 1',
2018-10-23 22:54:09 +11:00
(plex_id, ))
2018-10-25 00:20:25 +11:00
return self.entry_to_movie(self.cursor.fetchone())
@staticmethod
def entry_to_movie(entry):
if not entry:
return
return {
'plex_type': v.PLEX_TYPE_MOVIE,
'kodi_type': v.KODI_TYPE_MOVIE,
'plex_id': entry[0],
'checksum': entry[1],
'section_id': entry[2],
'kodi_id': entry[3],
'kodi_fileid': entry[4],
'kodi_pathid': entry[5],
'fanart_synced': entry[6],
'last_sync': entry[7]
2018-10-25 00:20:25 +11:00
}