Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	DownloadToGo.podspec
  • Loading branch information
noamtamim committed Aug 6, 2017
2 parents 5162d33 + aa818c4 commit 83fb5aa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DownloadToGo.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'DownloadToGo'
s.version = '3.0.0.rc4'
s.version = '3.0.0'
s.summary = 'DownloadToGo -- download manager for HLS'
s.homepage = 'https://github.com/kaltura/DownloadToGo'
s.license = { :type => 'AGPLv3', :file => 'LICENSE' }
Expand Down
2 changes: 1 addition & 1 deletion Example/DownloadToGo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ViewController: UIViewController {
Item(id: "Kaltura 1", url: "http://cdnapi.kaltura.com/p/243342/sp/24334200/playManifest/entryId/1_sf5ovm7u/flavorIds/1_d2uwy7vv,1_jl7y56al/format/applehttp/protocol/http/a.m3u8"),
Item(id: "Kaltura multi captions", url: "https://cdnapisec.kaltura.com/p/811441/sp/81144100/playManifest/entryId/1_mhyj12pj/format/applehttp/protocol/https/a.m3u8"),
Item(id: "Trailer", url: "http://cdnbakmi.kaltura.com/p/1758922/sp/175892200/playManifest/entryId/0_ksthpwh8/format/applehttp/tags/ipad/protocol/http/f/a.m3u8"),
Item(id: "Elephants", url: "https://playertest.longtailvideo.com/adaptive/eleph-audio/playlist.m3u8")
Item(id: "Empty", url: "https://cdnapisec.kaltura.com/p/2215841/playManifest/entryId/1_58e88ugs/format/applehttp/protocol/https/a.m3u8"),
]

let itemPickerView: UIPickerView = {
Expand Down
45 changes: 31 additions & 14 deletions Sources/ContentManager/HLSLocalizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,31 @@ struct MockVideoTrack: DTGVideoTrack {
enum HLSLocalizerError: Error {
/// sent when an unknown playlist type was encountered
case unknownPlaylistType

case malformedPlaylist

case invalidState
}


func loadMasterPlaylist(url: URL) throws -> M3U8MasterPlaylist {
let text = try String.init(contentsOf: url)
return M3U8MasterPlaylist(content: text, baseURL: url.deletingLastPathComponent())

if let playlist = M3U8MasterPlaylist(content: text, baseURL: url.deletingLastPathComponent()) {
return playlist
} else {
throw HLSLocalizerError.malformedPlaylist
}
}

func loadMediaPlaylist(url: URL, type: M3U8MediaPlaylistType) throws -> M3U8MediaPlaylist {
let text = try String.init(contentsOf: url)
return M3U8MediaPlaylist(content: text, type: type, baseURL: url.deletingLastPathComponent())

if let playlist = M3U8MediaPlaylist(content: text, type: type, baseURL: url.deletingLastPathComponent()) {
return playlist
} else {
throw HLSLocalizerError.malformedPlaylist
}
}

class Stream<T> {
Expand Down Expand Up @@ -302,18 +314,23 @@ class HLSLocalizer {

for i in 0 ..< streams.countInt {

let stream = try MediaStream(streamInfo: streams[i], mediaUrl: streams[i].m3u8URL(), type: type)
try addAllSegments(segmentList: stream.mediaPlaylist.segmentList, type: type)

switch type {
case M3U8MediaPlaylistTypeAudio:
let bitrate = streams[i].bandwidth()
aggregateTrackSize(bitrate: bitrate > 0 ? bitrate : defaultAudioBitrate)
selectedAudioStreams.append(stream)
case M3U8MediaPlaylistTypeSubtitle:
selectedTextStreams.append(stream)
default:
throw HLSLocalizerError.unknownPlaylistType
let url: URL! = streams[i].m3u8URL()
do {
let stream = try MediaStream(streamInfo: streams[i], mediaUrl: url, type: type)
try addAllSegments(segmentList: stream.mediaPlaylist.segmentList, type: type)

switch type {
case M3U8MediaPlaylistTypeAudio:
let bitrate = streams[i].bandwidth()
aggregateTrackSize(bitrate: bitrate > 0 ? bitrate : defaultAudioBitrate)
selectedAudioStreams.append(stream)
case M3U8MediaPlaylistTypeSubtitle:
selectedTextStreams.append(stream)
default:
throw HLSLocalizerError.unknownPlaylistType
}
} catch {
log.warning("Skipping malformed playlist")
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Downloader/DefaultDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class DefaultDownloader: NSObject, Downloader {
self.downloadItemTasksQueue.enqueue(tasks)
self.setBackgroundURLSession()
}

deinit {
self.invokeBackgroundSessionCompletionHandler()
}
}

/************************************************************/
Expand Down

0 comments on commit 83fb5aa

Please sign in to comment.