Exemple #1
0
def xhr_xbmcmm_set_episode(episodeid):
    xbmc = jsonrpclib.Server(server_api_address())
    print 'here'
    try:
        params = {
            'episodeid': episodeid,
            'title': request.form['title'],
            'plot': request.form['plot'],
            'firstaired': request.form['firstaired'],
            'rating': float(request.form['rating']),
            'votes': request.form['votes'],
            'director': str2lst(request.form['director']),
            'writer': str2lst(request.form['writer']),
        }

        # Only set artwork if it exists
        if request.form['thumb']:
            params['art'] = {'thumb': request.form['thumb']}

        # Check playcount
        if 'playcount' in request.form:
            params['playcount'] = 1
        else:
            params['playcount'] = 0

    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error='Invalid parameters.')

    try:
        xbmc.VideoLibrary.SetEpisodeDetails(**params)
        return jsonify(status='Episode details successfully changed.')
    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)
Exemple #2
0
def xhr_tvdb_episode(tvshowid, season, episode_number):
    xbmc = jsonrpclib.Server(server_api_address())
    t = tvdb_api.Tvdb(apikey=tvdb_apikey)

    show = xbmc.VideoLibrary.GetTVShowDetails(tvshowid=tvshowid, properties=['imdbnumber'])['tvshowdetails']

    if show['imdbnumber'] and show['imdbnumber'].isdigit():
        logger.log('TVDB :: Grabbing episode info based on TVBD ID', 'INFO')
        try:
            episode = t[int(show['imdbnumber'])][season][episode_number]
        except tvdb_exceptions.tvdb_shownotfound:
            return tvdb_except('notfound', show['label'])

        except tvdb_exceptions.tvdb_error:
            return tvdb_except('noconnect', show['label'])

    else:
        logger.log('TVDB :: No TVDB ID supplied. Searching using title', 'WARNING')
        try:
            episode = t[show['label']][season][episode_number]
        except tvdb_exceptions.tvdb_shownotfound:
            return tvdb_except('notfound', show['label'])

        except tvdb_exceptions.tvdb_error:
            return tvdb_except('noconnect', show['label'])

    title = '%s - %02dx%02d' % (show['label'], season, episode_number)

    return render_template('xbmcmm/modals/tvdb_episode_info.html',
        title=title,
        episode=tvdb_str2list(episode=episode)
    )
Exemple #3
0
def xhr_xbmcmm_set_movie(movieid):
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        params = {
            'movieid': movieid,
            'title': request.form['title'],
            'originaltitle': request.form['originaltitle'],
            'sorttitle': request.form['sorttitle'],
            'plot': request.form['plot'],
            'year': int(request.form['year']),
            'rating': float(request.form['rating']),
            'genre': str2lst(request.form['genre']),
            'director': str2lst(request.form['director']),
            'mpaa': request.form['mpaa'],
            'studio': str2lst(request.form['studio']),
            'tagline': request.form['tagline'],
            'set': request.form['set'],
            'tag': str2lst(request.form['tag']),
            'trailer': request.form['trailer'],
            'writer': str2lst(request.form['writer']),
            'runtime': int(request.form['runtime']),
            'votes': request.form['votes'],
        }

        # Only set artwork if it exists
        art = {}
        if request.form['poster']:
            art['poster'] = request.form['poster']
        if request.form['fanart']:
            art['fanart'] = request.form['fanart']
        if request.form['banner']:
            art['banner'] = request.form['banner']
        if request.form['discart']:
            art['discart'] = request.form['discart']
        if request.form['clearart']:
            art['clearart'] = request.form['clearart']
        if request.form['clearlogo']:
            art['clearlogo'] = request.form['clearlogo']

        if art:
            params['art'] = art

        # Check playcount
        if 'playcount' in request.form:
            params['playcount'] = 1
        else:
            params['playcount'] = 0

    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error='Invalid parameters.')

    try:
        xbmc.VideoLibrary.SetMovieDetails(**params)
        return jsonify(status='Movie details successfully changed.')

    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)
Exemple #4
0
def xhr_library_transcode(type, id):
    logger.log('TRANSCODE :: Transcoding %s' % type, 'INFO')
    xbmc = jsonrpclib.Server(server_api_address())

    script_type = 'movie'
    show_title = 'none'
    try:    
        if type == 'movie':
            library = xbmc_get_details(xbmc,'movie',id)
            path = library['file'][30:]
            title = library['title']
        elif type == 'episode':
            library = xbmc_get_details(xbmc,'episode',id)
            path = library['file'][30:]
            title = library['title']
            script_type = 'TV'
            show_title = library['showtitle']
    except:
        logger.log('TRANSCODE :: ERROR','ERROR')
        return jsonify(result=False)

    path = '/data' + path
    os.system('python /home/rob/Scripts/move_video.py -f "' + path + '" -c "' + script_type + '" -s "' + show_title + '" &')

    return jsonify(result=True,title=title,file=path)
