Example #1
0
    def __init__(self):

        self.emby = embyserver.Read_EmbyServer()

        self.kodi_id = xbmc.getInfoLabel('ListItem.DBID').decode('utf-8')
        self.item_type = self._get_item_type()
        self.item_id = self._get_item_id(self.kodi_id, self.item_type)

        log.info("Found item_id: %s item_type: %s", self.item_id,
                 self.item_type)

        if self.item_id:

            self.item = self.emby.getItem(self.item_id)
            self.api = api.API(self.item)

            if self._select_menu():
                self._action_menu()

                if self._selected_option in (OPTIONS['Delete'],
                                             OPTIONS['AddFav'],
                                             OPTIONS['RemoveFav'],
                                             OPTIONS['RateSong']):
                    log.info("refreshing container")
                    xbmc.sleep(500)
                    xbmc.executebuiltin('Container.Refresh')
Example #2
0
def getVideoFiles(embyId, embyPath):
    #returns the video files for the item as plugin listing, can be used for browsing the actual files or videoextras etc.
    emby = embyserver.Read_EmbyServer()
    if not embyId:
        if "plugin.video.emby" in embyPath:
            embyId = embyPath.split("/")[-2]
    if embyId:
        item = emby.getItem(embyId)
        putils = playutils.PlayUtils(item)
        if putils.isDirectPlay():
            #only proceed if we can access the files directly. TODO: copy local on the fly if accessed outside
            filelocation = putils.directPlay()
            if not filelocation.endswith("/"):
                filelocation = filelocation.rpartition("/")[0]
            dirs, files = xbmcvfs.listdir(filelocation)
            for file in files:
                file = filelocation + file
                li = xbmcgui.ListItem(file, path=file)
                xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                            url=file,
                                            listitem=li)
            for dir in dirs:
                dir = filelocation + dir
                li = xbmcgui.ListItem(dir, path=dir)
                xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                            url=dir,
                                            listitem=li,
                                            isFolder=True)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Example #3
0
    def __init__(self, embycursor, kodicursor):

        self.embycursor = embycursor
        self.kodicursor = kodicursor

        self.emby = embyserver.Read_EmbyServer()
        self.music_enabled = settings('enableMusic') == "true"
Example #4
0
    def __init__(self):

        self.__dict__ = self._shared_state

        client_info = clientinfo.ClientInfo()
        self.emby = embyserver.Read_EmbyServer()

        version = client_info.get_version()
        device_name = client_info.get_device_name()
        device_id = client_info.get_device_id()
        self._connect = connectionmanager.ConnectionManager(appName="Kodi",
                                                            appVersion=version,
                                                            deviceName=device_name,
                                                            deviceId=device_id)
        path = xbmc.translatePath(
                   "special://profile/addon_data/plugin.video.emby/").decode('utf-8')

        if not xbmcvfs.exists(path):
            xbmcvfs.mkdirs(path)

        self._connect.setFilePath(path)

        if window('emby_state.json'):
            self.state = window('emby_state.json')

        elif not self.state:
            self.state = self._connect.connect()
            log.info("Started with: %s", self.state)
            window('emby_state.json', value=self.state)
