jellyfin-kodi/resources/lib/objects/music.py
angelblue05 bab67ddf9b
Version 4.0.0 (#182)
* Adjust refresh behavior

* Fix favorites

* Add option to mask info

* Fix keymap delete

* Fix empty show

* Version bump 3.1.14

* Reset rescan flag

* Fix subtitles encoding

* Fix path verification

* Fix update library

Plug in remove library percentage

* Fix unauthorized behavior

Reprompt user with login

* Fix series pooling

* Version bump 3.1.15

* Fix for additional users

Return all users, not just public users

* Fix http potential errors

Prevent from going further if {server} or {userid} is requested but not filled to avoid 401 errors

* Fix extra fanart

* Fix patch

make a case insensitive search

* Version bump 3.1.16

Additional logging, fix kodi source.

* Fix library tags on update

* Version bump 3.1.17

* Fix season artwork

* Fix season artwork

* Fix logging

* Fix blank files sources

* Add backup option

* Fix userdata song

* Transfer data.txt to data.json

Use default port for webserver caching

* Fix mixed content shortcut

* Fix path encoding for patch

Hopefully this works...

* Fix source nonetype error

Just incase, wrap in a try/except because it's not important.

* Base fast sync on server time

Try to fix music video refresh to prevent cursor from moving up.

* Prep subfolders for dynamic

Support homevideos for now

* Fix empty artist, missing Title

* Version bump 3.1.18a

* Version bump for objects

171076013

* Notify user of large updates

Give option to back out if the user wants to manually update the libraries

* Fix sources.xml verification

* Prevent error in monitor

Put in place try/except in case data is None

* Remember sync position for manual triggers

Allow to resume sync on restart for manual user triggers (update, repair). Automatically refresh boxsets if movie library is selected.

use waitForAbort and emby_should_stop prop to terminate threads

* Update string for sync later

* Add subfolders for dynamic movies

* Small fixes

* Version bump 3.1.19

* Fix fast sync

try/except, default back to previous behavior.

* Fix artwork

* Change settings name

To ensure it takes default value instead of previous value set in 3.0.34

* Fix transcode

flac and live tv

* Fix episodes for series pooling

* Add live tv support

* Version bump 3.1.20

* Revert "Small fixes"

This reverts commit 9ec1fa3585.

* Version bump 3.1.21

* Fix playback starting server connection instance

* Fix show update

* Fix boxsets

* Fix lastplayed

* Patch to support pre 3.6 libraries

* Fix slowness

* Plug in settings for threading

* Plug in settings for threading

* Adjust sleep behavior

* Version bump 3.1.22

* Fix server detection in monitor

* Version bump 3.1.23

* Fix potential error with checksum

* Fix missing new artists

* Fix library sync

Adjust lock, re-add screensaver deactivated during sync, prep compare sync, stop library updates from being processed before startup sync is completed

* Version bump 3.1.25

* Fix local trailers

* Adjust lock modification

* Check db version

* Prevent error from creating nodes

The addon automatically creates nodes at startup with prefilled information. Prevent errors in the event something goes wrong. It will fix itself down the line, after user has logged in.

* Version bump 3.1.26

* Revert "Version bump 3.1.26"

This reverts commit c583a69a4b.

* Fix screensaver toggle

* Fix source selection for direct stream

* Version bump 3.1.26

* Add progress for updates

* Revise progress bar

Fix typos and subsetting

* content notification

* Remove content with update library

Now remove irrelevant content as well

* Fix slowness

* Version bump 3.1.27

* Stop trying to get items if server offline

* Fix content type for dynamic music

* Fix resume sync

Now save progress, unless exited due to path validation

* Fix artwork for shortcuts on profile switch

* Add force transcode settings

* Fix audiobooks back to video type

Add shortcuts. Audiobook can't be music type otherwise it break resume behavior and it won't play the right item. Has to be video type.

* Update general info

To finish, download and installation

* Update README.md

* Move welcome message to service

* Prevent patch loop

Try once, then let it go, to avoid locking user in a restart loop

* Review library threads

* Prep for audiobook transcode

Still need to implement universal for audio transcode

* Version bump 3.1.28

* Fix emby database locked

* Fix regression to welcome message

* Version bump 3.1.29

* Adjust playback

Allow direct play for http streams

* Ensure all threads are terminated correctly

* Fix empty results due to error 500

* Fix boxset refresh

* Fix resume sync behavior

Allow to complete the startup sync in the event user backs out of resume sync

* Version bump 3.1.30

* Update patch

Move patch from cache to addon_data. No longer need to restart Kodi to apply the first patch.

* Fix inital sync leading to fast sync

* Fix user settings

Due to api change in 3.6.0.55

* krypton update

* Adjust for resume settings

With .55 the resume setting is set per library. Instead query server to see if the item is played to offer delete

* Restart service upon check for updates

To reload the new objects module.

* Fix update library

Only do the compare when user selects update library, also add a restart service option in the add-on settings > advanced

* Version bump 3.1.31

* Update dependencies

* Update FR translation

* Update DE translation

* Add translation

* Support up next

* Small service adjustment

* Krypton update to support upnext

* Add a verification onwake

Somehow, Kodi can trigger OnWake without first trigger OnSleep.

* Fix loading if special char in path

* Add logging and small fixes

Prepare userdata by date modified

* Version bump 3.1.32

* Change default behavior of startup dialog

In case it is forced closed by Kodi, allow the sync to proceed

* Ensure deliveryurl is an actual url

* Update README.md

* Fix nextup

* Fix dynamic widgets

* Detect coreelect, etc

* Fix progress report

Silent RefreshProgress in websocket

* Follow emby settings for subtitles

* Version bump 3.1.33

* Add Italian translation

* Fix playback for server 3.6.0.61

* Version bump 3.1.34a

* Add silent catch for errors

* Adjust playback progress monitor

Only track progress report if the item is an emby item

* Fix subtitles not following server settings

* Add remove libraries, fix mixed libraries

* Fix live tv

For now, use transcode since direct play returns a 127.0.0.1 unusable address as the path.

* Allow live tv to direct stream

* Fix LiveTV

* Add setting to sync during playback

* Fix updates

* Fix encoding error

* Add optional rotten tomatoes option

* Version bump 3.1.35

* Fix emby connect auth string

Was preventing proper device detection when using emby connect, play to, etc.

* Add setup RT

* Fix audio/sub change

Only for addon playback

* Add developer mode

* Update patch

Check for updates + dev = forced grab from github

* Fix RT string

* Fix patch

Allow dev mode to redownload zip

* Fix patch

ugh sleep!!

* Verify patch connection

* Version bump 3.1.36

* Fix libraries being wiped

Catch errors to prevent false positive

* Add dateutil library

* Prep convert to local time

* Fix string

* Prep for multi db version support

* Fix service restart

* Add shortcut restart addon

Add notification

* Add database discovery

* Ensure previous playback terminated

* Update translation

New: Polish, Dutch Updated: German, French, Italian

* Version bump 3.1.37

* Quick fix for new library dateutil

* Catch error for dateutil

In the event the server has some weird date that can't be converted

* Version bump 3.1.38

* Fix dateutil import

* Fix db discovery

Ignore emby.db

* Version bump 3.1.39

* Add a delay if setup not completed

Avoid crash from everything loading at once.

* Fix database discovery

Add table verification + date modified verification

* Container optional playutils

* Version bump 3.1.40

* Adjust database discovery

Compare loaded vs discovered to avoid loading old databases by accident.

* Version bump 3.1.41

* Fix discovery toggle

* Version bump 3.1.42

* Add webservice for playback prep

* Fix service restart

* Version bump 3.1.43

* Update default sync indicator

Based on overall feedback

* Fix check update

* Fix if server is selected but unavailable

* Support songs without albums

* Fix encode and params

* Increase retry timeout

* Fix update generating duplicates

* Add manage libraries

Too many entries

* Fix database discovery

* Fixed transcode via context menu

* Fix context transcode

* Quiet webservice

* Update Krypton objects

* Fix database discovery prompt

* fixed video listitem issues for krypton

* load all item details for playlists

* Fix playlist

* Version bump 3.1.44

* Fix force hi10p transcoding behavior

Fixes the "Force Hi10p transcoding" option to only apply to h264 video codecs

* Clear playlist on player.onstop

* Don't clear playlist if busy spinner is active

* Fix case sensitive issue at calling the log function

* fix db stuff (#164)

* Reload objects upon initial setup

* Fix database discovery

ignore db-journal

* Update translation

German, Italian

* Use LastConnectionMode for server test

* Fix compare sync

* Version bump 3.1.45

* Ensure widgets get updated

Container.Refresh alone doesn't seem to work

* Update database discovery

* Re-add texture to database discovery

* Add option to enable/disable service

* Remove unused strings

* Fix object reload upon restart service

* Update Krypton objects

* Update translation

Dutch, Polish

* Version bump 3.1.46

* Adjust client api

* Adjust subtitles behavior

* Fix string typo

* Only run one full sync instance

Prevent user from launching multiple syncs and freezing the add-on.

* added "playlists" to wnodes

* Disable Audiobooks

Server doesn't have a set structure yet. This feature is broken atm.

* Version bump 4.0.0

* License GPL v3

* Update readme
2019-01-24 07:04:48 -06:00

560 lines
19 KiB
Python

# -*- coding: utf-8 -*-
##################################################################################################
import json
import datetime
import logging
import urllib
from obj import Objects
from kodi import Music as KodiDb, queries_music as QU
from database import emby_db, queries as QUEM
from helper import api, catch, stop, validate, emby_item, values, library_check, settings, Local
##################################################################################################
LOG = logging.getLogger("EMBY."+__name__)
##################################################################################################
class Music(KodiDb):
def __init__(self, server, embydb, musicdb, direct_path):
self.server = server
self.emby = embydb
self.music = musicdb
self.direct_path = direct_path
self.emby_db = emby_db.EmbyDatabase(embydb.cursor)
self.objects = Objects()
self.item_ids = []
KodiDb.__init__(self, musicdb.cursor)
def __getitem__(self, key):
if key in ('MusicArtist', 'AlbumArtist'):
return self.artist
elif key == 'MusicAlbum':
return self.album
elif key == 'Audio':
return self.song
elif key == 'UserData':
return self.userdata
elif key in 'Removed':
return self.remove
@stop()
@emby_item()
@library_check()
def artist(self, item, e_item, library):
''' If item does not exist, entry will be added.
If item exists, entry will be updated.
'''
API = api.API(item, self.server['auth/server-address'])
obj = self.objects.map(item, 'Artist')
update = True
try:
obj['ArtistId'] = e_item[0]
except TypeError as error:
update = False
obj['ArtistId'] = None
LOG.debug("ArtistId %s not found", obj['Id'])
else:
if self.validate_artist(*values(obj, QU.get_artist_by_id_obj)) is None:
update = False
LOG.info("ArtistId %s missing from kodi. repairing the entry.", obj['ArtistId'])
obj['LibraryId'] = library['Id']
obj['LibraryName'] = library['Name']
obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
obj['ArtistType'] = "MusicArtist"
obj['Genre'] = " / ".join(obj['Genres'] or [])
obj['Bio'] = API.get_overview(obj['Bio'])
obj['Artwork'] = API.get_all_artwork(self.objects.map(item, 'ArtworkMusic'), True)
obj['Thumb'] = obj['Artwork']['Primary']
obj['Backdrops'] = obj['Artwork']['Backdrop'] or ""
if obj['Thumb']:
obj['Thumb'] = "<thumb>%s</thumb>" % obj['Thumb']
if obj['Backdrops']:
obj['Backdrops'] = "<fanart>%s</fanart>" % obj['Backdrops'][0]
if update:
self.artist_update(obj)
else:
self.artist_add(obj)
self.update(obj['Genre'], obj['Bio'], obj['Thumb'], obj['Backdrops'], obj['LastScraped'], obj['ArtistId'])
self.artwork.add(obj['Artwork'], obj['ArtistId'], "artist")
self.item_ids.append(obj['Id'])
def artist_add(self, obj):
''' Add object to kodi.
safety checks: It looks like Emby supports the same artist multiple times.
Kodi doesn't allow that. In case that happens we just merge the artist entries.
'''
obj['ArtistId'] = self.get(*values(obj, QU.get_artist_obj))
self.emby_db.add_reference(*values(obj, QUEM.add_reference_artist_obj))
LOG.info("ADD artist [%s] %s: %s", obj['ArtistId'], obj['Name'], obj['Id'])
def artist_update(self, obj):
''' Update object to kodi.
'''
self.emby_db.update_reference(*values(obj, QUEM.update_reference_obj))
LOG.info("UPDATE artist [%s] %s: %s", obj['ArtistId'], obj['Name'], obj['Id'])
@stop()
@emby_item()
def album(self, item, e_item):
''' Update object to kodi.
'''
API = api.API(item, self.server['auth/server-address'])
obj = self.objects.map(item, 'Album')
update = True
try:
obj['AlbumId'] = e_item[0]
except TypeError as error:
update = False
obj['AlbumId'] = None
LOG.debug("AlbumId %s not found", obj['Id'])
else:
if self.validate_album(*values(obj, QU.get_album_by_id_obj)) is None:
update = False
LOG.info("AlbumId %s missing from kodi. repairing the entry.", obj['AlbumId'])
obj['Rating'] = 0
obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
obj['Genres'] = obj['Genres'] or []
obj['Genre'] = " / ".join(obj['Genres'])
obj['Bio'] = API.get_overview(obj['Bio'])
obj['Artists'] = " / ".join(obj['Artists'] or [])
obj['Artwork'] = API.get_all_artwork(self.objects.map(item, 'ArtworkMusic'), True)
obj['Thumb'] = obj['Artwork']['Primary']
if obj['Thumb']:
obj['Thumb'] = "<thumb>%s</thumb>" % obj['Thumb']
if update:
self.album_update(obj)
else:
self.album_add(obj)
self.artist_link(obj)
self.artist_discography(obj)
self.update_album(*values(obj, QU.update_album_obj))
self.add_genres(*values(obj, QU.add_genres_obj))
self.artwork.add(obj['Artwork'], obj['AlbumId'], "album")
self.item_ids.append(obj['Id'])
def album_add(self, obj):
''' Add object to kodi.
'''
obj['AlbumId'] = self.get_album(*values(obj, QU.get_album_obj))
self.emby_db.add_reference(*values(obj, QUEM.add_reference_album_obj))
LOG.info("ADD album [%s] %s: %s", obj['AlbumId'], obj['Title'], obj['Id'])
def album_update(self, obj):
''' Update object to kodi.
'''
self.emby_db.update_reference(*values(obj, QUEM.update_reference_obj))
LOG.info("UPDATE album [%s] %s: %s", obj['AlbumId'], obj['Title'], obj['Id'])
def artist_discography(self, obj):
''' Update the artist's discography.
'''
for artist in (obj['ArtistItems'] or []):
temp_obj = dict(obj)
temp_obj['Id'] = artist['Id']
temp_obj['AlbumId'] = obj['Id']
try:
temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except TypeError:
continue
self.add_discography(*values(temp_obj, QU.update_discography_obj))
self.emby_db.update_parent_id(*values(temp_obj, QUEM.update_parent_album_obj))
def artist_link(self, obj):
''' Assign main artists to album.
Artist does not exist in emby database, create the reference.
'''
for artist in (obj['AlbumArtists'] or []):
temp_obj = dict(obj)
temp_obj['Name'] = artist['Name']
temp_obj['Id'] = artist['Id']
try:
temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except TypeError:
try:
self.artist(self.server['api'].get_item(temp_obj['Id']), library=None)
temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except Exception as error:
LOG.error(error)
continue
self.update_artist_name(*values(temp_obj, QU.update_artist_name_obj))
self.link(*values(temp_obj, QU.update_link_obj))
self.item_ids.append(temp_obj['Id'])
@stop()
@emby_item()
def song(self, item, e_item):
''' Update object to kodi.
'''
API = api.API(item, self.server['auth/server-address'])
obj = self.objects.map(item, 'Song')
update = True
try:
obj['SongId'] = e_item[0]
obj['PathId'] = e_item[2]
obj['AlbumId'] = e_item[3]
except TypeError as error:
update = False
obj['SongId'] = self.create_entry_song()
LOG.debug("SongId %s not found", obj['Id'])
else:
if self.validate_song(*values(obj, QU.get_song_by_id_obj)) is None:
update = False
LOG.info("SongId %s missing from kodi. repairing the entry.", obj['SongId'])
self.get_song_path_filename(obj, API)
obj['Rating'] = 0
obj['Genres'] = obj['Genres'] or []
obj['PlayCount'] = API.get_playcount(obj['Played'], obj['PlayCount'])
obj['Runtime'] = (obj['Runtime'] or 0) / 10000000.0
obj['Genre'] = " / ".join(obj['Genres'])
obj['Artists'] = " / ".join(obj['Artists'] or [])
obj['AlbumArtists'] = obj['AlbumArtists'] or []
obj['Index'] = obj['Index'] or 0
obj['Disc'] = obj['Disc'] or 1
obj['EmbedCover'] = False
obj['Comment'] = API.get_overview(obj['Comment'])
obj['Artwork'] = API.get_all_artwork(self.objects.map(item, 'ArtworkMusic'), True)
if obj['DateAdded']:
obj['DateAdded'] = Local(obj['DateAdded']).split('.')[0].replace('T', " ")
if obj['DatePlayed']:
obj['DatePlayed'] = Local(obj['DatePlayed']).split('.')[0].replace('T', " ")
if obj['Disc'] != 1:
obj['Index'] = obj['Disc'] * 2 ** 16 + obj['Index']
if update:
self.song_update(obj)
else:
self.song_add(obj)
self.link_song_album(*values(obj, QU.update_song_album_obj))
self.add_role(*values(obj, QU.update_role_obj)) # defaultt role
self.song_artist_link(obj)
self.song_artist_discography(obj)
obj['strAlbumArtists'] = " / ".join(obj['AlbumArtists'])
self.get_album_artist(*values(obj, QU.get_album_artist_obj))
self.add_genres(*values(obj, QU.update_genre_song_obj))
self.artwork.add(obj['Artwork'], obj['SongId'], "song")
self.item_ids.append(obj['Id'])
if obj['SongAlbumId'] is None:
self.artwork.add(obj['Artwork'], obj['AlbumId'], "album")
return not update
def song_add(self, obj):
''' Add object to kodi.
Verify if there's an album associated.
If no album found, create a single's album
'''
obj['PathId'] = self.add_path(obj['Path'])
try:
obj['AlbumId'] = self.emby_db.get_item_by_id(*values(obj, QUEM.get_item_song_obj))[0]
except TypeError:
try:
if obj['SongAlbumId'] is None:
raise TypeError("No album id found associated?")
self.album(self.server['api'].get_item(obj['SongAlbumId']))
obj['AlbumId'] = self.emby_db.get_item_by_id(*values(obj, QUEM.get_item_song_obj))[0]
except TypeError:
self.single(obj)
self.add_song(*values(obj, QU.add_song_obj))
self.emby_db.add_reference(*values(obj, QUEM.add_reference_song_obj))
LOG.debug("ADD song [%s/%s/%s] %s: %s", obj['PathId'], obj['AlbumId'], obj['SongId'], obj['Id'], obj['Title'])
def song_update(self, obj):
''' Update object to kodi.
'''
self.update_path(*values(obj, QU.update_path_obj))
self.update_song(*values(obj, QU.update_song_obj))
self.emby_db.update_reference(*values(obj, QUEM.update_reference_obj))
LOG.info("UPDATE song [%s/%s/%s] %s: %s", obj['PathId'], obj['AlbumId'], obj['SongId'], obj['Id'], obj['Title'])
def get_song_path_filename(self, obj, api):
''' Get the path and filename and build it into protocol://path
'''
obj['Path'] = api.get_file_path(obj['Path'])
obj['Filename'] = obj['Path'].rsplit('\\', 1)[1] if '\\' in obj['Path'] else obj['Path'].rsplit('/', 1)[1]
if self.direct_path:
if not validate(obj['Path']):
raise Exception("Failed to validate path. User stopped.")
obj['Path'] = obj['Path'].replace(obj['Filename'], "")
else:
obj['Path'] = "%s/emby/Audio/%s/" % (self.server['auth/server-address'], obj['Id'])
obj['Filename'] = "stream.%s?static=true" % obj['Container']
def song_artist_discography(self, obj):
''' Update the artist's discography.
'''
artists = []
for artist in (obj['AlbumArtists'] or []):
temp_obj = dict(obj)
temp_obj['Name'] = artist['Name']
temp_obj['Id'] = artist['Id']
artists.append(temp_obj['Name'])
try:
temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except TypeError:
try:
self.artist(self.server['api'].get_item(temp_obj['Id']), library=None)
temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except Exception as error:
LOG.error(error)
continue
self.link(*values(temp_obj, QU.update_link_obj))
self.item_ids.append(temp_obj['Id'])
if obj['Album']:
temp_obj['Title'] = obj['Album']
temp_obj['Year'] = 0
self.add_discography(*values(temp_obj, QU.update_discography_obj))
obj['AlbumArtists'] = artists
def song_artist_link(self, obj):
''' Assign main artists to song.
Artist does not exist in emby database, create the reference.
'''
for index, artist in enumerate(obj['ArtistItems'] or []):
temp_obj = dict(obj)
temp_obj['Name'] = artist['Name']
temp_obj['Id'] = artist['Id']
temp_obj['Index'] = index
try:
temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except TypeError:
try:
self.artist(self.server['api'].get_item(temp_obj['Id']), library=None)
temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0]
except Exception as error:
LOG.error(error)
continue
self.link_song_artist(*values(temp_obj, QU.update_song_artist_obj))
self.item_ids.append(temp_obj['Id'])
def single(self, obj):
obj['AlbumId'] = self.create_entry_album()
self.add_single(*values(obj, QU.add_single_obj))
@stop()
@emby_item()
def userdata(self, item, e_item):
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
Poster with progress bar
'''
API = api.API(item, self.server['auth/server-address'])
obj = self.objects.map(item, 'SongUserData')
try:
obj['KodiId'] = e_item[0]
obj['Media'] = e_item[4]
except TypeError:
return
obj['Rating'] = 0
if obj['Media'] == 'song':
if obj['DatePlayed']:
obj['DatePlayed'] = Local(obj['DatePlayed']).split('.')[0].replace('T', " ")
self.rate_song(*values(obj, QU.update_song_rating_obj))
self.emby_db.update_reference(*values(obj, QUEM.update_reference_obj))
LOG.info("USERDATA %s [%s] %s: %s", obj['Media'], obj['KodiId'], obj['Id'], obj['Title'])
@stop()
@emby_item()
def remove(self, item_id, e_item):
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
Poster with progress bar
This should address single song scenario, where server doesn't actually
create an album for the song.
'''
obj = {'Id': item_id}
try:
obj['KodiId'] = e_item[0]
obj['Media'] = e_item[4]
except TypeError:
return
if obj['Media'] == 'song':
self.remove_song(obj['KodiId'], obj['Id'])
self.emby_db.remove_wild_item(obj['id'])
for item in self.emby_get_item_by_wild_id(*values(obj, QUEM.get_item_by_wild_obj)):
if item[1] == 'album':
temp_obj = dict(obj)
temp_obj['ParentId'] = item[0]
if not self.emby_db.get_item_by_parent_id(*values(temp_obj, QUEM.get_item_by_parent_song_obj)):
self.remove_album(temp_obj['ParentId'], obj['Id'])
elif obj['Media'] == 'album':
obj['ParentId'] = obj['KodiId']
for song in self.emby_db.get_item_by_parent_id(*values(obj, QUEM.get_item_by_parent_song_obj)):
self.remove_song(song[1], obj['Id'])
else:
self.emby_db.remove_items_by_parent_id(*values(obj, QUEM.delete_item_by_parent_song_obj))
self.remove_album(obj['KodiId'], obj['Id'])
elif obj['Media'] == 'artist':
obj['ParentId'] = obj['KodiId']
for album in self.emby_db.get_item_by_parent_id(*values(obj, QUEM.get_item_by_parent_album_obj)):
temp_obj = dict(obj)
temp_obj['ParentId'] = album[1]
for song in self.emby_db.get_item_by_parent_id(*values(temp_obj, QUEM.get_item_by_parent_song_obj)):
self.remove_song(song[1], obj['Id'])
else:
self.emby_db.remove_items_by_parent_id(*values(temp_obj, QUEM.delete_item_by_parent_song_obj))
self.emby_db.remove_items_by_parent_id(*values(temp_obj, QUEM.delete_item_by_parent_artist_obj))
self.remove_album(temp_obj['ParentId'], obj['Id'])
else:
self.emby_db.remove_items_by_parent_id(*values(obj, QUEM.delete_item_by_parent_album_obj))
self.remove_artist(obj['KodiId'], obj['Id'])
self.emby_db.remove_item(*values(obj, QUEM.delete_item_obj))
def remove_artist(self, kodi_id, item_id):
self.artwork.delete(kodi_id, "artist")
self.delete(kodi_id)
LOG.info("DELETE artist [%s] %s", kodi_id, item_id)
def remove_album(self, kodi_id, item_id):
self.artwork.delete(kodi_id, "album")
self.delete_album(kodi_id)
LOG.info("DELETE album [%s] %s", kodi_id, item_id)
def remove_song(self, kodi_id, item_id):
self.artwork.delete(kodi_id, "song")
self.delete_song(kodi_id)
LOG.info("DELETE song [%s] %s", kodi_id, item_id)
@emby_item()
def get_child(self, item_id, e_item):
''' Get all child elements from tv show emby id.
'''
obj = {'Id': item_id}
child = []
try:
obj['KodiId'] = e_item[0]
obj['FileId'] = e_item[1]
obj['ParentId'] = e_item[3]
obj['Media'] = e_item[4]
except TypeError:
return child
obj['ParentId'] = obj['KodiId']
for album in self.emby_db.get_item_by_parent_id(*values(obj, QUEM.get_item_by_parent_album_obj)):
temp_obj = dict(obj)
temp_obj['ParentId'] = album[1]
child.append((album[0],))
for song in self.emby_db.get_item_by_parent_id(*values(temp_obj, QUEM.get_item_by_parent_song_obj)):
child.append((song[0],))
return child