Created
May 27, 2020 20:10
-
-
Save zallanx/9b09c639c999f2ffc6fd504c59e23d34 to your computer and use it in GitHub Desktop.
generateForSleep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func generateForSleep(_ playlist: Playlist) -> Playlist { | |
var remainingDurationInMs: Int = self.getDurationInMsFromNow() | |
let maxRemainderLength = 90 * 60 * 1000 * 2 | |
let firstChunks = [1,2,3,5,6,7,8,9,11,12,13,16] | |
let thenChunks = [2,4,7,8,9,10,12,14,15] | |
let endChunks = [1,5,6,11,16] | |
let ultEndChunks = [17] | |
var chunks: [PlayChunk] = [] | |
var resultTracks: [Track] = [] | |
while remainingDurationInMs > maxRemainderLength { | |
let resultChunks: [PlayChunk] = self.generateClustersFor(playlist: playlist, duration: 90 * 60 * 1000, | |
chunkDefinition:[firstChunks, thenChunks, endChunks]) | |
remainingDurationInMs -= (90 * 60 * 1000) | |
chunks.append(contentsOf: resultChunks) | |
print("Chunk for \(90*60)s limit -") // \(resultChunks.debugDescription())") | |
for chunk in resultChunks { | |
print("Chunk - \(chunk.debugDescription())") | |
} | |
resultTracks.append(contentsOf: PlayChunk.serializeChunk(chunks: resultChunks)) | |
} | |
// Do the ULT END | |
let resultChunks: [PlayChunk] = self.generateClustersFor(playlist: playlist, duration: remainingDurationInMs, | |
chunkDefinition:[firstChunks, thenChunks, ultEndChunks]) | |
chunks.append(contentsOf: resultChunks) | |
print("Chunk for \(remainingDurationInMs)ms limit -") | |
for chunk in resultChunks { | |
print("Chunk - \(chunk.debugDescription())") | |
} | |
resultTracks.append(contentsOf: PlayChunk.serializeChunk(chunks: resultChunks)) | |
playlist.tracks = resultTracks | |
return playlist | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment