Example #1
0
    def setUp(self):
        self.test_path = os.path.dirname(os.path.realpath(__file__))

        for each in os.listdir( "%s/playlists" % self.test_path  ):
            os.remove("%s/playlists/%s" % (self.test_path,each))

        self.master_playlist = open(self.test_path + "/wt_suite/wt_dripls/wt.m3u8","r").read()
        self.master_loc_playlist = open(self.test_path + "/wt_suite/local/wt.m3u8","r").read().replace("{local}", "file://" + self.test_path + "/wt_suite/local")

        local_url = "file://" + os.path.abspath(self.test_path + "/wt_suite/basic/wt_1000k_asset_ad.m3u8")
        self.v_playlist_1000k =  httpls_client.pull_variant_playlist(local_url)
        self.v_playlist_1000k["bandwidth"] = 1000000
        self.v_playlist_1000k["cdn"] = "a"
        self.v_playlist_1000k["type"] = "vplaylist"
 
        self.s0_1000k = self.v_playlist_1000k["segments"][0]

        self.s0_1000k_mock = self.v_playlist_1000k["segments"][0].copy()
        self.s0_1000k_mock["url"] =  "file://" + os.path.abspath(self.test_path + "/wt_suite/basic/mock_segment.ts")

        self.c0_1000k = next( self.v_playlist_1000k["segments"][s] for s in self.v_playlist_1000k["segments"] if self.v_playlist_1000k["segments"][s]["type"] == "content" )   
        self.a0_1000k = next( self.v_playlist_1000k["segments"][s] for s in self.v_playlist_1000k["segments"] if self.v_playlist_1000k["segments"][s]["type"] == "ad" )   
        self.as0_1000k = next( self.v_playlist_1000k["segments"][s] for s in self.v_playlist_1000k["segments"] if self.v_playlist_1000k["segments"][s]["type"] == "asset" )   

        shaper.shaper_store_path = "%s/" % self.test_path
        return
Example #2
0
def hls_cache_and_shape(master_playlist, seeded_content_id, rules, master_playlist_url = ''):
    """Returns shaped m3u8 playlist

    Process and shape a m3u8 playlist based on a set of rules 

    """

    shape_info = {}
    shape_info["id"] = seeded_content_id
    shape_info["variants"] = {}
    shape_port_session = {}

    variant_playlists = httpls_client.get_variant_playlist_urls(master_playlist, master_playlist_url)

    for bitrate in variant_playlists.iterkeys():
        for alt in variant_playlists[bitrate].iterkeys():
            variant_playlist_desc = variant_playlists[bitrate][alt]
            variant_playlist = httpls_client.pull_variant_playlist( variant_playlist_desc["url"])

            # perform rewrite on the variant playlist url to local url or a rule matched url 
            seg_rewrite_url = hls_segment_rule_rewrite(rules, variant_playlist_desc, variant_playlist_desc, shape_port_session)
            local_rewrite_url = conf.common.get_final_url("playlist.m3u8","p=m_{0}_{1}_{2}".format(seeded_content_id, bitrate, alt))
            shape_info["variants"]["{0}_{1}".format(bitrate, alt)] = "{0}_{1}_{2}".format(seeded_content_id, bitrate, alt)
            master_playlist = httpls_client.switch_segment( master_playlist, variant_playlist_desc["original_url"], seg_rewrite_url if seg_rewrite_url else local_rewrite_url )

            # don't process a playlist if it hit a rule (ie has been errored out)
            if seg_rewrite_url:
                shape_info["{0}.{1}".format(bitrate, alt)] = seg_rewrite_url
                continue

            # perform rule rewrite on segments within the variant playlist  
            for s in variant_playlist["segments"].iterkeys():
                seg_rewrite_url = hls_segment_rule_rewrite(rules, variant_playlist_desc, variant_playlist["segments"][s], shape_port_session)

                # rewrite local to full url playlist
                if variant_playlist["segments"][s]["original_url"] != variant_playlist["segments"][s]["url"]:
                    variant_playlist["content"] = httpls_client.switch_segment(variant_playlist["content"], variant_playlist["segments"][s]["original_url"], variant_playlist["segments"][s]["url"])

                # replace segment with shaped url
                if seg_rewrite_url:
                    variant_playlist["content"] = httpls_client.switch_segment(variant_playlist["content"], variant_playlist["segments"][s]["url"], seg_rewrite_url)
                    variant_playlist["segments"][s]["url"] = seg_rewrite_url
                    shape_info["{0}.{1}.s{2}".format( bitrate, alt, s)] = seg_rewrite_url

            httpls_client.store_playlist(variant_playlist["content"], shaper_store_path + "playlists/m_{0}_{1}_{2}.m3u8".format(seeded_content_id, bitrate, alt))


    shape_port_session = {}
    httpls_client.store_playlist(master_playlist, shaper_store_path + "playlists/m_{0}.m3u8".format(seeded_content_id))
    return shape_info
