コード例 #1
0
ファイル: Entrypoint.py プロジェクト: Misty27/Emby.Kodi
def getThemeMedia():

    doUtils = DownloadUtils()
    playUtils = PlayUtils()

    currUser = WINDOW.getProperty('currUser')
    server = WINDOW.getProperty('server%s' % currUser)
    playback = None

    library = xbmc.translatePath(
        "special://profile/addon_data/plugin.video.emby/library/").decode(
            'utf-8')

    # Choose playback method
    resp = xbmcgui.Dialog().select("Choose playback method for your themes",
                                   ["Direct Play", "Direct Stream"])
    if resp == 0:
        # Direct Play
        playback = "DirectPlay"
    elif resp == 1:
        # Direct Stream
        playback = "DirectStream"
    else:
        return

    # Set custom path for user
    tvtunes_path = xbmc.translatePath(
        "special://profile/addon_data/script.tvtunes/").decode('utf-8')
    if xbmcvfs.exists(tvtunes_path):
        tvtunes = xbmcaddon.Addon(id="script.tvtunes")
        tvtunes.setSetting('custom_path_enable', "true")
        tvtunes.setSetting('custom_path', library)
        xbmc.log("TV Tunes custom path is enabled and set.")
    else:
        # if it does not exist this will not work so warn user, often they need to edit the settings first for it to be created.
        dialog = xbmcgui.Dialog()
        dialog.ok(
            'Warning',
            'The settings file does not exist in tvtunes. Go to the tvtunes addon and change a setting, then come back and re-run'
        )
        return

    # Create library directory
    if not xbmcvfs.exists(library):
        xbmcvfs.mkdir(library)

    # Get every user view Id
    userViews = []
    url = "{server}/mediabrowser/Users/{UserId}/Items?format=json"
    result = doUtils.downloadUrl(url)

    for view in result[u'Items']:
        userviewId = view[u'Id']
        userViews.append(userviewId)

    # Get Ids with Theme Videos
    itemIds = {}
    for view in userViews:
        url = "{server}/mediabrowser/Users/{UserId}/Items?HasThemeVideo=True&ParentId=%s&format=json" % view
        result = doUtils.downloadUrl(url)
        if result[u'TotalRecordCount'] != 0:
            for item in result[u'Items']:
                itemId = item[u'Id']
                folderName = item[u'Name']
                folderName = utils.normalize_string(folderName.encode('utf-8'))
                itemIds[itemId] = folderName

    # Get paths for theme videos
    for itemId in itemIds:
        nfo_path = xbmc.translatePath(
            "special://profile/addon_data/plugin.video.emby/library/%s/" %
            itemIds[itemId])
        # Create folders for each content
        if not xbmcvfs.exists(nfo_path):
            xbmcvfs.mkdir(nfo_path)
        # Where to put the nfos
        nfo_path = "%s%s" % (nfo_path, "tvtunes.nfo")

        url = "{server}/mediabrowser/Items/%s/ThemeVideos?format=json" % itemId
        result = doUtils.downloadUrl(url)

        # Create nfo and write themes to it
        nfo_file = open(nfo_path, 'w')
        pathstowrite = ""
        # May be more than one theme
        for theme in result[u'Items']:
            if playback == "DirectPlay":
                playurl = playUtils.directPlay(theme)
            else:
                playurl = playUtils.directStream(result, server, theme[u'Id'],
                                                 "ThemeVideo")
            pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))

        # Check if the item has theme songs and add them
        url = "{server}/mediabrowser/Items/%s/ThemeSongs?format=json" % itemId
        result = doUtils.downloadUrl(url)

        # May be more than one theme
        for theme in result[u'Items']:
            if playback == "DirectPlay":
                playurl = playUtils.directPlay(theme)
            else:
                playurl = playUtils.directStream(result, server, theme[u'Id'],
                                                 "Audio")
            pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))

        nfo_file.write('<tvtunes>%s</tvtunes>' % pathstowrite)
        # Close nfo file
        nfo_file.close()

    # Get Ids with Theme songs
    musicitemIds = {}
    for view in userViews:
        url = "{server}/mediabrowser/Users/{UserId}/Items?HasThemeSong=True&ParentId=%s&format=json" % view
        result = doUtils.downloadUrl(url)
        if result[u'TotalRecordCount'] != 0:
            for item in result[u'Items']:
                itemId = item[u'Id']
                folderName = item[u'Name']
                folderName = utils.normalize_string(folderName.encode('utf-8'))
                musicitemIds[itemId] = folderName

    # Get paths
    for itemId in musicitemIds:

        # if the item was already processed with video themes back out
        if itemId in itemIds:
            continue

        nfo_path = xbmc.translatePath(
            "special://profile/addon_data/plugin.video.emby/library/%s/" %
            musicitemIds[itemId])
        # Create folders for each content
        if not xbmcvfs.exists(nfo_path):
            xbmcvfs.mkdir(nfo_path)
        # Where to put the nfos
        nfo_path = "%s%s" % (nfo_path, "tvtunes.nfo")

        url = "{server}/mediabrowser/Items/%s/ThemeSongs?format=json" % itemId
        result = doUtils.downloadUrl(url)

        # Create nfo and write themes to it
        nfo_file = open(nfo_path, 'w')
        pathstowrite = ""
        # May be more than one theme
        for theme in result[u'Items']:
            if playback == "DirectPlay":
                playurl = playUtils.directPlay(theme)
            else:
                playurl = playUtils.directStream(result, server, theme[u'Id'],
                                                 "Audio")
            pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))

        nfo_file.write('<tvtunes>%s</tvtunes>' % pathstowrite)
        # Close nfo file
        nfo_file.close()
