<commit_before><?php

class VodPackagerDeliveryUtils
{
	protected static function generateMultiUrl(array $flavors, entry $entry, DeliveryProfileDynamicAttributes $params)
	{
		$urls = array();
		foreach ($flavors as $flavor)
		{
			$urls[] = $flavor['url'];
		}
		$urls = array_unique($urls);
	
		if (count($urls) == 1)
		{
			$baseUrl = reset($urls);
			return '/' . ltrim($baseUrl, '/');
		}
	
		$prefix = kString::getCommonPrefix($urls);
		$postfix = kString::getCommonPostfix($urls);
		
		if ( ($entry->getType() == entryType::PLAYLIST) || $params->getHasValidSequences() )
		{
			// in case of a playlist, need to merge the flavor params of the urls
			// instead of using a urlset, since nginx-vod does not support urlsets of 
			// non-trivial mapping responses.
			 
			// so instead of building:
			//		/p/123/serveFlavor/entryId/0_abc/flavorParamIds/100,1,2,3,/forceproxy/true/name/a.mp4.urlset
			// we build:
			//		/p/123/serveFlavor/entryId/0_abc/flavorParamIds/1001,1002,1003/forceproxy/true/name/a.mp4.urlset
			$prefix = substr($prefix, 0, strrpos($prefix, '/') + 1);
			$postfix = substr($postfix, strpos($postfix, '/'));
		}
		
		$prefixLen = strlen($prefix);
		$postfixLen = strlen($postfix);
		$middlePart = ',';
		foreach ($urls as $url)
		{
			$middlePart .= substr($url, $prefixLen, strlen($url) - $prefixLen - $postfixLen) . ',';
		}
		
		if (($entry->getType() == entryType::PLAYLIST && strpos($middlePart, '/') === false) || ($params->getSequences()))
		{
			$middlePart = rtrim(ltrim($middlePart, ','), ',');
			$result = $prefix . $middlePart . $postfix;
		}
		else
		{
			$result = $prefix . $middlePart . $postfix;
			if (!$params->getUsePlayServer())
				$result .= '.urlset';
		}
	
		return '/' . ltrim($result, '/');
	}
	
	public static function getVodPackagerUrl($flavors, $urlPrefix, $urlSuffix, DeliveryProfileDynamicAttributes $params)
	{<commit_msg>PLAT-7483: fixes from code review, don't fail when sequence ids are bad<commit_after><?php

class VodPackagerDeliveryUtils
{
	protected static function generateMultiUrl(array $flavors, entry $entry, DeliveryProfileDynamicAttributes $params)
	{
		$urls = array();
		foreach ($flavors as $flavor)
		{
			$urls[] = $flavor['url'];
		}
		$urls = array_unique($urls);
	
		if (count($urls) == 1)
		{
			$baseUrl = reset($urls);
			return '/' . ltrim($baseUrl, '/');
		}
	
		$prefix = kString::getCommonPrefix($urls);
		$postfix = kString::getCommonPostfix($urls);
		
		if ( ($entry->getType() == entryType::PLAYLIST) || $params->getHasValidSequences() )
		{
			// in case of a playlist, need to merge the flavor params of the urls
			// instead of using a urlset, since nginx-vod does not support urlsets of 
			// non-trivial mapping responses.
			 
			// so instead of building:
			//		/p/123/serveFlavor/entryId/0_abc/flavorParamIds/100,1,2,3,/forceproxy/true/name/a.mp4.urlset
			// we build:
			//		/p/123/serveFlavor/entryId/0_abc/flavorParamIds/1001,1002,1003/forceproxy/true/name/a.mp4.urlset
			$prefix = substr($prefix, 0, strrpos($prefix, '/') + 1);
			$postfix = substr($postfix, strpos($postfix, '/'));
		}
		
		$prefixLen = strlen($prefix);
		$postfixLen = strlen($postfix);
		$middlePart = ',';
		foreach ($urls as $url)
		{
			$middlePart .= substr($url, $prefixLen, strlen($url) - $prefixLen - $postfixLen) . ',';
		}
		
		if (($entry->getType() == entryType::PLAYLIST && strpos($middlePart, '/') === false) || ($params->getHasValidSequences()))
		{
			$middlePart = rtrim(ltrim($middlePart, ','), ',');
			$result = $prefix . $middlePart . $postfix;
		}
		else
		{
			$result = $prefix . $middlePart . $postfix;
			if (!$params->getUsePlayServer())
				$result .= '.urlset';
		}
	
		return '/' . ltrim($result, '/');
	}
	
	public static function getVodPackagerUrl($flavors, $urlPrefix, $urlSuffix, DeliveryProfileDynamicAttributes $params)
	{
{'fraction_non_alphanumeric': 0.1790733992712129, 'fraction_numerical': 0.01717855283706403, 'mean_word_length': 3.7153374233128833, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '6958501', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1370, 'n_words': 267}