Ejemplo n.º 1
0
class TestAllMediaAccess(unittest.TestCase):

    def setUp(self):
        self._mediaSet = MediaSet()
        self.testNumeric = re.compile("\d*")        
        self._mediaSet.configure( parseXmlString(configMediaAccess))
        return

    def tearDown(self):
        return

    def assertUnicodeType( self, str ):
        self.assertEqual( type(str), types.UnicodeType )

    def assertUnicodeEqual( self, str, match ):
        self.assertUnicodeType( str )
        self.assertUnicodeType( match )
        self.assertEqual( str, match )

    def verifyXml( self, xmlStr ):
        # expect error if load fails
        self.assertUnicodeType( xmlStr )

        try:
            xmlDom = parseXmlString( xmlStr )
        except Exception, e:
            logging.exception( "bad Xml %s " % xmlStr )
            self.assert_( False, "Bad Xml" )
Ejemplo n.º 2
0
    def status( self, medianame='name-required', status='item-required' ):
        """
        Return status of a media server
        """
        result = ClientProfiles.makeStandardResponse( cherrypy.request )

        self.__log.debug( 'MediaAccess.status %s, %s ' % (medianame, status) )
        result['stserr'] = None
        result['mediaName'] = medianame

        try :
            if ( status == 'vol' ):
                xmlStr = MediaSet.volume( self, medianame )
            elif ( status == 'playlist' ):
                 xmlStr = MediaSet.playlist( self, medianame )
            elif ( status == 'playlists' ):
                xmlStr = MediaSet.playlists( self, medianame )
            elif ( status == 'position' ):
                xmlStr = MediaSet.status( self, medianame )
            else:
                xmlStr = MediaSet.status( self, medianame )
            self.__log.debug( '%s:%s - xmlString %s' % (medianame, status, xmlStr) )
            xml = parseXmlString( xmlStr )

            if ( status == 'position' ):
                result['position'] = getNamedNodeText( xml, 'position' )
                result['duration'] = getNamedNodeText( xml, 'duration' )

            elif ( status == 'vol' ):
                result['vol'] = getNamedNodeText( xml, status )

            elif ( status == 'playlist' ):
                result['playlist'] = getElemXml( getNamedElem( xml, status ) )

            elif ( status == 'playlists' ):
                result['playlists'] = getElemXml( getNamedElem( xml, status ) )

            elif ( status == 'track' ):
                result['track'] = getNamedNodeText( xml, status )

            else:
                result[str(status)] = getNamedNodeText( xml, status )
        except Exception, ex :
            self.__log.exception( 'Error %s, %s ' % (medianame, status) )
            result['stserr'] = "unknown"
Ejemplo n.º 3
0
 def setPosition(self, medianame='name-required', newPosition="newPosition"):
     """
     Issue command to media server
     """
     self.__log.debug( 'setPosition %s, %s ' % (medianame, newPosition) )
     result = MediaSet.setPosition( self, medianame, newPosition )
     raise cherrypy.HTTPRedirect("/mediapanel?mediatitle=iTunes&medianame=%s" % (medianame) )
     if not result:
         result = ""
     return result
Ejemplo n.º 4
0
 def command(self, medianame='name-required', mediacmd="command-to-issue"):
     """
     Issue command to media server
     """
     self.__log.debug( 'status %s, %s ' % (medianame, mediacmd) )
     result = MediaSet.command( self, medianame, mediacmd )
     raise cherrypy.HTTPRedirect("/mediapanel?mediatitle=iTunes&medianame=%s" % (medianame) )
     if not result:
         result = ""
     return result
Ejemplo n.º 5
0
    def __init__(self):
        # a dictionary of media server names to media server implementations
        MediaSet.__init__( self )
        self.__log = logging.getLogger( "WebBrickGateway.MediaAccess" )
        self.videoTracks = {
                '0': {'title':'Enterprise Broken Bow Part 1', 'location':'/static/video/BrokenBowPart1.avi' },
                '1': {'title':'Enterprise Broken Bow Part 2', 'location':'/static/video/BrokenBowPart2.avi' },
                }
        #
        # I think this needs dealing with in the browser.
        #
        port = cherrypy.config.get( 'server.socket_port', '8080' )
        ipadr = cherrypy.config.get( 'server.socket_host' )

        addresses = gethostbyaddr(gethostname())  # (hostname, aliaslist, ipaddrlist)
        ipaddrlist = addresses[2]
        self.__log.debug( 'server addresses %s' % (ipaddrlist) )
        if not ipadr:
            ipadr = ipaddrlist[0]

        self.serverBaseUrl = 'http://%s:%s' % ( ipadr, port )
        self.__log.debug( 'serverBaseUrl %s' % (self.serverBaseUrl) )
