Music: include bitrate for songs (channels + sampling rate won't work yet due to Plex not listing this info for an album's children)
This commit is contained in:
parent
f4923eda22
commit
2ef95b1480
4 changed files with 45 additions and 2 deletions
|
@ -458,6 +458,7 @@ class Song(MusicMixin, ItemBase):
|
||||||
moods.append(entry.attrib['tag'])
|
moods.append(entry.attrib['tag'])
|
||||||
mood = api.list_to_string(moods)
|
mood = api.list_to_string(moods)
|
||||||
_, path, filename = api.fullpath()
|
_, path, filename = api.fullpath()
|
||||||
|
audio_codec = api.audio_codec()
|
||||||
# UPDATE THE SONG #####
|
# UPDATE THE SONG #####
|
||||||
if update_item:
|
if update_item:
|
||||||
LOG.info("UPDATE song plex_id: %s - %s", plex_id, title)
|
LOG.info("UPDATE song plex_id: %s - %s", plex_id, title)
|
||||||
|
@ -479,6 +480,9 @@ class Song(MusicMixin, ItemBase):
|
||||||
api.userrating(),
|
api.userrating(),
|
||||||
comment,
|
comment,
|
||||||
mood,
|
mood,
|
||||||
|
audio_codec['bitrate'] or 0,
|
||||||
|
audio_codec['samplingrate'] or 0,
|
||||||
|
audio_codec['channels'] or 0,
|
||||||
api.date_created(),
|
api.date_created(),
|
||||||
kodi_id)
|
kodi_id)
|
||||||
# OR ADD THE SONG #####
|
# OR ADD THE SONG #####
|
||||||
|
@ -506,6 +510,9 @@ class Song(MusicMixin, ItemBase):
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
mood,
|
mood,
|
||||||
|
audio_codec['bitrate'] or 0,
|
||||||
|
audio_codec['samplingrate'] or 0,
|
||||||
|
audio_codec['channels'] or 0,
|
||||||
api.date_created())
|
api.date_created())
|
||||||
# Link song to artists
|
# Link song to artists
|
||||||
artist_name = api.grandparent_title()
|
artist_name = api.grandparent_title()
|
||||||
|
|
|
@ -348,8 +348,11 @@ class KodiMusicDB(common.KodiDBBase):
|
||||||
iStartOffset,
|
iStartOffset,
|
||||||
iEndOffset,
|
iEndOffset,
|
||||||
mood,
|
mood,
|
||||||
|
iBitRate,
|
||||||
|
iSampleRate,
|
||||||
|
iChannels,
|
||||||
dateAdded)
|
dateAdded)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
''', (args))
|
''', (args))
|
||||||
|
|
||||||
@db.catch_operationalerrors
|
@db.catch_operationalerrors
|
||||||
|
@ -370,6 +373,9 @@ class KodiMusicDB(common.KodiDBBase):
|
||||||
rating = ?,
|
rating = ?,
|
||||||
comment = ?,
|
comment = ?,
|
||||||
mood = ?,
|
mood = ?,
|
||||||
|
iBitRate = ?,
|
||||||
|
iSampleRate = ?,
|
||||||
|
iChannels = ?,
|
||||||
dateAdded = ?
|
dateAdded = ?
|
||||||
WHERE idSong = ?
|
WHERE idSong = ?
|
||||||
''', (args))
|
''', (args))
|
||||||
|
|
|
@ -27,6 +27,21 @@ class Media(object):
|
||||||
"""
|
"""
|
||||||
return self.xml[0][self.part].get(key, self.xml[0].get(key))
|
return self.xml[0][self.part].get(key, self.xml[0].get(key))
|
||||||
|
|
||||||
|
def _from_stream_or_part(self, key):
|
||||||
|
"""
|
||||||
|
Retrieves XML data 'key' first from the very first stream. If
|
||||||
|
unsuccessful, tries to retrieve the data from the active part.
|
||||||
|
|
||||||
|
If all fails, None is returned.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
value = self.xml[0][self.part][0].get(key)
|
||||||
|
except IndexError:
|
||||||
|
value = None
|
||||||
|
if value is None:
|
||||||
|
value = self.xml[0][self.part].get(key)
|
||||||
|
return value
|
||||||
|
|
||||||
def video_codec(self):
|
def video_codec(self):
|
||||||
"""
|
"""
|
||||||
Returns the video codec and resolution for the child and part selected.
|
Returns the video codec and resolution for the child and part selected.
|
||||||
|
@ -61,6 +76,19 @@ class Media(object):
|
||||||
answ['bitDepth'] = None
|
answ['bitDepth'] = None
|
||||||
return answ
|
return answ
|
||||||
|
|
||||||
|
def audio_codec(self):
|
||||||
|
"""
|
||||||
|
Returns the audio codec. If any data is not found on a part-level, the
|
||||||
|
Media-level data is returned. If that also fails (e.g. for old trailers,
|
||||||
|
None is returned)
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
'bitrate': cast(int, self._from_stream_or_part('bitrate')),
|
||||||
|
'samplingrate': cast(int, self._from_stream_or_part('samplingRate')),
|
||||||
|
'channels': cast(int, self._from_stream_or_part('channels')),
|
||||||
|
'gain': cast(float, self._from_stream_or_part('gain'))
|
||||||
|
}
|
||||||
|
|
||||||
def mediastreams(self):
|
def mediastreams(self):
|
||||||
"""
|
"""
|
||||||
Returns the media streams for metadata purposes
|
Returns the media streams for metadata purposes
|
||||||
|
|
|
@ -560,7 +560,9 @@ def GetAllPlexChildren(key):
|
||||||
Input:
|
Input:
|
||||||
key Key to a Plex item, e.g. 12345
|
key Key to a Plex item, e.g. 12345
|
||||||
"""
|
"""
|
||||||
return DownloadChunks("{server}/library/metadata/%s/children" % key)
|
return DownloadChunks(utils.extend_url(
|
||||||
|
f'{{server}}/library/metadata/{key}/children',
|
||||||
|
{'includeElements': 'Stream'}))
|
||||||
|
|
||||||
|
|
||||||
class ThreadedDownloadChunk(backgroundthread.Task):
|
class ThreadedDownloadChunk(backgroundthread.Task):
|
||||||
|
|
Loading…
Reference in a new issue