2

I'm developing an iOS app which is able to download m3u8 videos and play it offline according to the iOS 10 latest feature Offline HLS.

I'm trying to protect as best as I can HTTP Live Stream format videos on our CDN.

Each video has multiple bitrates so the HLS files consist of a master m3u8 manifest which points to several sub manifest files which in turn point to ts files (transport stream).

So I need to append this CDN token to the URLs of master m3u8, sub manifest m3u8 and .ts files. The token will be valid for 60 seconds, so it needs to get refreshed and the current token should get append with the URL.

How can I do this?

I tried this, but its appending to only master m3u8.

My Code :

    var components = URLComponents(string: playUrl)
    let token = URLQueryItem(name: "token", value: CDNTokenManager.getCDNToken())
    components?.queryItems = [token]
    let url = components?.url
    let asset = AVURLAsset(url: url!)
    let downloadTask = downloadURLSession.makeAssetDownloadTask(asset: asset,
                                                             assetTitle: "title",
                                                             assetArtworkData: nil,
                                                             options: nil)
    downloadTask?.resume()
Dev
  • 3,885
  • 10
  • 39
  • 65

1 Answers1

0

As far as I know, iOS doesn't offer anything to modify the URL in the m3u8 files. It will retrieve them without any changes. So I don't think you can solve this entirely on the client side.

In addition to your client side code, you will also need to implement a web app on the server side that generates the m3u8 files on demand and adds the CDN token.

For example, the iOS client requests the master file at https://cdn.com/master/fk29x8.m3u8?token=12345, the web app dynamically generates the file containing URLs like https://cdn.com/sub/fk29x8-1280x720-1823.m3u8?token=12345. This URL is again served by the web app and contains URLs like https://cdn.com/stream/fk29x8-1280x720-1823/mp4-123.ts?token=12345.

So the web app's task is basically to read a template file and replace the token value with the on given in the requested URL.

Codo
  • 75,595
  • 17
  • 168
  • 206
  • The token needs to get refreshed for the security means. So how this will work? – Dev Sep 22 '16 at 06:28
  • Is there any way to track the URL requests, and modify them by inserting token at the client side? – Dev Sep 22 '16 at 06:39
  • I've heard of solutions where the app additionally works as an HTTP proxy server. The proxy server can then modify the responses. I can't tell if this is still possible on iOS and how it would be done. – Codo Sep 22 '16 at 06:50