Exemplo n.º 1
0
    def test_segment_shape(self):
        self.assertTrue( shaper.segment_rule_rewrite(shaper.parse_rules("1000k~e400"), self.v_playlist_1000k, self.v_playlist_1000k) == shaper.generate_status(400))

        self.assertTrue( shaper.segment_rule_rewrite(shaper.parse_rules("1000k.s0~e404"), self.v_playlist_1000k, self.s0_1000k) == shaper.generate_status(404))
        self.assertTrue( shaper.segment_rule_rewrite(shaper.parse_rules("1000k.s1~e404"), self.v_playlist_1000k, self.s0_1000k) == None)
  
        self.assertTrue( shaper.segment_rule_rewrite(shaper.parse_rules("1000k.s0~net100.loss10"), self.v_playlist_1000k, self.s0_1000k_mock, mock_shape_segment=True) != None)
        self.assertTrue( shaper.segment_rule_rewrite(shaper.parse_rules("1000k.*~net100.loss10"),self.v_playlist_1000k, self.s0_1000k_mock, mock_shape_segment=True) != None)

        self.assertRaises(ValueError, shaper.segment_rule_rewrite, {"1000k.*":"404"}, self.v_playlist_1000k, self.s0_1000k_mock)
Exemplo n.º 2
0
    def variant_m3u8(self, cid=None, r=None, tag=None, **kwargs):
        """ Special endpoint for shaping direct variqnt playlists"""

        seeded_content_id = conf.common.get_seeded_cid(cid)
        fake_master_playlist_url = ""
        fake_master_playlist =  """
        #EXTM3U
        #EXT-X-VERSION:2
        #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=0,RESOLUTION=0x0
        {0}
        """.format( conf.data.provider.master_m3u8_url(cid, kwargs) )

        varient_playlists = httpls_client.get_variant_playlist_urls(fake_master_playlist, fake_master_playlist_url)
        rules = shaper.parse_rules(r, varient_playlists)

        info = shaper.cache_and_shape(fake_master_playlist, seeded_content_id, rules, fake_master_playlist_url)
        info["url"] = conf.common.get_final_url("playlist.m3u8","p=m_{0}".format(seeded_content_id))

        # if we have a tag, store
        if tag:
            self.store_tag(cid, r, tag, kwargs)

        cached_cid = info['variants'][info['variants'].keys()[0]]

        with open("{0}/playlists/m_{1}.m3u8".format(shaper.shaper_store_path, cached_cid), "r") as pf:
            master_content = pf.read()

        # return the rewritten master  
        cherrypy.response.headers['Content-Type'] = "application/vnd.apple.mpegurl"
        cherrypy.response.headers['Content-Disposition'] = "inline; filename={0}.m3u8".format(cid)
        cherrypy.response.headers['Last-Modified'] = httputil.HTTPDate()

        return master_content
Exemplo n.º 3
0
    def test_rule_parse_with_mpl(self):
        rules = shaper.parse_rules("v.400k-4000k.s1-10~e404", self.mpl)
        self.assertTrue(rules["v.400k.s5"] == "e404")
        self.assertTrue(rules["v.650k.s5"] == "e404")
        self.assertTrue(rules["v.4000k.s5"] == "e404")

        rules = shaper.parse_rules("v.400k-4000k~e404", self.mpl)
        self.assertTrue(rules["v.400k"] == "e404")

        rules = shaper.parse_rules("400k-4000k~e404", self.mpl)
        self.assertTrue(rules["400k"] == "e404")

        rules = shaper.parse_rules("*~e404,1000-2000k~e500", self.mpl)
        self.assertTrue(rules["1000k"] == "e500")

        rules = shaper.parse_rules("*~e404,*.*.s10-20~net10", self.mpl)
        self.assertTrue(rules["*.*.s12"] == "net10")
Exemplo n.º 4
0
    def test_cache_and_shape(self):
        seeded_cid = conf.common.get_seeded_cid("wt")
      
        shaper.cache_and_shape(self.master_loc_playlist, seeded_cid, shaper.parse_rules("1000k.s0~e404,4000k~e500"))
                
        self.assertTrue( open("%s/playlists/m_%s.m3u8" % (self.test_path, seeded_cid) ).read().find("s=500") != -1)
        self.assertTrue( open("%s/playlists/m_%s_1000000__d.m3u8" % (self.test_path, seeded_cid) ).read().find("s=404") != -1)

        pass
