<commit_before>package com.kaltura.playersdk;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;

import java.util.Map;

public class RequestHandler {
	private static final String KP_PLAYER_ADATA_SOURCE_WidKey = "wid";
	private static final String KP_PLAYER_ADATA_SOURCE_UiConfIdKey = "uiconf_id";
	private static final String KP_PLAYER_ADATA_SOURCE_CacheStKey = "cache_st";
	private static final String KP_PLAYER_ADATA_SOURCE_EntryId = "entry_id";
	private static final String KP_PLAYER_ADATA_SOURCE_UridKey = "urid";


    public static String videoRequestURL(RequestDataSource requestDataSource){
        if(requestDataSource.isSpecificVersionTemplate()){
            return videoRequestURLSpecific(requestDataSource);
        }else {
            return videoRequestURLProduction(requestDataSource);
        }
    }

    private static String videoRequestURLProduction(RequestDataSource requestDataSource){
        String serverAddress = requestDataSource.getServerAddress();
        if (serverAddress == null || serverAddress.length() == 0) {
            return null;
        }

        String wid = requestDataSource.getWid();
        String uiConfId = requestDataSource.getUiConfId();
        String cacheStr = requestDataSource.getCacheStr();
        String entryId = requestDataSource.getEntryId();
        String urid = requestDataSource.getUrid();
        KPPlayerConfig configFlags = requestDataSource.getFlashVars();
        String url = String.format("%s/p/%s/sp/%s00/embedIframeJs/uiconf_id/%s/partner_id/%s",serverAddress,wid,wid,uiConfId,wid);

        Uri.Builder builder = Uri.parse(url).buildUpon();

        if (entryId != null && !entryId.isEmpty()){
            builder.appendQueryParameter(KP_PLAYER_ADATA_SOURCE_EntryId, entryId);
        }

        if (cacheStr != null && !cacheStr.isEmpty()){
            builder.appendQueryParameter(KP_PLAYER_ADATA_SOURCE_CacheStKey, cacheStr);
        }

        if (configFlags != null) {
            for (Map.Entry<String,String> flashEntry : configFlags.getFlashVarsArray()) {
                builder.appendQueryParameter(flashEntry.getKey(), flashEntry.getValue());
            }
        }

        return builder.build().toString().replace("%5B", "[").replace("%5D", "]");
    }



	private static String videoRequestURLSpecific(RequestDataSource requestDataSource){
		String url = requestDataSource.getServerAddress();
	    if (url == null || url.length() == 0) {
	        return null;
	    }
	    
	    String wid = requestDataSource.getWid();
	    String uiConfId = requestDataSource.getUiConfId();
	    String cacheStr = requestDataSource.getCacheStr();<commit_msg>non specific url scheme fix<commit_after>package com.kaltura.playersdk;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;

import java.util.Map;

public class RequestHandler {
	private static final String KP_PLAYER_ADATA_SOURCE_WidKey = "wid";
	private static final String KP_PLAYER_ADATA_SOURCE_UiConfIdKey = "uiconf_id";
	private static final String KP_PLAYER_ADATA_SOURCE_CacheStKey = "cache_st";
	private static final String KP_PLAYER_ADATA_SOURCE_EntryId = "entry_id";
	private static final String KP_PLAYER_ADATA_SOURCE_UridKey = "urid";


    public static String videoRequestURL(RequestDataSource requestDataSource){
        if(requestDataSource.isSpecificVersionTemplate()){
            return videoRequestURLSpecific(requestDataSource);
        }else {
            return videoRequestURLProduction(requestDataSource);
        }
    }

    private static String videoRequestURLProduction(RequestDataSource requestDataSource){
        String serverAddress = requestDataSource.getServerAddress();
        if (serverAddress == null || serverAddress.length() == 0) {
            return null;
        }

        String wid = requestDataSource.getWid();
        String uiConfId = requestDataSource.getUiConfId();
        String cacheStr = requestDataSource.getCacheStr();
        String entryId = requestDataSource.getEntryId();
        String urid = requestDataSource.getUrid();
        KPPlayerConfig configFlags = requestDataSource.getFlashVars();
        String url = String.format("%s/p/%s/sp/%s00/embedIframeJs/uiconf_id/%s/partner_id/%s",serverAddress,wid,wid,uiConfId,wid);

        Uri.Builder builder = Uri.parse(url).buildUpon();

        if (entryId != null && !entryId.isEmpty()){
            builder.appendQueryParameter(KP_PLAYER_ADATA_SOURCE_EntryId, entryId);
        }

        if (cacheStr != null && !cacheStr.isEmpty()){
            builder.appendQueryParameter(KP_PLAYER_ADATA_SOURCE_CacheStKey, cacheStr);
        }

        if (configFlags != null) {
            for (Map.Entry<String,String> flashEntry : configFlags.getFlashVarsArray()) {
                builder.appendQueryParameter(flashEntry.getKey(), flashEntry.getValue());
            }
        }

        builder.appendQueryParameter("iframeembed", "true");

        return builder.build().toString().replace("%5B", "[").replace("%5D", "]");
    }



	private static String videoRequestURLSpecific(RequestDataSource requestDataSource){
		String url = requestDataSource.getServerAddress();
	    if (url == null || url.length() == 0) {
	        return null;
	    }
	    
	    String wid = requestDataSource.getWid();
	    String uiConfId = requestDataSource.getUiConfId();
	    String cacheStr = requestDataSource.getCacheStr();
{'fraction_non_alphanumeric': 0.10228095582910934, 'fraction_numerical': 0.002172338884866039, 'mean_word_length': 3.6234309623430963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6125737', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1482, 'n_words': 291}