Ejemplo n.º 6
0
 def setUp(self):
     self._mediaSet = MediaSet()
     self.testNumeric = re.compile("\d*")        
     self._mediaSet.configure( parseXmlString(configMediaAccess))
     return
Ejemplo n.º 7
0
 def setUp(self):
     self._mediaSet = MediaSet()
     self._mediaSet.configure( parseXmlString(testConfigMediaSet) )
     return
Ejemplo n.º 8
0
class TestMediaSet(unittest.TestCase):

    def setUp(self):
        self._mediaSet = MediaSet()
        self._mediaSet.configure( parseXmlString(testConfigMediaSet) )
        return

    def tearDown(self):
        return

    def assertUnicode( self, str, match ):
        self.assertEqual( type(str), types.UnicodeType )
        self.assertEqual( type(match), types.UnicodeType )
        self.assertEqual( str, match )

    # Actual tests follow
    def testGetStatus(self):
        self.assertUnicode( self._mediaSet.status( "AccessGood" ), u'<status name="AccessGood"><state>1</state><track>Test Track</track><position>119</position><duration>500</duration></status>' )
        self.assertEqual( self._mediaSet.status( "AccessBad" ), None )
        self.assertUnicode( self._mediaSet.status( "noKnownInterface" ), u'<error>No Such Interface noKnownInterface</error>' )

        self.assertUnicode( self._mediaSet.volume( "AccessGood" ), u'<vol>40</vol>' )
        self.assertEqual( self._mediaSet.volume( "AccessBad" ), None )
        self.assertUnicode( self._mediaSet.volume( "noKnownInterface" ), u'<error>No Such Interface noKnownInterface</error>' )

    def testCommands(self):
        self.assertEqual( self._mediaSet.command("AccessGood", "stop"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "stop"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "play"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "play"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "pause"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "pause"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "togglePause"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "togglePause"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "next"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "next"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "prev"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "prev"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "forward"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "forward"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "rewind"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "rewind"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.setPosition( "AccessGood", 100), None )
        self.assertUnicode( self._mediaSet.setPosition("AccessBad", 100), u'Error' )

        self.assertEqual( self._mediaSet.setVolume( "AccessGood", 100), None )
        self.assertUnicode( self._mediaSet.setVolume("AccessBad", 100), u'Error' )

        self.assertEqual( self._mediaSet.selectPlaylist("AccessGood", '1.1'), None )
        self.assertUnicode( self._mediaSet.selectPlaylist("AccessBad",'1.1'), u'Error' )

        self.assertEqual( self._mediaSet.selectTrack("AccessGood", '1.1.1'), None )
        self.assertUnicode( self._mediaSet.selectTrack("AccessBad", '1.1.1'), u'Error' )

        self.assertEqual( self._mediaSet.command("AccessGood", "toggleMute"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "toggleMute"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "volup"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "volup"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "voldown"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "voldown"), u'<error>Error</error>' )

        self.assertUnicode( self._mediaSet.command("AccessGood", "xxCommand"), u"<error>No Such Command xxCommand</error>" )
        self.assertUnicode( self._mediaSet.command("AccessBad", "xxCommand"), u"<error>No Such Command xxCommand</error>" )

    def testPlaylist(self):
        # first the playlists array
        self.assertUnicode( self._mediaSet.playlists("AccessGood"), u'<playlists><playlist id="1.1" current="yes">Playlist 1</playlist><playlist id="1.2">Playlist 2</playlist></playlists>' )
        self.assertEqual( self._mediaSet.playlists("AccessBad"), None )
       
        self.assertUnicode( self._mediaSet.playlist("AccessGood"), u'<playlist><track id="1.1.1" current="yes">Track 1</track><track id="1.1.2">Track 2</track><track id="1.1.3">Track 3</track></playlist>' )
        self.assertEqual( self._mediaSet.playlist("AccessBad"), None )