Exemplo n.º 5
0
    def test_rule_parse(self):
        rules = shaper.parse_rules("*.*~e404")
        self.assertTrue(rules["*.*"] == "e404")
        self.assertTrue(shaper.parse_rules(None) == {})

        self.assertRaises(ValueError, shaper.parse_rules, "*.-404")

        #test out [cdn][bitrate][segment]        
        rules = shaper.parse_rules("v.*.*~e404")
        rules = shaper.parse_rules("v.*.*~net100.loss10")

        #segment multiple rules
        rules = shaper.parse_rules("v.650k.*~net100.loss10, *~ e404 ,500k~net100")
        self.assertTrue(rules["*"] == "e404")           

        self.assertRaises(ValueError, shaper.parse_rules, "*.c0~e404,*,650k.c0~e404")
        self.assertRaises(ValueError, shaper.parse_rules, "*.c0~404,*,650k.c0~e404")

        return
Exemplo n.º 6
0
Arquivo: main.py Projeto: raeez/dripls
    def cache_stream(self, cid=None, r=None, tag=None, kwargs=None):
        """ Perform the actual caching and shaping  of the stream """

        rules = shaper.parse_rules(r)

        seeded_content_id = conf.common.get_seeded_cid(cid)
        master_playlist = conf.data.provider.pull_master_m3u8(cid, kwargs)

        info = shaper.cache_and_shape(master_playlist, seeded_content_id, rules)
        info["url"] = conf.common.get_final_url("playlist.m3u8","p=m_{0}".format(seeded_content_id))

        # if we have a tag, store
        if tag:
            self.store_tag(cid, r, tag, kwargs)

        return info
Exemplo n.º 7
0
    def test_segment_rule_match_vplaylist(self):
        v_playlists_desc = httpls_client.get_variant_playlist_urls(self.master_playlist)
       
        p4000k = next( v_playlists_desc["4000000"].itervalues())
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("4000k~e404"), p4000k, p4000k) != None )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("650k~e404"), p4000k, p4000k) == None )

        master_cdn_playlist = open(self.test_path + "/wt_suite/basic/wt_master_cdn_fallback.m3u8","r").read()
        v_playlists_cdn_desc = httpls_client.get_variant_playlist_urls(master_cdn_playlist)
    
        p4000k_a =  v_playlists_cdn_desc["4000000"]["a"]
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("b.4000k~e404"), p4000k_a, p4000k_a) == None )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("a.4000k~e404"), p4000k_a, p4000k_a) != None )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("4000k~e404"), p4000k_a, p4000k_a) != None )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("*~e404"), p4000k_a, p4000k_a) != None )
        
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("1000k.s0~e404,1000k~e500"), self.v_playlist_1000k, self.v_playlist_1000k) != None )
Exemplo n.º 8
0
    def test_segment_rule_match_segment(self):
        # test rule matching with regular segments      
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("1000k~e404"), self.v_playlist_1000k, self.s0_1000k) == None )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("1000k.s1~e404"), self.v_playlist_1000k, self.s0_1000k) == None )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("1000k.s0~e404"), self.v_playlist_1000k, self.s0_1000k) == "e404" )

        # test rule matching with content segments
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("1000k.c0~e404"), self.v_playlist_1000k, self.c0_1000k) == "e404" )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("1000k.*~e404"), self.v_playlist_1000k, self.c0_1000k) == "e404" )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("1000k.c0~e404"), self.v_playlist_1000k, self.s0_1000k) == None )

        # test rule matching with cdn and segments
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("a.*.c0~e404"), self.v_playlist_1000k, self.c0_1000k) == "e404" )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("b.*.c0~e404"), self.v_playlist_1000k, self.c0_1000k) == None )
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("a.*.*~e404"), self.v_playlist_1000k, self.c0_1000k) == "e404" )

        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("a.*.*~net100.loss10"), self.v_playlist_1000k, self.c0_1000k) == "net100.loss10")

        # specific rule takes precedencee
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("a.*.*~net100.loss10,1000k.c0~e404"), self.v_playlist_1000k, self.c0_1000k) == "e404")
        self.assertTrue( shaper.segment_rule_match(shaper.parse_rules("a.*.*~net100.loss10,1000k.s0~net100"), self.v_playlist_1000k, self.s0_1000k) == "net100")