Exemple #5
0
def xhr_library_resume_check(type, id):
    logger.log('LIBRARY :: Checking if %s has resume position' % type, 'INFO')
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        if type == 'movie':
            library = xbmc.VideoLibrary.GetMovieDetails(movieid=id,
                                                        properties=['resume'])

        elif type == 'episode':
            library = xbmc.VideoLibrary.GetEpisodeDetails(
                episodeid=id, properties=['resume'])

    except:
        logger.log('LIBRARY :: %s' % xbmc_error, 'ERROR')
        return render_library(message=xbmc_error)

    position = library[type + 'details']['resume']['position']

    if position:
        position = format_seconds(position)

        template = render_template('dialogs/library-resume_dialog.html',
                                   position=position,
                                   library=library)
        return jsonify(resume=True, template=template)
    else:
        return jsonify(resume=False, template=None)
Exemple #6
0
def xhr_xbmcmm_episode_details(id):
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        item = xbmc.VideoLibrary.GetEpisodeDetails(episodeid=id, properties=episode_properties)['episodedetails']
    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)

    return render_template('/xbmcmm/tvshow-episode.html',
        episode=lst2str(item)
    )
Exemple #7
0
def xhr_xbmcmm_set_tvshow(tvshowid):
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        params = {
            'tvshowid': tvshowid,
            'title': request.form['title'],
            'originaltitle': request.form['originaltitle'],
            'sorttitle': request.form['sorttitle'],
            'plot': request.form['plot'],
            'rating': float(request.form['rating']),
            'genre': str2lst(request.form['genre']),
            'premiered': request.form['premiered'],
            'mpaa': request.form['mpaa'],
            'studio': str2lst(request.form['studio']),
            'votes': request.form['votes'],
            'tag': str2lst(request.form['tag']),
        }

        # Only set artwork if it exists
        art = {}
        if request.form['poster']:
            art['poster'] = request.form['poster']
        if request.form['fanart']:
            art['fanart'] = request.form['fanart']
        if request.form['banner']:
            art['banner'] = request.form['banner']
        if request.form['clearart']:
            art['clearart'] = request.form['clearart']
        if request.form['clearlogo']:
            art['clearlogo'] = request.form['clearlogo']
        if request.form['characterart']:
            art['characterart'] = request.form['characterart']
        if request.form['landscape']:
            art['landscape'] = request.form['landscape']

        if art:
            params['art'] = art

    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error='Invalid parameters.')

    try:
        xbmc.VideoLibrary.SetTVShowDetails(**params)
        return jsonify(status='TV show details successfully changed.')
    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)
Exemple #8
0
def xbmc_media_list(type):
    try:
        xbmc = jsonrpclib.Server(server_api_address())
    except Exception as e:
        xbmcmm_except(e)
        return False

    sort = {'method': 'label', 'ignorearticle': True}

    if type == 'movies':
        return xbmc.VideoLibrary.GetMovies(sort=sort)
    elif type == 'moviesets':
        return xbmc.VideoLibrary.GetMovieSets(sort=sort)
    else:
        return xbmc.VideoLibrary.GetTVShows(sort=sort)
Exemple #9
0
def xhr_xbmcmm_season_details(id, season):
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        item = xbmc.VideoLibrary.GetEpisodes(
            tvshowid=id,
            season=season,
            sort={'method': 'episode'},
            properties=['tvshowid', 'season', 'showtitle', 'episode']
        )
    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)

    return render_template('/xbmcmm/tvshow-season.html',
        item=item
    )
Exemple #10
0
def xhr_xbmcmm_movie_details(id):
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        item = xbmc.VideoLibrary.GetMovieDetails(movieid=id, properties=movie_properties)
    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)

    try:
        item['sets'] = xbmc.VideoLibrary.GetMovieSets(sort={'method': 'label'})['sets']
    except:
        item['sets'] = []

    item['moviedetails'] = lst2str(item['moviedetails'])

    return render_template('/xbmcmm/movie.html',
        item=item
    )
