Skip to content

Commit

Permalink
Merge pull request #2048 from croneter/python3-beta
Browse files Browse the repository at this point in the history
Bump python3 stable
  • Loading branch information
croneter committed Mar 26, 2024
2 parents c6c8da7 + fc04ba4 commit 8db9cde
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 65 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ Unfortunately, the PKC Kodi repository had to move because it stopped working (t
* [**Credits**](#credits)

### Download and Installation

Install PKC via the PlexKodiConnect Kodi repository download button just below (do NOT use the standard GitHub download!). Alternatively, add [https://croneter.github.io/pkc-source](https://croneter.github.io/pkc-source) as a new Kodi `Web server directory (HTTPS)` source. See the [github wiki installation manual](https://github.com/croneter/PlexKodiConnect/wiki/Installation) for a detailed guide. Please use the stable version except if you really know what you're doing. Kodi will update PKC automatically.

| Stable version | Beta version |
|----------------|--------------|
| [![stable version](https://img.shields.io/badge/stable_version-latest-blue.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/stable/repository.plexkodiconnect/repository.plexkodiconnect-1.0.2.zip) | [![beta version](https://img.shields.io/badge/beta_version-latest-red.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/beta/repository.plexkodiconnectbeta/repository.plexkodiconnectbeta-1.0.2.zip) |
See here for detailed instructions: [Installation](https://github.com/croneter/PlexKodiConnect/wiki/Installation)

### Warning
Use at your own risk! This plugin assumes that you manage all your videos with Plex (and none with Kodi). You might lose data already stored in the Kodi video and music databases as this plugin directly changes them. Don't worry if you want Plex to manage all your media (like you should ;-)).
Expand Down
32 changes: 28 additions & 4 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.plexkodiconnect" name="PlexKodiConnect" version="3.8.3" provider-name="croneter">
<addon id="plugin.video.plexkodiconnect" name="PlexKodiConnect" version="3.9.0" provider-name="croneter">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.22.0+matrix.1" />
<import addon="script.module.requests" version="2.22.0" />
<import addon="plugin.video.plexkodiconnect.movies" version="3.0.2" />
<import addon="plugin.video.plexkodiconnect.tvshows" version="3.0.2" />
<import addon="metadata.themoviedb.org.python" version="1.3.1+matrix.1" />
<import addon="metadata.themoviedb.org.python" version="1.3.1" />
</requires>
<extension point="xbmc.python.pluginsource" library="default.py">
<provides>video audio image</provides>
Expand Down Expand Up @@ -103,7 +103,31 @@
<summary lang="ko_KR">Plex를 Kodi에 기본 통합</summary>
<description lang="ko_KR">Kodi를 Plex Media Server에 연결합니다. 이 플러그인은 Plex로 모든 비디오를 관리하고 Kodi로는 관리하지 않는다고 가정합니다. Kodi 비디오 및 음악 데이터베이스에 이미 저장된 데이터가 손실 될 수 있습니다 (이 플러그인이 직접 변경하므로). 자신의 책임하에 사용하십시오!</description>
<disclaimer lang="ko_KR">자신의 책임하에 사용</disclaimer>
<news>version 3.8.3:
<news>version 3.9.0:
- WARNING: You will need to reset the Kodi database!
- versions 3.8.4-3.8.8 for everyone

version 3.8.8 (beta only):
- WARNING: You will need to reset the Kodi database!
- Fix changelog: Omega instead of Nexus #2036

version 3.8.7 (beta only):
- Kodi Omega: new attempt to fix movies not showing up #2034
- Separate intro / credit / commercial skip settings (thanks @Spacetech) #2033

version 3.8.6 (beta only):
- Kodi Omega: Fix SQlite-Error if not using exactly Omega Beta 3 #2031

version 3.8.5 (beta only):
- WARNING: You will need to reset the Kodi database!
- Kodi Omega Beta 3 and beyond: fix movies not showing up (thanks @Spacetech) #2028
- Kodi Omega Beta 3 and beyond: fix missing dependencies upon first installation #2029
- Prevent excessive library refreshes when browsing libraries in Plex Web (thanks @Spacetech) #2027

version 3.8.4 (beta only):
- Don't be so strict when checking for compatibility: always select the database file with highest version number #2015

version 3.8.3:
- version 3.8.2 for everyone

version 3.8.2 (beta only):
Expand Down
24 changes: 24 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
version 3.9.0:
- WARNING: You will need to reset the Kodi database!
- versions 3.8.4-3.8.8 for everyone

version 3.8.8 (beta only):
- WARNING: You will need to reset the Kodi database!
- Fix changelog: Omega instead of Nexus #2036

version 3.8.7 (beta only):
- Kodi Omega: new attempt to fix movies not showing up #2034
- Separate intro / credit / commercial skip settings (thanks @Spacetech) #2033

version 3.8.6 (beta only):
- Kodi Omega: Fix SQlite-Error if not using exactly Omega Beta 3 #2031

version 3.8.5 (beta only):
- WARNING: You will need to reset the Kodi database!
- Kodi Omega Beta 3 and beyond: fix movies not showing up (thanks @Spacetech) #2028
- Kodi Omega Beta 3 and beyond: fix missing dependencies upon first installation #2029
- Prevent excessive library refreshes when browsing libraries in Plex Web (thanks @Spacetech) #2027

version 3.8.4 (beta only):
- Don't be so strict when checking for compatibility: always select the database file with highest version number #2015

version 3.8.3:
- version 3.8.2 for everyone

Expand Down
10 changes: 10 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -1516,3 +1516,13 @@ msgstr ""
msgctxt "#39720"
msgid "Auto skip intro"
msgstr ""

# PKC Settings - Playback
msgctxt "#39721"
msgid "Auto skip credits"
msgstr ""

# PKC Settings - Playback
msgctxt "#39722"
msgid "Auto skip commercials"
msgstr ""
3 changes: 2 additions & 1 deletion resources/lib/kodi_db/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

KODIDB_LOCK = Lock()
# Names of tables we generally leave untouched and e.g. don't wipe
UNTOUCHED_TABLES = ('version', 'versiontagscan')
UNTOUCHED_TABLES = ('version', 'versiontagscan', 'videoversiontype')


class KodiDBBase(object):
Expand All @@ -24,6 +24,7 @@ def __init__(self, texture_db=False, kodiconn=None, artconn=None,
self.cursor = self.kodiconn.cursor() if self.kodiconn else None
self.artconn = artconn
self.artcursor = self.artconn.cursor() if self.artconn else None
self._has_video_version_table = None

def __enter__(self):
if self.lock:
Expand Down
41 changes: 41 additions & 0 deletions resources/lib/kodi_db/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,26 @@ def add_movie(self, *args):
?, ?, ?, ?)
''', (args))

if self.has_video_version_table:
self.cursor.execute(
'''
INSERT OR REPLACE INTO videoversion(
idFile,
idMedia,
media_type,
itemType,
idType)
VALUES
(?, ?, ?, ?, ?)
''', (args[1], args[0], "movie", "0", 40400))

@db.catch_operationalerrors
def remove_movie(self, kodi_id):
self.cursor.execute('DELETE FROM movie WHERE idMovie = ?', (kodi_id,))

if self.has_video_version_table:
self.cursor.execute('DELETE FROM videoversion WHERE idMedia = ?', (kodi_id,))

@db.catch_operationalerrors
def update_userrating(self, kodi_id, kodi_type, userrating):
"""
Expand All @@ -1083,3 +1099,28 @@ def update_userrating(self, kodi_id, kodi_type, userrating):
identifier = 'idShow'
self.cursor.execute('''UPDATE %s SET userrating = ? WHERE ? = ?''' % table,
(userrating, identifier, kodi_id))

@property
def has_video_version_table(self):
if self._has_video_version_table is None:
self._check_video_version_table_consistancy()
return self._has_video_version_table

@db.catch_operationalerrors
def _check_video_version_table_consistancy(self):
self._has_video_version_table = False
# Check whether videoversion table exists
self.cursor.execute('SELECT COUNT(name) FROM sqlite_master WHERE type=\'table\' AND name=\'videoversion\'')
if not self.cursor.fetchone()[0] == 1:
return
# Check whether all needed columns for table videoversion actually exist
self.cursor.execute('PRAGMA table_info(videoversion)')
columns = self.cursor.fetchall()
needed_columns =[
(0, 'idFile', 'INTEGER', 0, None, 1),
(1, 'idMedia', 'INTEGER', 0, None, 0),
(2, 'media_type', 'TEXT', 0, None, 0),
(3, 'itemType', 'INTEGER', 0, None, 0),
(4, 'idType', 'INTEGER', 0, None, 0)
]
self._has_video_version_table = columns == needed_columns
11 changes: 7 additions & 4 deletions resources/lib/kodimonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,14 @@ def PlayBackStart(self, data):
container_key = '/playQueues/%s' % playqueue.id
else:
container_key = '/library/metadata/%s' % plex_id
# Mechanik for Plex skip intro feature
if utils.settings('enableSkipIntro') == 'true':
# Mechanik for Plex skip intro/credits/commercials feature
if utils.settings('enableSkipIntro') == 'true' \
or utils.settings('enableSkipCredits') == 'true' \
or utils.settings('enableSkipCommercials') == 'true':
status['markers'] = item.api.markers()
status['first_credits_marker'] = item.api.first_credits_marker()
status['final_credits_marker'] = item.api.final_credits_marker()
if utils.settings('enableSkipCredits') == 'true':
status['first_credits_marker'] = item.api.first_credits_marker()
status['final_credits_marker'] = item.api.final_credits_marker()
if item.playmethod is None and path and not path.startswith('plugin://'):
item.playmethod = v.PLAYBACK_METHOD_DIRECT_PATH
item.playerid = playerid
Expand Down
3 changes: 3 additions & 0 deletions resources/lib/library_sync/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def store_activity_message(data):
elif message['Activity']['type'] != 'library.refresh.items':
# Not the type of message relevant for us
continue
elif message['Activity']['Context']['refreshed'] != True:
# The item was scanned but not actually refreshed
continue
plex_id = PF.GetPlexKeyNumber(message['Activity']['Context']['key'])[1]
if not plex_id:
# Likely a Plex id like /library/metadata/3/children
Expand Down
15 changes: 8 additions & 7 deletions resources/lib/skip_plex_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
# Supported types of markers that can be skipped; values here will be
# displayed to the user when skipping is available
MARKERS = {
'intro': utils.lang(30525), # Skip intro
'credits': utils.lang(30526), # Skip credits
'commercial': utils.lang(30530) # Skip commercial
'intro': (utils.lang(30525), 'enableSkipIntro', 'enableAutoSkipIntro'), # Skip intro
'credits': (utils.lang(30526), 'enableSkipCredits', 'enableAutoSkipCredits'), # Skip credits
'commercial': (utils.lang(30530), 'enableSkipCommercials', 'enableAutoSkipCommercials'), # Skip commercial
}


def skip_markers(markers):
try:
progress = app.APP.player.getTime()
except RuntimeError:
# XBMC is not playing any media file yet
return
within_marker = False
marker_definition = None
for start, end, typus, _ in markers:
if start <= progress < end:
marker_definition = MARKERS[typus]
if utils.settings(marker_definition[1]) == "true" and start <= progress < end:
within_marker = True
break
if within_marker and app.APP.skip_markers_dialog is None:
Expand All @@ -32,9 +33,9 @@ def skip_markers(markers):
v.ADDON_PATH,
'default',
'1080i',
marker_message=MARKERS[typus],
marker_message=marker_definition[0],
marker_end=end)
if utils.settings('enableAutoSkipIntro') == "true":
if utils.settings(marker_definition[2]) == "true":
app.APP.skip_markers_dialog.seekTimeToEnd()
else:
app.APP.skip_markers_dialog.show()
Expand Down
77 changes: 34 additions & 43 deletions resources/lib/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import platform
import re

import xbmc
import xbmcvfs
Expand Down Expand Up @@ -103,25 +104,8 @@
PKC_MACHINE_IDENTIFIER = None

# Minimal PKC version needed for the Kodi database - otherwise need to recreate
MIN_DB_VERSION = '3.2.1'

# Supported databases
# See https://github.com/xbmc/xbmc/blob/master/xbmc/video/VideoDatabase.cpp
SUPPORTED_VIDEO_DB = {
19: (119, ),
20: (119, 120, 121),
21: (121, 122, 123, 124, ),
}
SUPPORTED_MUSIC_DB = {
19: (82, ),
20: (82, ),
21: (82, 83, ),
}
SUPPORTED_TEXTURE_DB = {
19: (13, ),
20: (13, ),
21: (13, ),
}
MIN_DB_VERSION = '3.8.8'

DB_VIDEO_VERSION = None
DB_VIDEO_PATH = None
DB_MUSIC_VERSION = None
Expand Down Expand Up @@ -695,33 +679,40 @@
M3U_ENCODING = sys.getfilesystemencoding()


def _find_latest_db(db_kind_regex):
'''
Returns the tuple (filepath [str], version [int]) for the regex
db_kind_regex with the highest version number at the end.
'''
database_path = xbmcvfs.translatePath('special://database')
matches = []
for root, dirs, files in path_ops.walk(database_path):
for file in files:
match = re.search(db_kind_regex, file, re.IGNORECASE)
if not match:
continue
matches.append((path_ops.path.join(root, file),
int(match.group(1))))
if not matches:
raise RuntimeError(f'Database {db_kind_regex} not found in {files}')
return max(matches, key=lambda x: x[1])


def database_paths():
'''
Set the Kodi database paths - PKC will choose the HIGHEST available and
supported database version for the current Kodi version.
Will raise a RuntimeError if the DBs are not found or of a wrong,
unsupported version
Set the Kodi database paths - PKC will choose the HIGHEST available
database version. You should thus never downgrade Kodi.
Will raise RuntimeError if the current Kodi version is not supported or
if a certain DB is not found.
'''
# Check Kodi version first
if KODIVERSION not in (19, 20, 21):
raise RuntimeError('Kodiversion %s not supported by PKC' % KODIVERSION)
raise RuntimeError(f'Kodiversion {KODIVERSION} not supported by PKC')

database_path = xbmcvfs.translatePath('special://database')
thismodule = sys.modules[__name__]
types = (('MyVideos%s.db', SUPPORTED_VIDEO_DB,
'DB_VIDEO_VERSION', 'DB_VIDEO_PATH'),
('MyMusic%s.db', SUPPORTED_MUSIC_DB,
'DB_MUSIC_VERSION', 'DB_MUSIC_PATH'),
('Textures%s.db', SUPPORTED_TEXTURE_DB,
'DB_TEXTURE_VERSION', 'DB_TEXTURE_PATH'))
for string, versions, actual_version, actual_path in types:
for version in sorted(versions[KODIVERSION], reverse=True):
file = string % version
path = path_ops.path.join(database_path, file)
if path_ops.exists(path):
setattr(thismodule, actual_version, version)
setattr(thismodule, actual_path, path)
break

if None in (DB_VIDEO_VERSION, DB_MUSIC_VERSION, DB_TEXTURE_VERSION):
raise RuntimeError('Kodi database versions not supported by PKC')
types = ((r'^MyVideos(\d+)\.db$', 'DB_VIDEO_PATH', 'DB_VIDEO_VERSION'),
(r'^MyMusic(\d+)\.db$', 'DB_MUSIC_PATH', 'DB_MUSIC_VERSION'),
(r'^Textures(\d+)\.db$', 'DB_TEXTURE_PATH', 'DB_TEXTURE_VERSION'))
for regex, pathstring, versionstring in types:
db_path, db_version = _find_latest_db(regex)
setattr(thismodule, pathstring, db_path)
setattr(thismodule, versionstring, db_version)
4 changes: 4 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
<setting id="trailerNumber" type="slider" label="39000" default="3" visible="eq(-2,true)" range="1,1,15" option="int" />
<setting id="enableSkipIntro" type="bool" label="30525" default="true" /><!-- Enable skipping of intros -->
<setting id="enableAutoSkipIntro" type="bool" label="39720" default="false" visible="eq(-1,true)" subsetting="true" /><!-- Enable auto skipping of intros -->
<setting id="enableSkipCredits" type="bool" label="30526" default="true" /><!-- Enable skipping of credits -->
<setting id="enableAutoSkipCredits" type="bool" label="39721" default="false" visible="eq(-1,true)" subsetting="true" /><!-- Enable auto skipping of credits -->
<setting id="enableSkipCommercials" type="bool" label="30530" default="true" /><!-- Enable skipping of commercials -->
<setting id="enableAutoSkipCommercials" type="bool" label="39722" default="false" visible="eq(-1,true)" subsetting="true" /><!-- Enable auto skipping of commercials -->
<setting id="firstVideoStream" type="bool" label="30546" default="false" /><!-- Pick the first video if several versions are present -->
<setting id="audioStreamPick" type="enum" label="30547" values="Plex|Kodi" default="0" /><!-- Who picks the audio stream on playback start? -->
<setting id="subtitleStreamPick" type="enum" label="30548" values="Plex|Kodi" default="0" /><!-- Who picks subtitles on playback start? -->
Expand Down

0 comments on commit 8db9cde

Please sign in to comment.