<commit_before>//
//  CustomPlayerVC.swift
//  SHVideoPlayer
//
//  Created by <NAME> on 2/12/17.
//  Copyright © 2017 CocoaPods. All rights reserved.
//

import UIKit
import SHVideoPlayer

class CustomPlayerVC: UIViewController {

    @IBOutlet var tableView: UITableView!
    @IBOutlet var videoPlayer: SHVideoPlayer!
    fileprivate var videos: [SHVideo?] = VideoDataSource.getModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        videoPlayer.backActionCompletionHandler = {() in
            _ = self.navigationController?.popViewController(animated: true)
        }
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        guard let video = videos[1] else {
            return
        }
        videoPlayerPlayVideo(video: video)
    }
    
    fileprivate func videoPlayerPlayVideo(video: SHVideo) {
        guard let sourceURL = video.sourceURL else {
            return
        }
        
        guard let url =  URL(string: sourceURL),
            let title = video.title else {
                return
        }
        videoPlayer.playWithURL(url, title: title)
    }
}

extension CustomPlayerVC: UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return videos.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "VideoTableViewCellID", for: indexPath) as! VideoTableViewCell
        if let video = videos[indexPath.row] {
            cell.titleLabel.text = video.title
            cell.sourceURLLabel.text = video.sourceURL
            cell.thumbImageView.image = video.thumbImage
        }
        return cell
    }
}

extension CustomPlayerVC: UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView .deselectRow(at: indexPath, animated: true)
        guard let video = videos[indexPath.row] else {
            return
        }
        videoPlayerPlayVideo(video: video)
    }
}<commit_msg>forced unwrapped removed from CustomPlayerVC<commit_after>//
//  CustomPlayerVC.swift
//  SHVideoPlayer
//
//  Created by <NAME> on 2/12/17.
//  Copyright © 2017 CocoaPods. All rights reserved.
//

import UIKit
import SHVideoPlayer

class CustomPlayerVC: UIViewController {

    @IBOutlet var tableView: UITableView!
    @IBOutlet var videoPlayer: SHVideoPlayer!
    fileprivate var videos: [SHVideo?] = VideoDataSource.getModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        videoPlayer.backActionCompletionHandler = {() in
            _ = self.navigationController?.popViewController(animated: true)
        }
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if let video = videos[1] {
            videoPlayerPlayVideo(video: video)
        }
    }
    
    fileprivate func videoPlayerPlayVideo(video: SHVideo) {
        if let sourceURL = video.sourceURL {
            guard let url =  URL(string: sourceURL) else {
                    print("Video URL is nil")
                    return
            }
            let title = video.title ?? ""
            videoPlayer.playWithURL(url, title: title)
        }
    }
}

extension CustomPlayerVC: UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return videos.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "VideoTableViewCellID", for: indexPath) as! VideoTableViewCell
        if let video = videos[indexPath.row] {
            cell.titleLabel.text = video.title
            cell.sourceURLLabel.text = video.sourceURL
            cell.thumbImageView.image = video.thumbImage
        }
        return cell
    }
}

extension CustomPlayerVC: UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView .deselectRow(at: indexPath, animated: true)
        if let video = videos[indexPath.row] {
            videoPlayerPlayVideo(video: video)
        }
    }
}
{'fraction_non_alphanumeric': 0.08306488725264612, 'fraction_numerical': 0.004601932811780948, 'mean_word_length': 2.4445324881141044, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1072063', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1191, 'n_words': 290}