Exemple #11
0
def xhr_xbmcmm_show_details(id):
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        item = xbmc.VideoLibrary.GetTVShowDetails(tvshowid=id, properties=show_properties)
        try:
            seasons = xbmc.VideoLibrary.GetSeasons(tvshowid=id, sort={'method': 'label'}, properties=season_properties)['seasons']
        except:
            seasons = {}
    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)

    item['seasons'] = seasons

    item['tvshowdetails'] = lst2str(item['tvshowdetails'])

    return render_template('/xbmcmm/tvshow-base.html',
        item=item
    )
Exemple #12
0
def xhr_xbmcmm_get_tags(media):
    xbmc = jsonrpclib.Server(server_api_address())
    tags = []
    if media == 'movie':
        media_list = xbmc.VideoLibrary.GetMovies(properties=['tag'])['movies']
    elif media == 'tvshow':
        media_list = xbmc.VideoLibrary.GetTVShows(properties=['tag'])['tvshows']

    for x in media_list:
        if x['tag']:
            for y in x['tag']:
                if y not in tags:
                    tags.append(y)

    existing = [x.strip() for x in request.form['exist'].split('/') if x != '']

    return render_template('xbmcmm/modals/tags.html',
        existing=existing,
        tags=sorted(tags)
    )
Exemple #13
0
def xhr_xbmcmm_get_genres(file_type, media):
    xbmc = jsonrpclib.Server(server_api_address())

    genres = video_genres

    try:
        xbmc_genres = xbmc.VideoLibrary.GetGenres(type=media)['genres']
    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)

    for genre in xbmc_genres:
        if not genre['label'] in genres:
            genres.append(genre['label'])

    existing = [x.strip() for x in request.form['exist'].split('/') if x != '']

    return render_template('xbmcmm/modals/genres.html',
        existing=existing,
        genres=sorted(genres)
    )
Exemple #14
0
def xhr_xbmcmm_movieset_details(id):
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        if id == 0:
            movieset = {'setid': 0, 'label': 'New Set', 'movies': []}
        else:
            movieset = xbmc.VideoLibrary.GetMovieSetDetails(setid=id)['setdetails']
        movies = xbmc.VideoLibrary.GetMovies(
            sort={'method': 'label', 'ignorearticle': True},
            properties=['set']
        )['movies']

    except Exception as e:
        xbmcmm_except(e)
        return jsonify(error=xbmc_error)

    return render_template('/xbmcmm/movieset.html',
        movieset=movieset,
        movies=movies
    )
Exemple #15
0
def xhr_library_resume_check(type, id):
    logger.log("LIBRARY :: Checking if %s has resume position" % type, "INFO")
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        if type == "movie":
            library = xbmc.VideoLibrary.GetMovieDetails(movieid=id, properties=["resume"])

        elif type == "episode":
            library = xbmc.VideoLibrary.GetEpisodeDetails(episodeid=id, properties=["resume"])

    except:
        logger.log("LIBRARY :: %s" % xbmc_error, "ERROR")
        return render_library(message=xbmc_error)

    position = library[type + "details"]["resume"]["position"]

    if position:
        position = format_seconds(position)

        template = render_template("dialogs/library-resume_dialog.html", position=position, library=library)
        return jsonify(resume=True, template=template)
    else:
        return jsonify(resume=False, template=None)
Exemple #16
0
def xhr_library_resume_check(type, id):
    logger.log('LIBRARY :: Checking if %s has resume position' % type, 'INFO')
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        if type == 'movie':
            library = xbmc.VideoLibrary.GetMovieDetails(movieid=id, properties=['resume'])

        elif type == 'episode':
            library = xbmc.VideoLibrary.GetEpisodeDetails(episodeid=id, properties=['resume'])

    except:
        logger.log('LIBRARY :: %s' % xbmc_error, 'ERROR')
        return render_library(message=xbmc_error)

    position = library[type + 'details']['resume']['position']

    if position:
        position = format_seconds(position)

        template = render_template('dialogs/library-resume_dialog.html', position=position, library=library)
        return jsonify(resume=True, template=template)
    else:
        return jsonify(resume=False, template=None)
Exemple #17
0
def xhr_xbmcmm_modify_set(action, movieid=None):
    xbmc = jsonrpclib.Server(server_api_address())

    try:
        if request.method == 'GET':
            params = {'movieid': movieid}

            if action == 'add':
                params['set'] = request.args['setlabel']
            else:
                params['set'] = ''

            xbmc.VideoLibrary.SetMovieDetails(**params)

        else:
            for movieid in request.form.getlist('movies[]'):
                params = {'movieid': int(movieid)}

                if action == 'rename':
                    params['set'] = request.form['setlabel']
                else:
                    params['set'] = ''

                xbmc.VideoLibrary.SetMovieDetails(**params)

        if action == 'add' or action == 'rename':
            movies = xbmc.VideoLibrary.GetMovies(properties=['set', 'setid'])['movies']
            setid = [x['setid'] for x in movies if x['set'] == params['set']][0]

            return jsonify(success=True, setid=setid)

        return jsonify(success=True)

    except Exception as e:
        xbmcmm_except(e)
        return jsonify(failed=True)
