示例#1
0
def xhr_notify_message():
    label = str(request.form['label'])
    hostname = str(request.form['hostname'])
    message = str(request.form['message'])
    title = str(request.form['title'])

    if title == "Title":
        title = "Maraschino"

    if server_type() == "XBMC":
        port = 9777
        icon = os.path.join(RUNDIR, 'static', 'images', 'notifications', request.form['image'])

        if not os.path.exists(icon):
            icon = os.path.join(RUNDIR, 'static', 'images', 'maraschino_logo.png')


        if icon[-3:] == "png":
            icon_type = ICON_PNG
        elif icon[-3:] == "jpg":
            icon_type = ICON_JPEG
        elif icon[-4:] == "jpeg":
            icon_type = ICON_JPEG
        elif icon[-3:] == "gif":
            icon_type = ICON_GIF
        else:
            icon_type = ICON_NONE

        addr = (hostname, port)
        sock = socket(AF_INET,SOCK_DGRAM)

        try:
            logger.log('NOTIFY XBMC :: Sending message to %s' % label, 'INFO')
            packet = PacketNOTIFICATION(title, message, icon_type, icon)
            packet.send(sock, addr)
            return jsonify({ 'status': 'successful'})
        except:
            logger.log('NOTIFY XBMC :: Message failed to send', 'ERROR')
            return jsonify({ 'error': 'Message failed to send'})
    elif server_type() == "PLEX":

        try:
            logger.log('NOTIFY XBMC :: Sending message %s' % label, 'INFO')
            server = PLEXLibrary(server_address())
            for connectedclient in server.getClients():
                client = PLEXClient(connectedclient['host'], connectedclient['port'])
                client.sendmessage(title + "," + message)
                
            return jsonify({'status': 'successful'})
        except Exception, e:
            logger.log('NOTIFY XBMC :: Message failed to send', 'ERROR')
            logger.log('NOTIFY XBMC :: Error %s' % e, 'ERROR')
            return jsonify({'error': 'Message failed to send'})
示例#2
0
def xhr_play_media(file_type, media_type, media_id):
    logger.log('CONTROLS :: Playing %s' % media_type, 'INFO')
    position = 0

    if file_type == 'video':
        id = 1
    else:
        id = 0

    try:
        xhr_clear_playlist(id)
    except:
        logger.log('CONTROLS :: Failed to clear %s playlist' % file_type, 'DEBUG')
        return jsonify({ 'failed': True })

    if server_type()=="XBMC":
        xbmc = jsonrpclib.Server(server_api_address())
    elif server_type()=="PLEX":
        plexlibrary=PLEXLibrary(server_address(),TVLibID=get_setting_value('plex_tvlib_id'),MovieLibID=get_setting_value('plex_movielib_id'))

    if file_type == 'video':

        if media_type == 'tvshow':
            try:
                tvshow_episodes = xbmc.VideoLibrary.GetEpisodes(tvshowid=media_id, sort={ 'method': 'episode' })['episodes']
                for episode in tvshow_episodes:
                    episodeid = episode['episodeid']
                    item = {'episodeid': episodeid}
                    xbmc.Playlist.Add(playlistid=1, item=item)

            except:
                logger.log('CONTROLS :: Failed to retrieve episodes', 'DEBUG')
                return jsonify({'failed': True})

        elif 'season' in media_type:
            if server_type()=="XBMC":
                media_type = media_type.split('_')
                season = int(media_type[1])

                try:
                    tvshow_episodes = xbmc.VideoLibrary.GetEpisodes(tvshowid=media_id, season=season, sort={ 'method': 'episode' })['episodes']
                    for episode in tvshow_episodes:
                        episodeid = episode['episodeid']
                        item = {'episodeid': episodeid}
                        xbmc.Playlist.Add(playlistid=1, item=item)

                except:
                    logger.log('CONTROLS :: Failed to retrieve episodes', 'DEBUG')
                    return jsonify({'failed': True})
            elif server_type()=="PLEX":
                pass   
        else:
            try:
                if server_type()=="XMBC":
                    item = { media_type + 'id': media_id }
                    xbmc.Playlist.Add(playlistid=1, item=item)
                elif server_type()=="PLEX":
                    item=str(media_id)
            except:
                logger.log('CONTROLS :: Failed to add %s to playlist' % media_type, 'DEBUG')
                return jsonify({'failed': True})

    else:

        try:
            if media_type == 'song' and get_setting_value('xbmc_songs_play_album') == '1':
                song = xbmc.AudioLibrary.GetSongDetails(songid=media_id, properties=['albumid', 'track'])['songdetails']
                item = {'albumid': song['albumid']}
                position = song['track'] -1
            else:
                item = {media_type+'id': media_id}
            xbmc.Playlist.Add(playlistid=0, item=item)
        except:
            logger.log('CONTROLS :: Failed to add %s to playlist' % media_type, 'DEBUG')
            return jsonify({'failed': True})

    try:
        if server_type()=="XBMC":
            item = {'playlistid': id, 'position': position}
            xbmc.Player.Open(item)
        elif server_type()=="PLEX":
            plexlibrary.playFile (item,plexlibrary.getClients()[0]['host'])
    except:
        logger.log('CONTROLS :: Failed to open %s playlist' % file_type, 'DEBUG')
        return jsonify({'failed': True})

    return jsonify({'success': True})