Example #5
0
def getExtraFanArt(embyId,embyPath):
    
    emby = embyserver.Read_EmbyServer()
    art = artwork.Artwork()
    
    # Get extrafanart for listitem 
    # will be called by skinhelper script to get the extrafanart
    try:
        # for tvshows we get the embyid just from the path
        if not embyId:
            if "plugin.video.emby" in embyPath:
                embyId = embyPath.split("/")[-2]
        
        if embyId:
            #only proceed if we actually have a emby id
            utils.logMsg("EMBY", "Requesting extrafanart for Id: %s" % embyId, 0)

            # We need to store the images locally for this to work
            # because of the caching system in xbmc
            fanartDir = xbmc.translatePath("special://thumbnails/emby/%s/" % embyId).decode('utf-8')
            
            if not xbmcvfs.exists(fanartDir):
                # Download the images to the cache directory
                xbmcvfs.mkdirs(fanartDir)
                item = emby.getItem(embyId)
                if item:
                    backdrops = art.getAllArtwork(item)['Backdrop']
                    tags = item['BackdropImageTags']
                    count = 0
                    for backdrop in backdrops:
                        # Same ordering as in artwork
                        tag = tags[count]
                        if os.path.supports_unicode_filenames:
                            fanartFile = os.path.join(fanartDir, "fanart%s.jpg" % tag)
                        else:
                            fanartFile = os.path.join(fanartDir.encode("utf-8"), "fanart%s.jpg" % tag.encode("utf-8"))
                        li = xbmcgui.ListItem(tag, path=fanartFile)
                        xbmcplugin.addDirectoryItem(
                                            handle=int(sys.argv[1]),
                                            url=fanartFile,
                                            listitem=li)
                        xbmcvfs.copy(backdrop, fanartFile) 
                        count += 1               
            else:
                utils.logMsg("EMBY", "Found cached backdrop.", 2)
                # Use existing cached images
                dirs, files = xbmcvfs.listdir(fanartDir)
                for file in files:
                    fanartFile = os.path.join(fanartDir, file.decode('utf-8'))
                    li = xbmcgui.ListItem(file, path=fanartFile)
                    xbmcplugin.addDirectoryItem(
                                            handle=int(sys.argv[1]),
                                            url=fanartFile,
                                            listitem=li)
    except Exception as e:
        utils.logMsg("EMBY", "Error getting extrafanart: %s" % e, 0)
    
    # Always do endofdirectory to prevent errors in the logs
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Example #6
0
    def __init__(self):

        self.clientInfo = clientinfo.ClientInfo()
        self.addonName = self.clientInfo.getAddonName()

        self.userid = utils.window('emby_currUser')
        self.server = utils.window('emby_server%s' % self.userid)

        self.emby = embyserver.Read_EmbyServer()
Example #7
0
    def __init__(self):

        self.__dict__ = self._shared_state

        self.doutils = downloadutils.DownloadUtils()
        self.emby = embyserver.Read_EmbyServer()
        self.connectmanager = connectmanager.ConnectManager()

        threading.Thread.__init__(self)
Example #8
0
    def __init__(self):

        self.artwork = artwork.Artwork()
        self.emby = embyserver.Read_EmbyServer()
        self.do_url = downloadutils.DownloadUtils().downloadUrl
        self.should_stop = should_stop

        self.kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2])
        self.direct_path = settings('useDirectPaths') == "1"
        self.content_msg = settings('newContent') == "true"
Example #9
0
    def __init__(self):

        global log
        log = Logging(self.__class__.__name__).log

        self.clientInfo = clientinfo.ClientInfo()
        self.addonName = self.clientInfo.getAddonName()

        self.userid = window('emby_currUser')
        self.server = window('emby_server%s' % self.userid)

        self.emby = embyserver.Read_EmbyServer()
Example #10
0
    def __init__(self):

        self.__dict__ = self._shared_state
        self.monitor = xbmc.Monitor()

        self.clientInfo = clientinfo.ClientInfo()
        self.doUtils = downloadutils.DownloadUtils().downloadUrl
        self.user = userclient.UserClient()
        self.emby = embyserver.Read_EmbyServer()

        self.kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2])

        threading.Thread.__init__(self)
Example #11
0
    def __init__(self, item):

        self.item = item
        self.API = api.API(self.item)

        self.doUtils = downloadutils.DownloadUtils().downloadUrl

        self.userid = window('emby_currUser')
        self.server = window('emby_server%s' % self.userid)

        self.artwork = artwork.Artwork()
        self.emby = embyserver.Read_EmbyServer()
        self.pl = playlist.Playlist()
