예제 #1
0
 def parse(self,manifest):
     ms_counter = None
     lines = manifest.split('\n')
     assert(lines[0].startswith('#EXTM3U'))
     for i,line in enumerate(lines):
         if line.startswith('#EXTINF'):
             key,val = line.split(':')
             attr = cast.my_cast(val)
             name = lines[i+1].rstrip() # next line
             if not ms_counter:
                 ms_counter = self.media_sequence
             if not name.startswith('#'):
                 # TODO, bit of a hack here. Some manifests put an attribute
                 # line on the first fragment which breaks this.
                 if ms_counter not in [x.media_sequence for x in self.media_fragments]:
                     url = urlparse.urljoin(self.url, name) # construct absolute url
                     self.media_fragments.append(MediaFragment(name,
                                                               url,
                                                               attr,
                                                               self,
                                                               ms_counter))
             ms_counter += 1
         elif line.startswith('#EXT-X-'): 
             try:
                 key,val = line.split(':')
             except ValueError:
                 key = line
                 val = True
             key = cast.attr_name(key)
             val = cast.my_cast(val)
             setattr(self,key,val)
예제 #2
0
 def test_cast_bool(self):
     self.assertEqual(cast.my_cast('NO'), False)
     self.assertEqual(cast.my_cast('No'), False)
     self.assertEqual(cast.my_cast('no'), False)
     self.assertEqual(cast.my_cast('YES'), True)
     self.assertEqual(cast.my_cast('Yes'), True)
     self.assertEqual(cast.my_cast('yes'), True)
     self.assertEqual(cast.my_cast(True), True)
     self.assertEqual(cast.my_cast(False), False)
예제 #3
0
    def parse(self,manifest):
        self.media_playlists = []
        lines = manifest.split('\n')
        assert(lines[0].startswith('#EXTM3U'))

        for i,line in enumerate(lines):
            if line.startswith('#EXT-X-STREAM-INF'):
                key,val = line.split(':')
                attr = cast.my_cast(val)
                name = lines[i+1].rstrip() # next line 
                url = urlparse.urljoin(self.url, name) # construct absolute url
                self.media_playlists.append(MediaPlaylist(name,url,attr))
            elif line.startswith('#EXT-X-'):
                try:
                    key,val = line.split(':')
                except ValueError:
                    key = line
                    val = True
                key = cast.attr_name(key)
                val = cast.my_cast(val)
                setattr(self,key,val)
예제 #4
0
 def test_cast_dict(self):
     self.assertEqual(
         cast.my_cast('PROGRAM-ID=1127167744,BANDWIDTH=1000000'), {
             'program_id': 1127167744,
             'bandwidth': 1000000
         })
예제 #5
0
 def test_cast_list(self):
     self.assertEqual(cast.my_cast('No,10,100.0'), [False, 10, 100.0])
예제 #6
0
 def test_cast_float(self):
     self.assertEqual(cast.my_cast('1.5'), 1.5)
     self.assertEqual(cast.my_cast('1.0'), 1.0)
     self.assertEqual(cast.my_cast('-1.0'), -1.0)
예제 #7
0
 def test_cast_int(self):
     self.assertEqual(cast.my_cast('1'), 1)
     self.assertEqual(cast.my_cast('-1'), -1)
예제 #8
0
 def test_cast_dict(self):
     self.assertEqual(cast.my_cast('PROGRAM-ID=1127167744,BANDWIDTH=1000000'),
                      {'program_id':1127167744,'bandwidth':1000000})
예제 #9
0
 def test_single_item_list(self):
     self.assertEqual(cast.my_cast('9.9,'), [9.9])
     self.assertEqual(cast.my_cast('10,'), [10])
예제 #10
0
 def test_cast_list(self):
     self.assertEqual(cast.my_cast('No,10,100.0'),[False,10,100.0])
예제 #11
0
 def test_cast_float(self):
     self.assertEqual(cast.my_cast('1.5'),1.5)
     self.assertEqual(cast.my_cast('1.0'),1.0)
     self.assertEqual(cast.my_cast('-1.0'),-1.0)
예제 #12
0
 def test_cast_int(self):
     self.assertEqual(cast.my_cast('1'),1)
     self.assertEqual(cast.my_cast('-1'),-1)