コード例 #2
0
ファイル: Entrypoint.py プロジェクト: goofwear/Emby.Kodi
def getThemeMedia():

    doUtils = DownloadUtils()
    playUtils = PlayUtils()
    
    currUser = WINDOW.getProperty('currUser')
    server = WINDOW.getProperty('server%s' % currUser)
    playback = None

    library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/").decode('utf-8')

    # Choose playback method
    resp = xbmcgui.Dialog().select("Choose playback method for your themes", ["Direct Play", "Direct Stream"])
    if resp == 0:
        # Direct Play
        playback = "DirectPlay"
    elif resp == 1:
        # Direct Stream
        playback = "DirectStream"
    else:return

    # Set custom path for user
    tvtunes_path = xbmc.translatePath("special://profile/addon_data/script.tvtunes/").decode('utf-8')
    if xbmcvfs.exists(tvtunes_path):
        tvtunes = xbmcaddon.Addon(id="script.tvtunes")
        tvtunes.setSetting('custom_path_enable', "true")
        tvtunes.setSetting('custom_path', library)
        xbmc.log("TV Tunes custom path is enabled and set.")
    else:
        # if it does not exist this will not work so warn user, often they need to edit the settings first for it to be created.
        dialog = xbmcgui.Dialog()
        dialog.ok('Warning', 'The settings file does not exist in tvtunes. Go to the tvtunes addon and change a setting, then come back and re-run')
        return
        

    # Create library directory
    if not xbmcvfs.exists(library):
        xbmcvfs.mkdir(library)

    # Get every user view Id
    userViews = []
    url = "{server}/mediabrowser/Users/{UserId}/Items?format=json"
    result = doUtils.downloadUrl(url)
    
    for view in result[u'Items']:
        userviewId = view[u'Id']
        userViews.append(userviewId)


    # Get Ids with Theme Videos
    itemIds = {}
    for view in userViews:
        url = "{server}/mediabrowser/Users/{UserId}/Items?HasThemeVideo=True&ParentId=%s&format=json" % view
        result = doUtils.downloadUrl(url)
        if result[u'TotalRecordCount'] != 0:
            for item in result[u'Items']:
                itemId = item[u'Id']
                folderName = item[u'Name']
                folderName = utils.normalize_string(folderName.encode('utf-8'))
                itemIds[itemId] = folderName

    # Get paths for theme videos
    for itemId in itemIds:
        nfo_path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/%s/" % itemIds[itemId])
        # Create folders for each content
        if not xbmcvfs.exists(nfo_path):
            xbmcvfs.mkdir(nfo_path)
        # Where to put the nfos
        nfo_path = "%s%s" % (nfo_path, "tvtunes.nfo")

        url = "{server}/mediabrowser/Items/%s/ThemeVideos?format=json" % itemId
        result = doUtils.downloadUrl(url)

        # Create nfo and write themes to it
        nfo_file = open(nfo_path, 'w')
        pathstowrite = ""
        # May be more than one theme
        for theme in result[u'Items']:  
            if playback == "DirectPlay":
                playurl = playUtils.directPlay(theme)
            else:
                playurl = playUtils.directStream(result, server, theme[u'Id'], "ThemeVideo")
            pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))
        
        # Check if the item has theme songs and add them   
        url = "{server}/mediabrowser/Items/%s/ThemeSongs?format=json" % itemId
        result = doUtils.downloadUrl(url)

        # May be more than one theme
        for theme in result[u'Items']:  
            if playback == "DirectPlay":
                playurl = playUtils.directPlay(theme)
            else:
                playurl = playUtils.directStream(result, server, theme[u'Id'], "Audio")
            pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))

        nfo_file.write(
            '<tvtunes>%s</tvtunes>' % pathstowrite
        )
        # Close nfo file
        nfo_file.close()

    # Get Ids with Theme songs
    musicitemIds = {}
    for view in userViews:
        url = "{server}/mediabrowser/Users/{UserId}/Items?HasThemeSong=True&ParentId=%s&format=json" % view
        result = doUtils.downloadUrl(url)
        if result[u'TotalRecordCount'] != 0:
            for item in result[u'Items']:
                itemId = item[u'Id']
                folderName = item[u'Name']
                folderName = utils.normalize_string(folderName.encode('utf-8'))
                musicitemIds[itemId] = folderName

    # Get paths
    for itemId in musicitemIds:
        
        # if the item was already processed with video themes back out
        if itemId in itemIds:
            continue
        
        nfo_path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/%s/" % musicitemIds[itemId])
        # Create folders for each content
        if not xbmcvfs.exists(nfo_path):
            xbmcvfs.mkdir(nfo_path)
        # Where to put the nfos
        nfo_path = "%s%s" % (nfo_path, "tvtunes.nfo")
        
        url = "{server}/mediabrowser/Items/%s/ThemeSongs?format=json" % itemId
        result = doUtils.downloadUrl(url)

        # Create nfo and write themes to it
        nfo_file = open(nfo_path, 'w')
        pathstowrite = ""
        # May be more than one theme
        for theme in result[u'Items']:  
            if playback == "DirectPlay":
                playurl = playUtils.directPlay(theme)
            else:
                playurl = playUtils.directStream(result, server, theme[u'Id'], "Audio")
            pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))

        nfo_file.write(
            '<tvtunes>%s</tvtunes>' % pathstowrite
        )
        # Close nfo file
        nfo_file.close()
コード例 #3
0
ファイル: Entrypoint.py プロジェクト: stagenal/Emby.Kodi
def getThemeMedia():

    doUtils = DownloadUtils()
    playUtils = PlayUtils()
    
    currUser = WINDOW.getProperty('currUser')
    server = WINDOW.getProperty('server%s' % currUser)
    playback = None

    library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/")

    # Choose playback method
    resp = xbmcgui.Dialog().select("Choose playback method for your themes", ["Direct Play", "Direct Stream"])
    if resp == 0:
        # Direct Play
        playback = "DirectPlay"
    elif resp == 1:
        # Direct Stream
        playback = "DirectStream"
    else:return

    # Create library directory
    if not xbmcvfs.exists(library):
        xbmcvfs.mkdir(library)

    # Get every user view Id
    userViews = []
    url = "{server}/mediabrowser/Users/{UserId}/Items?format=json"
    result = doUtils.downloadUrl(url)
    
    for view in result[u'Items']:
        userviewId = view[u'Id']
        userViews.append(userviewId)

    # Get Ids with Theme songs
    itemIds = {}
    for view in userViews:
        url = "{server}/mediabrowser/Users/{UserId}/Items?HasThemeSong=True&ParentId=%s&format=json" % view
        result = doUtils.downloadUrl(url)
        if result[u'TotalRecordCount'] != 0:
            for item in result[u'Items']:
                itemId = item[u'Id']
                folderName = item[u'Name']
                itemIds[itemId] = folderName

    # Get paths
    for itemId in itemIds:
        nfo_path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/%s/" % itemIds[itemId])
        # Create folders for each content
        if not xbmcvfs.exists(nfo_path):
            xbmcvfs.mkdir(nfo_path)
        # Where to put the nfos
        nfo_path = "%s%s" % (nfo_path, "tvtunes.nfo")

        url = "{server}/mediabrowser/Items/%s/ThemeSongs?format=json" % itemId
        result = doUtils.downloadUrl(url)

        # Create nfo and write themes to it
        nfo_file = open(nfo_path, 'w')
        pathstowrite = ""
        # May be more than one theme
        for theme in result[u'Items']:  
            if playback == "DirectPlay":
                playurl = playUtils.directPlay(theme)
            else:
                playurl = playUtils.directStream(result, server, theme[u'Id'], "Audio")
            pathstowrite += ('<file>%s</file>' % playurl)

        nfo_file.write(
            '<tvtunes>%s</tvtunes>' % pathstowrite
        )
        # Close nfo file
        nfo_file.close()