Example #12
0
    def __init__(self, item):

        self.item = item
        self.API = PlexAPI.API(item)

        self.clientInfo = clientinfo.ClientInfo()
        self.addonName = self.clientInfo.getAddonName()

        self.userid = utils.window('currUserId')
        self.server = utils.window('pms_server')

        self.artwork = artwork.Artwork()
        self.emby = embyserver.Read_EmbyServer()
        self.pl = playlist.Playlist()
Example #13
0
    def __init__(self, item):

        self.item = item
        self.API = api.API(self.item)

        self.clientInfo = clientinfo.ClientInfo()
        self.addonName = self.clientInfo.getAddonName()
        self.doUtils = downloadutils.DownloadUtils().downloadUrl

        self.userid = utils.window('emby_currUser')
        self.server = utils.window('emby_server%s' % self.userid)

        self.artwork = artwork.Artwork()
        self.emby = embyserver.Read_EmbyServer()
        self.pl = playlist.Playlist()
Example #14
0
    def __init__(self, emby_cursor, kodi_cursor):
        self.emby_cursor = emby_cursor
        self.kodi_cursor = kodi_cursor

        self.total_nodes = 0
        self.nodes = list()
        self.playlists = list()
        self.views = list()
        self.sorted_views = list()
        self.grouped_views = list()

        self.video_nodes = VideoNodes()
        self.playlist = Playlist()
        self.emby = embyserver.Read_EmbyServer()
        self.emby_db = embydb.Embydb_Functions(emby_cursor)
Example #15
0
def deleteItem():

    # Serves as a keymap action
    if xbmc.getInfoLabel(
            'ListItem.Property(embyid)'):  # If we already have the embyid
        itemId = xbmc.getInfoLabel('ListItem.Property(embyid)')
    else:
        dbId = xbmc.getInfoLabel('ListItem.DBID')
        itemType = xbmc.getInfoLabel('ListItem.DBTYPE')

        if not itemType:

            if xbmc.getCondVisibility('Container.Content(albums)'):
                itemType = "album"
            elif xbmc.getCondVisibility('Container.Content(artists)'):
                itemType = "artist"
            elif xbmc.getCondVisibility('Container.Content(songs)'):
                itemType = "song"
            elif xbmc.getCondVisibility('Container.Content(pictures)'):
                itemType = "picture"
            else:
                log("Unknown type, unable to proceed.", 1)
                return

        embyconn = utils.kodiSQL('emby')
        embycursor = embyconn.cursor()
        emby_db = embydb.Embydb_Functions(embycursor)
        item = emby_db.getItem_byKodiId(dbId, itemType)
        embycursor.close()

        try:
            embyid = item[0]
        except TypeError:
            log("Unknown embyId, unable to proceed.", 1)
            return

    if settings('skipContextMenu') != "true":
        resp = xbmcgui.Dialog().yesno(heading=lang(29999), line1=lang(33041))
        if not resp:
            log("User skipped deletion for: %s." % itemId, 1)
            return

    embyserver.Read_EmbyServer().deleteItem(itemId)
Example #16
0
import PlexFunctions as PF
import PlexAPI


def logMsg(msg, lvl=1):
    utils.logMsg("%s %s" % ("PlexKodiConnect", "Contextmenu"), msg, lvl)


#Kodi contextmenu item to configure the emby settings
#for now used to set ratings but can later be used to sync individual items etc.
if __name__ == '__main__':
    itemid = utils.tryDecode(xbmc.getInfoLabel("ListItem.DBID"))
    itemtype = utils.tryDecode(xbmc.getInfoLabel("ListItem.DBTYPE"))

    emby = embyserver.Read_EmbyServer()

    plexid = ""
    if not itemtype and xbmc.getCondVisibility("Container.Content(albums)"):
        itemtype = "album"
    if not itemtype and xbmc.getCondVisibility("Container.Content(artists)"):
        itemtype = "artist"
    if not itemtype and xbmc.getCondVisibility("Container.Content(songs)"):
        itemtype = "song"
    if not itemtype and xbmc.getCondVisibility("Container.Content(pictures)"):
        itemtype = "picture"

    if (not itemid or itemid
            == "-1") and xbmc.getInfoLabel("ListItem.Property(plexid)"):
        plexid = xbmc.getInfoLabel("ListItem.Property(plexid)")
    else:
Example #17
0
def BrowseContent(viewname, type="", folderid=""):
    
    emby = embyserver.Read_EmbyServer()
    art = artwork.Artwork()
    doUtils = downloadutils.DownloadUtils()
    
    #folderid used as filter ?
    if folderid in ["recent","recentepisodes","inprogress","inprogressepisodes","unwatched","nextepisodes","sets","genres","random","recommended"]:
        filter = folderid
        folderid = ""
    else:
        filter = ""
    
    xbmcplugin.setPluginCategory(int(sys.argv[1]), viewname)
    #get views for root level
    if not folderid:
        views = emby.getViews(type)
        for view in views:
            if view.get("name") == viewname.decode('utf-8'):
                folderid = view.get("id")
    
    utils.logMsg("BrowseContent","viewname: %s - type: %s - folderid: %s - filter: %s" %(viewname.decode('utf-8'), type.decode('utf-8'), folderid.decode('utf-8'), filter.decode('utf-8')))
    #set the correct params for the content type
    #only proceed if we have a folderid
    if folderid:
        if type.lower() == "homevideos":
            xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
            itemtype = "Video,Folder,PhotoAlbum"
        elif type.lower() == "photos":
            xbmcplugin.setContent(int(sys.argv[1]), 'files')
            itemtype = "Photo,PhotoAlbum,Folder"
        else:
            itemtype = ""
        
        #get the actual listing
        if type == "recordings":
            listing = emby.getTvRecordings(folderid)
        elif type == "tvchannels":
            listing = emby.getTvChannels()
        elif filter == "recent":
            listing = emby.getFilteredSection(folderid, itemtype=itemtype.split(",")[0], sortby="DateCreated", recursive=True, limit=25, sortorder="Descending")
        elif filter == "random":
            listing = emby.getFilteredSection(folderid, itemtype=itemtype.split(",")[0], sortby="Random", recursive=True, limit=150, sortorder="Descending")
        elif filter == "recommended":
            listing = emby.getFilteredSection(folderid, itemtype=itemtype.split(",")[0], sortby="SortName", recursive=True, limit=25, sortorder="Ascending", filter="IsFavorite")
        elif filter == "sets":
            listing = emby.getFilteredSection(folderid, itemtype=itemtype.split(",")[1], sortby="SortName", recursive=True, limit=25, sortorder="Ascending", filter="IsFavorite")
        else:
            listing = emby.getFilteredSection(folderid, itemtype=itemtype, recursive=False)
        
        #process the listing
        if listing:
            for item in listing.get("Items"):
                li = createListItemFromEmbyItem(item,art,doUtils)
                if item.get("IsFolder") == True:
                    #for folders we add an additional browse request, passing the folderId
                    path = "%s?id=%s&mode=browsecontent&type=%s&folderid=%s" % (sys.argv[0].decode('utf-8'), viewname.decode('utf-8'), type.decode('utf-8'), item.get("Id").decode('utf-8'))
                    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=path, listitem=li, isFolder=True)
                else:
                    #playable item, set plugin path and mediastreams
                    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=li.getProperty("path"), listitem=li)


    if filter == "recent":
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
    else:
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE)
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RATING)
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)

    xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
Example #18
0
def doPlayback(itemid, dbid):

    emby = embyserver.Read_EmbyServer()
    item = emby.getItem(itemid)
    pbutils.PlaybackUtils(item).play(itemid, dbid)
Example #19
0
 def __init__(self):
     self.emby = embyserver.Read_EmbyServer()
Example #20
0
    def __init__(self, *args, **kwargs):

        self.emby = embyserver.Read_EmbyServer()
        xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
Example #21
0
    def __init__(self):
        self.userid = utils.window('currUserId')
        self.server = utils.window('pms_server')

        self.emby = embyserver.Read_EmbyServer()
