def update_albums_in_items(self, items, forceAll=False):
if self._config.cache_albums:
# Step 1: Read all available Albums from Cache
self.albumQueue = Queue()
missing_ids = []
missing_items = []
track_count = 0
self.abortAlbumThreads = False
for item in items:
if isinstance(item, TrackItem):
track_count += 1
isAlbum = True
try:
# In Single Tracks the Album-ID is Track-ID - 1
if not forceAll and item.name == item.album.name and item.trackNumber == 1 and (int('%s' % item.id) - int('%s' % item.album.id)) == 1:
isAlbum = False
except:
pass
if item.available and not item.album.releaseDate and isAlbum:
#(item.title <> item.album.title or item.trackNumber > 1):
# Try to read Album from Cache
json_obj = self.albumJsonBuffer.get('%s' % item.album.id, None)
if json_obj == None:
json_obj = self.metaCache.getAlbumJson(item.album.id)
if json_obj != None:
item.album = self._parse_album(json_obj)
else:
missing_items.append(item)
if not item.album.id in missing_ids:
missing_ids.append(item.album.id)
self.albumQueue.put('%s' % item.album.id)
# Step 2: Load JSon-Data from all missing Albums
if len(missing_ids) <= 5 or self._config.max_http_requests <= 1:
# Without threads
self.get_album_json_thread()
else:
log('Starting Threads to load Albums')
runningThreads = []
while len(runningThreads) < self._config.max_http_requests:
try:
worker = Thread(target=self.get_album_json_thread)
worker.start()
runningThreads.append(worker)
except Exception, e:
log(str(e), xbmc.LOGERROR)
log('Waiting until all Threads are terminated')
for worker in runningThreads:
worker.join(20)
if worker.isAlive():
log('Worker %s is still running ...' % worker.ident, xbmc.LOGWARNING)
# Step 3: Save JsonData into MetaCache
if len(missing_items) > 0:
numAlbums = self.save_album_cache()
log('Cached %s from %s missing Albums for %s TrackItems' % (numAlbums, len(missing_items), track_count))
# Step 4: Fill missing Albums into the TrackItems
for item in missing_items:
json_obj = self.albumJsonBuffer.get('%s' % item.album.id, None)
if json_obj != None:
item.album = self._parse_album(json_obj)
python类LOGWARNING的实例源码
def play_stream(path):
"""
Play a stream by the provided path.
:param path: stream id
:return: None
"""
data = get_item(path)
report_url = None
subtitle_list = []
for publication in data['publicationEvent']:
if publication['temporalStatus'] == 'currently' and publication['type'] == 'OnDemandPublication':
log("Found correct publication, media id: " + publication['media']['id'])
media_id = publication['media']['id']
report_url = get_report_url(path, media_id)
protocol = 'HLS'
media_is_audio = publication['media']['type'] == 'AudioObject'
if media_is_audio:
protocol = 'PMD'
playout_data = get_playout(path, media_id, protocol)
encrypted_url = playout_data[0]['url']
subtitles = playout_data[0]['subtitles']
for subtitle in subtitles:
subtitle_list.append(subtitle['uri'])
path = decrypt_url(encrypted_url)
log("decrypted path: " + path)
if int(_addon.getSetting("maxResolution")) > 0 and not media_is_audio:
path = get_resolution_specific_url(path)
log("modified path: " + path)
break
# Create a playable item with a path to play.
play_item = xbmcgui.ListItem(path=path)
play_item.setSubtitles(subtitle_list)
# Report usage to YLE
response = get_url_response(report_url)
if response.getcode() != 200:
log("Could not report usage. Got code {0}".format(response.getcode()), xbmc.LOGWARNING)
if _addon.getSetting("noSubtitlesForDefaultLangAudio") == 'true':
disable_subtitles = False
if 'audio' in data:
for audio in data['audio']:
if 'language' in audio:
for language in audio['language']:
if language == get_language_codes()[0]:
disable_subtitles = True
if disable_subtitles:
xbmcplugin.endOfDirectory(_handle, True, False, False)
player = xbmc.Player()
player.play(item=path, listitem=play_item)
tries = 10
while tries > 0:
time.sleep(1)
tries -= 1
if player.isPlaying():
break
player.showSubtitles(False)
return
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)