Example #3
0
    def test_pull_variant_playlist(self):
    
        # test a read of a vplaylist and its decomposition 
        local_url = "file://" + os.path.abspath(self.test_path + "/wt_suite/basic/wt_1000k_asset_ad.m3u8") 
        v_playlist =  httpls_client.pull_variant_playlist(local_url)
        
        self.assertTrue( v_playlist["url"] != None) 
        self.assertTrue( v_playlist["content"] != None) 
        
        for segment in v_playlist["segments"].iterkeys():
           self.assertTrue ( v_playlist["segments"][segment]["url"] != None)
           self.assertTrue ( v_playlist["segments"][segment]["segment"] != None)
           self.assertTrue ( v_playlist["segments"][segment]["type"] != None)
             
           if ( v_playlist["segments"][segment]["type"] == "content"):
               self.assertTrue ( v_playlist["segments"][segment]["content_segment"] != None)

        return
Example #4
0
    def setUp(self):
        self.test_path = os.path.dirname(os.path.realpath(__file__))

        for each in os.listdir("%s/playlists" % self.test_path):
            os.remove("%s/playlists/%s" % (self.test_path, each))

        self.master_playlist = open(
            self.test_path + "/wt_suite/wt_dripls/wt.m3u8", "r").read()
        self.master_loc_playlist = open(
            self.test_path + "/wt_suite/local/wt.m3u8",
            "r").read().replace("{local}",
                                "file://" + self.test_path + "/wt_suite/local")

        local_url = "file://" + os.path.abspath(
            self.test_path + "/wt_suite/basic/wt_1000k_asset_ad.m3u8")
        self.v_playlist_1000k = httpls_client.pull_variant_playlist(local_url)
        self.v_playlist_1000k["bandwidth"] = 1000000
        self.v_playlist_1000k["cdn"] = "a"
        self.v_playlist_1000k["type"] = "vplaylist"

        self.s0_1000k = self.v_playlist_1000k["segments"][0]

        self.s0_1000k_mock = self.v_playlist_1000k["segments"][0].copy()
        self.s0_1000k_mock["url"] = "file://" + os.path.abspath(
            self.test_path + "/wt_suite/basic/mock_segment.ts")

        self.c0_1000k = next(
            self.v_playlist_1000k["segments"][s]
            for s in self.v_playlist_1000k["segments"]
            if self.v_playlist_1000k["segments"][s]["type"] == "content")
        self.a0_1000k = next(
            self.v_playlist_1000k["segments"][s]
            for s in self.v_playlist_1000k["segments"]
            if self.v_playlist_1000k["segments"][s]["type"] == "ad")
        self.as0_1000k = next(
            self.v_playlist_1000k["segments"][s]
            for s in self.v_playlist_1000k["segments"]
            if self.v_playlist_1000k["segments"][s]["type"] == "asset")

        self.mpl = {}
        self.mpl["400000"] = {}
        self.mpl["400000"]["__d"] = {
            "url": "http://test.com",
            "original_url": "http://test.com",
            "type": "vplaylist",
            "bandwidth": 400000,
            "cdn": "__d"
        }
        self.mpl["650000"] = {}
        self.mpl["650000"]["__d"] = {
            "url": "http://test.com",
            "original_url": "http://test.com",
            "type": "vplaylist",
            "bandwidth": 650000,
            "cdn": "__d"
        }
        self.mpl["1000000"] = {}
        self.mpl["1000000"]["__d"] = {
            "url": "http://test.com",
            "original_url": "http://test.com",
            "type": "vplaylist",
            "bandwidth": 1000000,
            "cdn": "__d"
        }
        self.mpl["1000000"]["v"] = {
            "url": "http://test.com",
            "original_url": "http://test.com",
            "type": "vplaylist",
            "bandwidth": 1000000,
            "cdn": "__d"
        }
        self.mpl["1000000"]["c"] = {
            "url": "http://test.com",
            "original_url": "http://test.com",
            "type": "vplaylist",
            "bandwidth": 1000000,
            "cdn": "__d"
        }
        self.mpl["4000000"] = {}
        self.mpl["4000000"]["__d"] = {
            "url": "http://test.com",
            "original_url": "http://test.com",
            "type": "vplaylist",
            "bandwidth": 4000000,
            "cdn": "__d"
        }

        shaper.shaper_store_path = "%s/" % self.test_path
        return