Example #22
0
def getAdditionalSongTags(embyid, emby_rating, API, kodicursor, emby_db, enableimportsongrating, enableexportsongrating, enableupdatesongrating):
    
    emby = embyserver.Read_EmbyServer()

    previous_values = None
    filename = API.get_file_path()
    rating = 0
    emby_rating = int(round(emby_rating, 0))
    
    #get file rating and comment tag from file itself.
    if enableimportsongrating:
        file_rating, comment, hasEmbeddedCover = getSongTags(filename)
    else: 
        file_rating = 0
        comment = ""
        hasEmbeddedCover = False
        

    emby_dbitem = emby_db.getItem_byId(embyid)
    try:
        kodiid = emby_dbitem[0]
    except TypeError:
        # Item is not in database.
        currentvalue = None
    else:
        query = "SELECT rating FROM song WHERE idSong = ?"
        kodicursor.execute(query, (kodiid,))
        try:
            currentvalue = int(round(float(kodicursor.fetchone()[0]),0))
        except: currentvalue = None
    
    # Only proceed if we actually have a rating from the file
    if file_rating is None and currentvalue:
        return (currentvalue, comment, False)
    elif file_rating is None and not currentvalue:
        return (emby_rating, comment, False)
    
    log.info("getAdditionalSongTags --> embyid: %s - emby_rating: %s - file_rating: %s - current rating in kodidb: %s" %(embyid, emby_rating, file_rating, currentvalue))
    
    updateFileRating = False
    updateEmbyRating = False

    if currentvalue != None:
        # we need to translate the emby values...
        if emby_rating == 1 and currentvalue == 2:
            emby_rating = 2
        if emby_rating == 3 and currentvalue == 4:
            emby_rating = 4
            
        #if updating rating into file is disabled, we ignore the rating in the file...
        if not enableupdatesongrating:
            file_rating = currentvalue
        #if convert emby likes/favourites convert to song rating is disabled, we ignore the emby rating...
        if not enableexportsongrating:
            emby_rating = currentvalue
            
        if (emby_rating == file_rating) and (file_rating != currentvalue):
            #the rating has been updated from kodi itself, update change to both emby ands file
            rating = currentvalue
            updateFileRating = True
            updateEmbyRating = True
        elif (emby_rating != currentvalue) and (file_rating == currentvalue):
            #emby rating changed - update the file
            rating = emby_rating
            updateFileRating = True  
        elif (file_rating != currentvalue) and (emby_rating == currentvalue):
            #file rating was updated, sync change to emby
            rating = file_rating
            updateEmbyRating = True
        elif (emby_rating != currentvalue) and (file_rating != currentvalue):
            #both ratings have changed (corner case) - the highest rating wins...
            if emby_rating > file_rating:
                rating = emby_rating
                updateFileRating = True
            else:
                rating = file_rating
                updateEmbyRating = True
        else:
            #nothing has changed, just return the current value
            rating = currentvalue
    else:      
        # no rating yet in DB
        if enableimportsongrating:
            #prefer the file rating
            rating = file_rating
            #determine if we should also send the rating to emby server
            if enableexportsongrating:
                if emby_rating == 1 and file_rating == 2:
                    emby_rating = 2
                if emby_rating == 3 and file_rating == 4:
                    emby_rating = 4
                if emby_rating != file_rating:
                    updateEmbyRating = True
                
        elif enableexportsongrating:
            #set the initial rating to emby value
            rating = emby_rating
        
    if updateFileRating and enableupdatesongrating:
        updateRatingToFile(rating, filename)
        
    if updateEmbyRating and enableexportsongrating:
        # sync details to emby server. Translation needed between ID3 rating and emby likes/favourites:
        like, favourite, deletelike = getEmbyRatingFromKodiRating(rating)
        window("ignore-update-%s" %embyid, "true") #set temp windows prop to ignore the update from webclient update
        emby.updateUserRating(embyid, favourite)
    
    return (rating, comment, hasEmbeddedCover)