<commit_before>//
//  MediaEntry.swift
//  PlayKit
//
//  Created by <NAME> on 08/10/2016.
//  Copyright © 2016 Kaltura. All rights reserved.
//

import UIKit
import SwiftyJSON

public class MediaEntry: NSObject {
    internal var id: String?
    internal var sources: [MediaSource]?
    internal var duration: Int64?
    
    private let idKey = "id"
    private let sourcesKey = "sources"
    private let durationKey = "duration"
    

    public init(json: JSON) {
      
        guard let id = json[idKey].string else { return}
        self.id = id
        self.duration = json[durationKey].int64
        var sources : [MediaSource] = [MediaSource]()
        for jsonSource in json[sourcesKey].array! {
            
            let mediaSource : MediaSource = MediaSource(json: jsonSource)
            sources.append(mediaSource)
        }
        
        self.sources = sources
    }
}

public class MediaSource {
    internal var id: String
    internal var contentUrl: URL?
    internal var mimeType: String?
    internal var drmData: DRMData?
    
    
    
    private let idKey: String = "id"
    private let contentUrlKey: String = "url"
    private let mimeTypeKey: String = "mimeType"
    private let drmDataKey: String = "drmData"
    
    
    public init(json:JSON) {
        self.id = json[idKey].string!
        
        if let pathString = json[contentUrlKey].string {
                self.contentUrl = URL(string: pathString)
        }
        
        if let mimeTypeString = json[mimeTypeKey].string {
            self.mimeType = mimeTypeString
        }
    }
}

open class DRMData {
    var licenseURL: URL?
}

public class FairPlayDRMData: DRMData {
    var fpsCertificate: Data?    
}
<commit_msg>Parse DRMData.<commit_after>//
//  MediaEntry.swift
//  PlayKit
//
//  Created by <NAME> on 08/10/2016.
//  Copyright © 2016 Kaltura. All rights reserved.
//

import UIKit
import SwiftyJSON

public class MediaEntry: NSObject {
    internal var id: String?
    internal var sources: [MediaSource]?
    internal var duration: Int64?
    
    private let idKey = "id"
    private let sourcesKey = "sources"
    private let durationKey = "duration"
    

    public init(json: JSON) {
      
        guard let id = json[idKey].string else { return}
        self.id = id
        self.duration = json[durationKey].int64
        var sources : [MediaSource] = [MediaSource]()
        for jsonSource in json[sourcesKey].array! {
            
            let mediaSource : MediaSource = MediaSource(json: jsonSource)
            sources.append(mediaSource)
        }
        
        self.sources = sources
    }
}

public class MediaSource {
    internal var id: String
    internal var contentUrl: URL?
    internal var mimeType: String?
    internal var drmData: DRMData?
    
    
    
    private let idKey: String = "id"
    private let contentUrlKey: String = "url"
    private let mimeTypeKey: String = "mimeType"
    private let drmDataKey: String = "drmData"
    
    
    public init(json:JSON) {
        self.id = json[idKey].string!
        
        if let pathString = json[contentUrlKey].string {
                self.contentUrl = URL(string: pathString)
        }
        
        if let mimeTypeString = json[mimeTypeKey].string {
            self.mimeType = mimeTypeString
        }
        
        if let drmData = json[drmDataKey].dictionaryObject {
            guard let licenseURL = drmData["licenseUrl"] as? String else { return }
            
            if let fpsCertificate = drmData["fpsCertificate"] as? String {
                var fpsData = FairPlayDRMData()
                fpsData.fpsCertificate = Data(base64Encoded: fpsCertificate)
                fpsData.licenseURL = URL(string: licenseURL)
                self.drmData = fpsData
            }
        }
    }
}

open class DRMData {
    var licenseURL: URL?
}

public class FairPlayDRMData: DRMData {
    var fpsCertificate: Data?    
}

{'fraction_non_alphanumeric': 0.0868020304568528, 'fraction_numerical': 0.008629441624365483, 'mean_word_length': 2.0765027322404372, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3373398', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1135, 'n_words': 320}