diff --git a/DownloadToGo.podspec b/DownloadToGo.podspec index 54d15d8..8398c27 100644 --- a/DownloadToGo.podspec +++ b/DownloadToGo.podspec @@ -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' } diff --git a/Example/DownloadToGo/ViewController.swift b/Example/DownloadToGo/ViewController.swift index a5aafa5..6f16906 100644 --- a/Example/DownloadToGo/ViewController.swift +++ b/Example/DownloadToGo/ViewController.swift @@ -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 = { diff --git a/Sources/ContentManager/HLSLocalizer.swift b/Sources/ContentManager/HLSLocalizer.swift index d2ad05e..ff783b7 100644 --- a/Sources/ContentManager/HLSLocalizer.swift +++ b/Sources/ContentManager/HLSLocalizer.swift @@ -25,6 +25,8 @@ struct MockVideoTrack: DTGVideoTrack { enum HLSLocalizerError: Error { /// sent when an unknown playlist type was encountered case unknownPlaylistType + + case malformedPlaylist case invalidState } @@ -32,12 +34,22 @@ enum HLSLocalizerError: Error { 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 { @@ -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") } } } diff --git a/Sources/Downloader/DefaultDownloader.swift b/Sources/Downloader/DefaultDownloader.swift index 71684a5..f6f2d39 100644 --- a/Sources/Downloader/DefaultDownloader.swift +++ b/Sources/Downloader/DefaultDownloader.swift @@ -91,6 +91,10 @@ class DefaultDownloader: NSObject, Downloader { self.downloadItemTasksQueue.enqueue(tasks) self.setBackgroundURLSession() } + + deinit { + self.invokeBackgroundSessionCompletionHandler() + } } /************************************************************/