Exemple #18
0
def xhr_xbmc_library_media(media_type=None):
    global back_id
    path = None
    back_path = "/"
    library = None

    if not server_api_address():
        logger.log("LIBRARY :: No XBMC server defined", "ERROR")
        return render_xbmc_library(message="You need to configure XBMC server settings first.")

    try:
        # Reset back positions when rendering home
        if not media_type:
            back_id = {}

            return render_xbmc_library()

        xbmc = jsonrpclib.Server(server_api_address())
        template = "library/media.html"

        # MOVIES
        if media_type == "movies":
            file_type = "video"

            if "movieid" in request.args:  # Movie details
                movieid = request.args["movieid"]
                back_id["movies"] = movieid
                library = xbmc_get_details(xbmc, "movie", int(movieid))
                template = "library/details.html"
                title = "%s (%s)" % (library["label"], library["year"])
                if "setid" in request.args:
                    back_path = "/movies?setid=%s" % request.args["setid"]
                else:
                    back_path = "/movies"

            elif "setid" in request.args:  # Movie set
                setid = request.args["setid"]
                back_id["movies"] = "set" + setid
                library = xbmc_get_moviesets(xbmc, int(setid))
                title = library[0]["set"]
                path = "/movies?setid=%s" % setid
                back_path = "/movies"

            else:
                library = xbmc_get_movies(xbmc)
                title = "Movies"
                path = "/movies"

        # TVSHOWS
        elif media_type == "tvshows":
            file_type = "video"

            if "tvshowid" in request.args:  # TV show details
                tvshowid = request.args["tvshowid"]
                back_id["tvshows"] = tvshowid
                library = xbmc_get_details(xbmc, "tvshow", int(tvshowid))
                template = "library/details.html"
                title = library["label"]
                path = "/tvshows?tvshowid=%s" % tvshowid
                back_path = "/tvshows"

            else:
                library = xbmc_get_tvshows(xbmc)
                title = "TV Shows"
                path = "/tvshows"

        elif media_type == "seasons":
            file_type = "video"
            tvshowid = request.args["tvshowid"]
            back_id["tvshows"] = tvshowid
            library = xbmc_get_seasons(xbmc, int(tvshowid))
            title = library[0]["showtitle"]
            path = "/seasons?tvshowid=%s" % tvshowid
            back_path = "/tvshows"

        elif media_type == "episodes":
            file_type = "video"
            tvshowid = request.args["tvshowid"]
            season = request.args["season"]
            back_id["tvshows"] = tvshowid
            back_id["seasons"] = season
            path = "/episodes?tvshowid=%s&season=%s" % (tvshowid, season)

            if "episodeid" in request.args:  # Episode details
                episodeid = request.args["episodeid"]
                back_id["episodes"] = episodeid
                library = xbmc_get_details(xbmc, "episode", int(episodeid))
                template = "library/details.html"
                title = library["label"]
                back_path = path

            else:
                library = xbmc_get_episodes(xbmc, int(tvshowid), int(season))
                title = "%s - Season %s" % (library[0]["showtitle"], library[0]["season"])
                back_path = "/seasons?tvshowid=%s" % tvshowid

        # MUSIC
        elif media_type == "artists":
            file_type = "audio"

            if "artistid" in request.args:  # Artist details
                artistid = request.args["artistid"]
                back_id["artists"] = artistid
                library = xbmc_get_details(xbmc, "artist", int(artistid))
                template = "library/details.html"
                title = library["label"]
                back_path = "/artists"

            else:
                library = xbmc_get_artists(xbmc)
                title = "Artists"
                path = "/artists"

        elif media_type == "albums":
            file_type = "audio"
            artistid = request.args["artistid"]
            back_id["artists"] = artistid
            path = "/albums?artistid=%s" % artistid

            if "albumid" in request.args:  # Album details
                albumid = request.args["albumid"]
                back_id["albums"] = albumid
                library = xbmc_get_details(xbmc, "album", int(albumid))
                template = "library/details.html"
                title = library["label"]
                back_path = path

            else:
                library = xbmc_get_albums(xbmc, int(artistid))
                title = library[0]["artist"]
                back_path = "/artists"

        elif media_type == "songs":
            file_type = "audio"
            artistid = request.args["artistid"]
            albumid = request.args["albumid"]
            back_id["artists"] = artistid
            back_id["albums"] = albumid

            library = xbmc_get_songs(xbmc, int(artistid), int(albumid))
            title = "%s (%s)" % (library[0]["album"], library[0]["year"])
            path = "/songs?artistid=%s&albumid=%s" % (artistid, albumid)
            back_path = "/albums?artistid=%s" % artistid

        # PVR
        elif media_type == "pvr":  # PVR home
            file_type = None
            title = "PVR"
            path = "/pvr"
            library = [{"label": "TV", "channeltype": "tv"}, {"label": "Radio", "channeltype": "radio"}]

        elif media_type == "channelgroups":  # CHANNEL GROUPS
            channeltype = request.args["type"]
            if channeltype == "tv":
                file_type = "video"
                title = "Live TV"
            else:
                file_type = "audio"
                title = "Live Radio"

            library = xbmc_get_channelgroups(xbmc, channeltype)
            path = "/channelgroups?type=%s" % channeltype
            back_path = "/pvr"

        elif media_type == "channels":  # CHANNELS
            channeltype = request.args["type"]
            if channeltype == "tv":
                file_type = "video"
            else:
                file_type = "audio"

            channelgroupid = request.args["channelgroupid"]

            library = xbmc_get_channels(xbmc, channeltype, int(channelgroupid))
            path = "/channels?type=%s&channelgroupid=%s" % (channeltype, channelgroupid)
            back_path = "/channelgroups?type=%s" % channeltype
            title = library[0]["grouplabel"]
            back_id["channelgroups"] = channelgroupid

        # FILES
        elif media_type == "files":
            global file_sources

            if "files" in request.args:
                file_type = request.args["files"]

                if "path" in request.args:  # Path
                    title = request.args["path"]
                    path = "/files?files=%s&path=%s" % (file_type, request.args["path"])
                    if title in file_sources[file_type]:
                        back_path = "/files?files=%s" % file_type
                    else:
                        back_path = "/files?files=%s&path=%s" % (file_type, os.path.dirname(title))
                        if back_path.endswith("/") or back_path.endswith("\\"):
                            back_path = back_path[:-1]

                    library = xbmc_get_file_path(xbmc, file_type, title)

                else:  # Sources
                    file_sources = {}
                    library = xbmc_get_sources(xbmc, file_type)
                    title = "%s Sources" % file_type.title()
                    path = "/files?files=%s" % file_type
                    back_path = "/files"

            else:  # Files home
                file_type = None
                title = "Files"
                path = "/files"
                library = [{"label": "Video", "filetype": "video"}, {"label": "Music", "filetype": "music"}]

    except Exception as e:
        logger.log("LIBRARY :: Problem fetching %s" % media_type, "ERROR")
        logger.log("EXCEPTION :: %s" % e, "DEBUG")
        return render_xbmc_library(message="There was a problem connecting to the XBMC server")

    return render_xbmc_library(
        template=template,
        library=library,
        title=title,
        media=media_type,
        file=file_type,
        path=path,
        back_path=back_path,
    )
