2018-10-20 23:49:04 +11:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import, division, unicode_literals
|
|
|
|
import xbmc
|
|
|
|
|
2019-05-01 16:56:11 +10:00
|
|
|
from .. import utils, app, variables as v
|
2019-02-03 01:49:21 +11:00
|
|
|
|
2019-02-06 04:52:10 +11:00
|
|
|
PLAYLIST_SYNC_ENABLED = (v.DEVICE != 'Microsoft UWP' and
|
2019-02-03 01:49:21 +11:00
|
|
|
utils.settings('enablePlaylistSync') == 'true')
|
2018-10-20 23:49:04 +11:00
|
|
|
|
|
|
|
|
2019-01-31 06:36:52 +11:00
|
|
|
class fullsync_mixin(object):
|
|
|
|
def __init__(self):
|
|
|
|
self._canceled = False
|
2018-10-20 23:49:04 +11:00
|
|
|
|
2019-01-31 06:36:52 +11:00
|
|
|
def abort(self):
|
|
|
|
"""Hit method to terminate the thread"""
|
|
|
|
self._canceled = True
|
|
|
|
# Let's NOT suspend sync threads but immediately terminate them
|
|
|
|
suspend = abort
|
|
|
|
|
|
|
|
@property
|
|
|
|
def suspend_reached(self):
|
|
|
|
"""Since we're not suspending, we'll never set it to True"""
|
|
|
|
return False
|
|
|
|
|
|
|
|
@suspend_reached.setter
|
|
|
|
def suspend_reached(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def resume(self):
|
|
|
|
"""Obsolete since we're not suspending"""
|
|
|
|
pass
|
2018-10-20 23:49:04 +11:00
|
|
|
|
2018-12-22 02:53:53 +11:00
|
|
|
def isCanceled(self):
|
2019-01-31 06:36:52 +11:00
|
|
|
"""Check whether we should exit this thread"""
|
|
|
|
return self._canceled
|
2018-12-22 02:53:53 +11:00
|
|
|
|
|
|
|
|
2018-10-20 23:49:04 +11:00
|
|
|
def update_kodi_library(video=True, music=True):
|
|
|
|
"""
|
|
|
|
Updates the Kodi library and thus refreshes the Kodi views and widgets
|
|
|
|
"""
|
2018-11-26 06:36:54 +11:00
|
|
|
if video:
|
2019-05-01 16:56:11 +10:00
|
|
|
if not xbmc.getCondVisibility('Window.IsMedia'):
|
|
|
|
xbmc.executebuiltin('UpdateLibrary(video)')
|
|
|
|
else:
|
|
|
|
# Prevent cursor from moving - refresh later
|
|
|
|
xbmc.executebuiltin('Container.Refresh')
|
|
|
|
app.APP.update_widgets = True
|
2018-11-26 06:36:54 +11:00
|
|
|
if music:
|
|
|
|
xbmc.executebuiltin('UpdateLibrary(music)')
|
2018-12-26 04:26:13 +11:00
|
|
|
|
|
|
|
|
|
|
|
def tag_last(iterable):
|
|
|
|
"""
|
|
|
|
Given some iterable, returns (last, item), where last is only True if you
|
|
|
|
are on the final iteration.
|
|
|
|
"""
|
|
|
|
iterator = iter(iterable)
|
|
|
|
gotone = False
|
|
|
|
try:
|
|
|
|
lookback = next(iterator)
|
|
|
|
gotone = True
|
|
|
|
while True:
|
|
|
|
cur = next(iterator)
|
|
|
|
yield False, lookback
|
|
|
|
lookback = cur
|
|
|
|
except StopIteration:
|
|
|
|
if gotone:
|
|
|
|
yield True, lookback
|
|
|
|
raise StopIteration()
|