1jQuery(document).ready(function() { 2 // create the ad break xml for fetching the video ads 3 window.cable.createAdBreakXML = function(xml = []) { 4 let createXML = function(randomId, time, adType, breakType = "linear", allowMultipleAds = "false", followRedirects = "true", repeatAfter = false) { 5 let adURL 6 switch (adType) { 7 case "midroll": 8 adURL = `https://pubads.g.doubleclick.net/gampad/ads?iu=/21623123519/icable-web/icable-web::article-page::mid-roll&description_url=http%3A%2F%2Fi-cable.com&tfcd=0&npa=0&sz=640x360%7C640x480&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=` 9 break 10 case "preroll-2": 11 adURL = `https://pubads.g.doubleclick.net/gampad/ads?iu=/21623123519/icable-web/icable-web::article-page::pre-roll-2&description_url=http%3A%2F%2Fi-cable.com&tfcd=0&npa=0&sz=640x360%7C640x480&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=` 12 break 13 case "outStream::homepage": 14 adURL = `https://pubads.g.doubleclick.net/gampad/ads?iu=/21623123519/icable-web/icable-web::homepage::out-stream&description_url=http%3A%2F%2Fi-cable.com&tfcd=0&npa=0&sz=640x360%7C640x480&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=` 15 break 16 case "outStream::article-page": 17 adURL = `https://pubads.g.doubleclick.net/gampad/ads?iu=/21623123519/icable-web/icable-web::article-page::out-stream&description_url=http%3A%2F%2Fi-cable.com&tfcd=0&npa=0&sz=640x360%7C640x480&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=` 18 break 19 case "preroll": 20 default: 21 adURL = `https://pubads.g.doubleclick.net/gampad/ads?iu=/21623123519/icable-web/icable-web::article-page::pre-roll&description_url=http%3A%2F%2Fi-cable.com&tfcd=0&npa=0&sz=640x360%7C640x480&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=` 22 break 23 } 24 let adBreak = 25 `<vmap:AdBreak timeOffset="${time}" breakType="${breakType}" breakId="${adType}_${randomId}" ${repeatAfter?`repeatAfter="${repeatAfter}"`:""}> 26 <vmap:AdSource id="${adType}_source_${randomId}" allowMultipleAds="${allowMultipleAds}" followRedirects="${followRedirects}"> 27 <vmap:AdTagURI templateType="vast3"><![CDATA[${adURL}]]></vmap:AdTagURI> 28 </vmap:AdSource> 29 </vmap:AdBreak>` 30 return adBreak 31 } 32 33 let arr = xml.map((adBreak, index) => { 34 return createXML(index, adBreak.time, adBreak.adType, adBreak.breakType, adBreak.allowMultipleAds, adBreak.followRedirects, adBreak.repeatAfter) 35 }) 36 37 let adBreak = arr.join("") 38 let xmlRes = `<?xml version="1.0" encoding="UTF-8"?> 39 <vmap:VMAP xmlns:vmap="http://www.iab.net/videosuite/vmap" version="1.0"> 40 ${adBreak} 41 </vmap:VMAP>` 42 43 return xmlRes 44 } 45 46 // to calculate the video duration by the m3u8 video URL 47 window.cable.getVideoDuration = async function(videoURL) { 48 try{ 49 let m3u8Playlist = await fetch(videoURL) 50 let playlistText = await m3u8Playlist.text() 51 let m3u8Path = playlistText.split(/\r?\n/).filter(item => item.includes('m3u8')) 52 if(m3u8Path.length > 0) { 53 let newURL = await fetch(videoURL.replace('playlist.m3u8', m3u8Path)) 54 let segments = await newURL.text() 55 let segmentsDuration = [ ...segments.matchAll(/#EXTINF:(\d+\.?\d*)/g)] 56 let totalDuration = segmentsDuration.reduce((previous, current) => {return previous + +current[1]}, 0) 57 return totalDuration 58 } 59 } catch(e) { 60 console.log("error", e) 61 } 62 } 63 64 // convert the Number of Seconds to a Time String in the hh:mm:ss Format 65 window.cable.toHHMMSS = function(numSecs) { 66 let secNum = parseInt(numSecs, 10) 67 let hours = Math.floor(secNum / 3600) 68 let minutes = Math.floor((secNum - (hours * 3600)) / 60) 69 let seconds = secNum - (hours * 3600) - (minutes * 60) 70 71 if (hours < 10) {hours = "0" + hours;} 72 if (minutes < 10) {minutes = "0" + minutes;} 73 if (seconds < 10) {seconds = "0" + seconds;} 74 return `${hours}:${minutes}:${seconds}` 75 } 76 77 // to fetch the video ads based on the video duration 78 window.cable.createImaOption = function(duration) { 79 let adBreakArr = [] 80 let adInterval 81 82 // count the video duration to define the number of PreRoll ads 83 switch(duration) { 84 case 'outStream::homepage': 85 case 'outStream::article-page': 86 adInterval = 10 87 for(let x = 1; x <= adInterval; x++) { 88 adBreakArr.push({time:"start", adType: duration}) 89 } 90 break 91 default: 92 if(duration > 600) { 93 adInterval = 2 94 // define the midroll ads 95 adBreakArr.push( {time: "00:10:00", adType: "midroll", repeatAfter: "00:10:00"}) 96 } else { 97 adInterval = 1 98 } 99 100 for(let x = 1; x <= adInterval; x++) { 101 adBreakArr.push({time:"start", adType: "preroll"}) 102 } 103 break 104 } 105 106 // create the xml 107 let adBreakRes = cable.createAdBreakXML(adBreakArr) 108 // create the ima options 109 return { 110 autoPlayAdBreaks: true, 111 adsResponse: adBreakRes, 112 } 113 } 114})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.