Exemple #19
0
def xhr_xbmc_library_media(media_type=None):
    global back_id
    path = None
    back_path = '/'
    library = None

    if not server_api_address():
        logger.log('LIBRARY :: No XBMC server defined', 'ERROR')
        return render_xbmc_library(message="You need to configure XBMC server settings first.")

    try:
        #Reset back positions when rendering home
        if not media_type:
            back_id = {}

            return render_xbmc_library()

        xbmc = jsonrpclib.Server(server_api_address())
        template = 'library/media.html'


        #MOVIES
        if media_type == 'movies':
            file_type = 'video'

            if 'movieid' in request.args: #Movie details
                movieid = request.args['movieid']
                back_id['movies'] = movieid
                library = xbmc_get_details(xbmc, 'movie', int(movieid))
                template = 'library/details.html'
                title = '%s (%s)' % (library['label'], library['year'])
                if 'setid' in request.args:
                    back_path = '/movies?setid=%s' % request.args['setid']
                else:
                    back_path = '/movies'

            elif 'setid' in request.args: #Movie set
                setid = request.args['setid']
                back_id['movies'] = 'set' + setid
                library = xbmc_get_moviesets(xbmc, int(setid))
                title = library[0]['set']
                path = '/movies?setid=%s' % setid
                back_path = '/movies'

            else:
                library = xbmc_get_movies(xbmc)
                title = 'Movies'
                path = '/movies'


        #TVSHOWS
        elif media_type == 'tvshows':
            file_type = 'video'

            if 'tvshowid' in request.args: #TV show details
                tvshowid = request.args['tvshowid']
                back_id['tvshows'] = tvshowid
                library = xbmc_get_details(xbmc, 'tvshow', int(tvshowid))
                template = 'library/details.html'
                title = library['label']
                path = '/tvshows?tvshowid=%s' % tvshowid
                back_path = '/tvshows'

            else:
                library = xbmc_get_tvshows(xbmc)
                title = 'TV Shows'
                path = '/tvshows'


        elif media_type == 'seasons':
            file_type = 'video'
            tvshowid = request.args['tvshowid']
            back_id['tvshows'] = tvshowid
            library = xbmc_get_seasons(xbmc, int(tvshowid))
            title = library[0]['showtitle']
            path = '/seasons?tvshowid=%s' % tvshowid
            back_path = '/tvshows'


        elif media_type == 'episodes':
            file_type = 'video'
            tvshowid = request.args['tvshowid']
            season = request.args['season']
            back_id['tvshows'] = tvshowid
            back_id['seasons'] = season
            path = '/episodes?tvshowid=%s&season=%s' % (tvshowid, season)

            if 'episodeid' in request.args: #Episode details
                episodeid = request.args['episodeid']
                back_id['episodes'] = episodeid
                library = xbmc_get_details(xbmc, 'episode', int(episodeid))
                template = 'library/details.html'
                title = library['label']
                back_path = path

            else:
                library = xbmc_get_episodes(xbmc, int(tvshowid), int(season))
                title = '%s - Season %s' % (library[0]['showtitle'], library[0]['season'])
                back_path = '/seasons?tvshowid=%s' % tvshowid


        #MUSIC
        elif media_type == 'artists':
            file_type = 'audio'

            if 'artistid' in request.args: #Artist details
                artistid = request.args['artistid']
                back_id['artists'] = artistid
                library = xbmc_get_details(xbmc, 'artist', int(artistid))
                template = 'library/details.html'
                title = library['label']
                back_path = '/artists'

            else:
                library = xbmc_get_artists(xbmc)
                title = 'Artists'
                path = '/artists'


        elif media_type == 'albums':
            file_type = 'audio'
            artistid = request.args['artistid']
            back_id['artists'] = artistid
            path = '/albums?artistid=%s' % artistid

            if 'albumid' in request.args: #Album details
                albumid = request.args['albumid']
                back_id['albums'] = albumid
                library = xbmc_get_details(xbmc, 'album', int(albumid))
                template = 'library/details.html'
                title = library['label']
                back_path = path

            else:
                library = xbmc_get_albums(xbmc, int(artistid))
                title = library[0]['artist']
                back_path = '/artists'
            

        elif media_type == 'songs':
            file_type = 'audio'
            artistid = request.args['artistid']
            albumid = request.args['albumid']
            back_id['artists'] = artistid
            back_id['albums'] = albumid

            library = xbmc_get_songs(xbmc, int(artistid), int(albumid))
            title = '%s (%s)' % (library[0]['album'], library[0]['year'])
            path = '/songs?artistid=%s&albumid=%s' % (artistid, albumid)
            back_path = '/albums?artistid=%s' % artistid


        #PVR
        elif media_type == 'pvr': #PVR home
            file_type = None
            title = 'PVR'
            path = '/pvr'
            library = [
                {'label': 'TV', 'channeltype': 'tv'},
                {'label': 'Radio', 'channeltype': 'radio'}
            ]


        elif media_type == 'channelgroups': #CHANNEL GROUPS
            channeltype = request.args['type']
            if channeltype == 'tv':
                file_type = 'video'
                title = 'Live TV'
            else:
                file_type = 'audio'
                title = 'Live Radio'

            library = xbmc_get_channelgroups(xbmc, channeltype)
            path = '/channelgroups?type=%s' % channeltype
            back_path = '/pvr'


        elif media_type == 'channels': #CHANNELS
            channeltype = request.args['type']
            if channeltype == 'tv':
                file_type = 'video'
            else:
                file_type = 'audio'

            channelgroupid = request.args['channelgroupid']

            library = xbmc_get_channels(xbmc, channeltype, int(channelgroupid))
            path = '/channels?type=%s&channelgroupid=%s' % (channeltype, channelgroupid)
            back_path = '/channelgroups?type=%s' % channeltype
            title = library[0]['grouplabel']
            back_id['channelgroups'] = channelgroupid


        #FILES
        elif media_type == 'files':
            global file_sources

            if 'files' in request.args:
                file_type = request.args['files']

                if 'path' in request.args: #Path
                    title = request.args['path']
                    if title in file_sources[file_type]:
                        back_path = '/files?files=%s' % file_type
                    else:
                        back_path = '/files?files=%s&path=%s' % (file_type, os.path.dirname(title))
                        if back_path.endswith('/') or back_path.endswith('\\'):
                            back_path = back_path[:-1]

                    library = xbmc_get_file_path(xbmc, file_type, title)

                else: #Sources
                    file_sources = {}
                    library = xbmc_get_sources(xbmc, file_type)
                    title = '%s Sources' % file_type.title()
                    path = '/files?files=%s' % file_type
                    back_path = '/files'

            else: #Files home
                file_type = None
                title = 'Files'
                path = '/files'
                library = [
                    {'label': 'Video', 'filetype': 'video'},
                    {'label': 'Music', 'filetype': 'music'}
                ]

    except Exception as e:
        logger.log('LIBRARY :: Problem fetching %s' % media_type, 'ERROR')
        logger.log('EXCEPTION :: %s' % e, 'DEBUG')
        return render_xbmc_library(message='There was a problem connecting to the XBMC server')

    return render_xbmc_library(
        template=template,
        library=library,
        title=title,
        media=media_type,
        file=file_type,
        path=path,
        back_path=back_path
    )
Exemple #20
0
def xhr_xbmc_library_media(media_type=None):
    global back_id
    path = None
    back_path = '/'
    library = None

    if not server_api_address():
        logger.log('LIBRARY :: No XBMC server defined', 'ERROR')
        return render_xbmc_library(
            message="You need to configure XBMC server settings first.")

    try:
        #Reset back positions when rendering home
        if not media_type:
            back_id = {}

            return render_xbmc_library()

        xbmc = jsonrpclib.Server(server_api_address())
        template = 'library/media.html'

        #MOVIES
        if media_type == 'movies':
            file_type = 'video'

            if 'movieid' in request.args:  #Movie details
                movieid = request.args['movieid']
                back_id['movies'] = movieid
                library = xbmc_get_details(xbmc, 'movie', int(movieid))
                template = 'library/details.html'
                title = '%s (%s)' % (library['label'], library['year'])
                if 'setid' in request.args:
                    back_path = '/movies?setid=%s' % request.args['setid']
                else:
                    back_path = '/movies'

            elif 'setid' in request.args:  #Movie set
                setid = request.args['setid']
                back_id['movies'] = 'set' + setid
                library = xbmc_get_moviesets(xbmc, int(setid))
                title = library[0]['set']
                path = '/movies?setid=%s' % setid
                back_path = '/movies'

            else:
                library = xbmc_get_movies(xbmc)
                title = 'Movies'
                path = '/movies'

        #TVSHOWS
        elif media_type == 'tvshows':
            file_type = 'video'

            if 'tvshowid' in request.args:  #TV show details
                tvshowid = request.args['tvshowid']
                back_id['tvshows'] = tvshowid
                library = xbmc_get_details(xbmc, 'tvshow', int(tvshowid))
                template = 'library/details.html'
                title = library['label']
                path = '/tvshows?tvshowid=%s' % tvshowid
                back_path = '/tvshows'

            else:
                library = xbmc_get_tvshows(xbmc)
                title = 'TV Shows'
                path = '/tvshows'

        elif media_type == 'seasons':
            file_type = 'video'
            tvshowid = request.args['tvshowid']
            back_id['tvshows'] = tvshowid
            library = xbmc_get_seasons(xbmc, int(tvshowid))
            title = library[0]['showtitle']
            path = '/seasons?tvshowid=%s' % tvshowid
            back_path = '/tvshows'

        elif media_type == 'episodes':
            file_type = 'video'
            tvshowid = request.args['tvshowid']
            season = request.args['season']
            back_id['tvshows'] = tvshowid
            back_id['seasons'] = season
            path = '/episodes?tvshowid=%s&season=%s' % (tvshowid, season)

            if 'episodeid' in request.args:  #Episode details
                episodeid = request.args['episodeid']
                back_id['episodes'] = episodeid
                library = xbmc_get_details(xbmc, 'episode', int(episodeid))
                template = 'library/details.html'
                title = library['label']
                back_path = path

            else:
                library = xbmc_get_episodes(xbmc, int(tvshowid), int(season))
                title = '%s - Season %s' % (library[0]['showtitle'],
                                            library[0]['season'])
                back_path = '/seasons?tvshowid=%s' % tvshowid

        #MUSIC
        elif media_type == 'artists':
            file_type = 'audio'

            if 'artistid' in request.args:  #Artist details
                artistid = request.args['artistid']
                back_id['artists'] = artistid
                library = xbmc_get_details(xbmc, 'artist', int(artistid))
                template = 'library/details.html'
                title = library['label']
                back_path = '/artists'

            else:
                library = xbmc_get_artists(xbmc)
                title = 'Artists'
                path = '/artists'

        elif media_type == 'albums':
            file_type = 'audio'
            artistid = request.args['artistid']
            back_id['artists'] = artistid
            path = '/albums?artistid=%s' % artistid

            if 'albumid' in request.args:  #Album details
                albumid = request.args['albumid']
                back_id['albums'] = albumid
                library = xbmc_get_details(xbmc, 'album', int(albumid))
                template = 'library/details.html'
                title = library['label']
                back_path = path

            else:
                library = xbmc_get_albums(xbmc, int(artistid))
                title = library[0]['artist']
                back_path = '/artists'

        elif media_type == 'songs':
            file_type = 'audio'
            artistid = request.args['artistid']
            albumid = request.args['albumid']
            back_id['artists'] = artistid
            back_id['albums'] = albumid

            library = xbmc_get_songs(xbmc, int(artistid), int(albumid))
            title = '%s (%s)' % (library[0]['album'], library[0]['year'])
            path = '/songs?artistid=%s&albumid=%s' % (artistid, albumid)
            back_path = '/albums?artistid=%s' % artistid

        #PVR
        elif media_type == 'pvr':  #PVR home
            file_type = None
            title = 'PVR'
            path = '/pvr'
            library = [{
                'label': 'TV',
                'channeltype': 'tv'
            }, {
                'label': 'Radio',
                'channeltype': 'radio'
            }]

        elif media_type == 'channelgroups':  #CHANNEL GROUPS
            channeltype = request.args['type']
            if channeltype == 'tv':
                file_type = 'video'
                title = 'Live TV'
            else:
                file_type = 'audio'
                title = 'Live Radio'

            library = xbmc_get_channelgroups(xbmc, channeltype)
            path = '/channelgroups?type=%s' % channeltype
            back_path = '/pvr'

        elif media_type == 'channels':  #CHANNELS
            channeltype = request.args['type']
            if channeltype == 'tv':
                file_type = 'video'
            else:
                file_type = 'audio'

            channelgroupid = request.args['channelgroupid']

            library = xbmc_get_channels(xbmc, channeltype, int(channelgroupid))
            path = '/channels?type=%s&channelgroupid=%s' % (channeltype,
                                                            channelgroupid)
            back_path = '/channelgroups?type=%s' % channeltype
            title = library[0]['grouplabel']
            back_id['channelgroups'] = channelgroupid

        #FILES
        elif media_type == 'files':
            global file_sources

            if 'files' in request.args:
                file_type = request.args['files']

                if 'path' in request.args:  #Path
                    title = request.args['path']
                    path = '/files?files=%s&path=%s' % (file_type,
                                                        request.args['path'])
                    if title in file_sources[file_type]:
                        back_path = '/files?files=%s' % file_type
                    else:
                        back_path = '/files?files=%s&path=%s' % (
                            file_type, os.path.dirname(title))
                        if back_path.endswith('/') or back_path.endswith('\\'):
                            back_path = back_path[:-1]

                    library = xbmc_get_file_path(xbmc, file_type, title)

                else:  #Sources
                    file_sources = {}
                    library = xbmc_get_sources(xbmc, file_type)
                    title = '%s Sources' % file_type.title()
                    path = '/files?files=%s' % file_type
                    back_path = '/files'

            else:  #Files home
                file_type = None
                title = 'Files'
                path = '/files'
                library = [{
                    'label': 'Video',
                    'filetype': 'video'
                }, {
                    'label': 'Music',
                    'filetype': 'music'
                }]

    except Exception as e:
        logger.log('LIBRARY :: Problem fetching %s' % media_type, 'ERROR')
        logger.log('EXCEPTION :: %s' % e, 'DEBUG')
        return render_xbmc_library(
            message='There was a problem connecting to the XBMC server')

    return render_xbmc_library(template=template,
                               library=library,
                               title=title,
                               media=media_type,
                               file=file_type,
                               path=path,
                               back_path=back_path)