Initial commit: SimVision tvOS streaming app
Features: - VOD library with movie grouping and version detection - TV show library with season/episode organization - TMDB integration for trending shows and recently aired episodes - Recent releases section with TMDB release date sorting - Watch history tracking with continue watching - Playlist caching (12-hour TTL) for offline support - M3U playlist parsing with XStream API support - Authentication with credential storage Technical: - SwiftUI for tvOS - Actor-based services for thread safety - Persistent caching for playlists, TMDB data, and watch history - KSPlayer integration for video playback Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
21
KSPlayer-main/Tests/KSPlayerTests/AudioTest.swift
Normal file
21
KSPlayer-main/Tests/KSPlayerTests/AudioTest.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
import AVFoundation
|
||||
@testable import KSPlayer
|
||||
import XCTest
|
||||
|
||||
class AudioTest: XCTestCase {
|
||||
func testChannelLayout() {
|
||||
for (tag, mask) in layoutMapTuple {
|
||||
assert(tag: tag, mask: mask)
|
||||
}
|
||||
}
|
||||
|
||||
private func assert(tag: AudioChannelLayoutTag, mask: UInt64) {
|
||||
let channelLayout = AVAudioChannelLayout(layout: tag.channelLayout)
|
||||
XCTAssertEqual(channelLayout.channelLayout().u.mask == mask, true)
|
||||
}
|
||||
|
||||
private func assert(bitmap: AudioChannelBitmap, mask: UInt64) {
|
||||
let channelLayout = AVAudioChannelLayout(layout: bitmap.channelLayout)
|
||||
XCTAssertEqual(channelLayout.channelLayout().u.mask == mask, true)
|
||||
}
|
||||
}
|
||||
53
KSPlayer-main/Tests/KSPlayerTests/KSAVPlayerTest.swift
Normal file
53
KSPlayer-main/Tests/KSPlayerTests/KSAVPlayerTest.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
@testable import KSPlayer
|
||||
import XCTest
|
||||
|
||||
class KSAVPlayerTest: XCTestCase {
|
||||
private var readyToPlayExpectation: XCTestExpectation?
|
||||
@MainActor
|
||||
func testPlayer() {
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "h264", ofType: "MP4") {
|
||||
set(path: path)
|
||||
}
|
||||
// if let path = Bundle(for: type(of: self)).path(forResource: "google-help-vr", ofType: "mp4") {
|
||||
// set(path: path)
|
||||
// }
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "mjpeg", ofType: "flac") {
|
||||
set(path: path)
|
||||
}
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "hevc", ofType: "mkv") {
|
||||
set(path: path)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func set(path: String) {
|
||||
let play = KSAVPlayer(url: URL(fileURLWithPath: path), options: KSOptions())
|
||||
play.delegate = self
|
||||
play.prepareToPlay()
|
||||
readyToPlayExpectation = expectation(description: "openVideo")
|
||||
waitForExpectations(timeout: 10) { _ in
|
||||
if play.isReadyToPlay {
|
||||
play.play()
|
||||
}
|
||||
play.shutdown()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension KSAVPlayerTest: MediaPlayerDelegate {
|
||||
func readyToPlay(player _: some MediaPlayerProtocol) {
|
||||
readyToPlayExpectation?.fulfill()
|
||||
}
|
||||
|
||||
func changeLoadState(player _: some MediaPlayerProtocol) {}
|
||||
|
||||
func changeBuffering(player _: some MediaPlayerProtocol, progress _: Int) {}
|
||||
|
||||
func playBack(player _: some MediaPlayerProtocol, loopCount _: Int) {}
|
||||
|
||||
func finish(player _: some MediaPlayerProtocol, error: Error?) {
|
||||
if error != nil {
|
||||
readyToPlayExpectation?.fulfill()
|
||||
}
|
||||
}
|
||||
}
|
||||
44
KSPlayer-main/Tests/KSPlayerTests/KSMEPlayerTest.swift
Normal file
44
KSPlayer-main/Tests/KSPlayerTests/KSMEPlayerTest.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
@testable import KSPlayer
|
||||
import XCTest
|
||||
|
||||
class KSMEPlayerTest: XCTestCase {
|
||||
@MainActor
|
||||
func testPlaying() {
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "h264", ofType: "mp4") {
|
||||
let options = KSOptions()
|
||||
let player = KSMEPlayer(url: URL(fileURLWithPath: path), options: options)
|
||||
player.delegate = self
|
||||
XCTAssertEqual(player.isPlaying, false)
|
||||
player.play()
|
||||
XCTAssertEqual(player.isPlaying, true)
|
||||
player.pause()
|
||||
XCTAssertEqual(player.isPlaying, false)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testAutoPlay() {
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "h264", ofType: "mp4") {
|
||||
let options = KSOptions()
|
||||
let player = KSMEPlayer(url: URL(fileURLWithPath: path), options: options)
|
||||
player.delegate = self
|
||||
XCTAssertEqual(player.isPlaying, false)
|
||||
player.play()
|
||||
XCTAssertEqual(player.isPlaying, true)
|
||||
player.pause()
|
||||
XCTAssertEqual(player.isPlaying, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension KSMEPlayerTest: MediaPlayerDelegate {
|
||||
func readyToPlay(player _: some KSPlayer.MediaPlayerProtocol) {}
|
||||
|
||||
func changeLoadState(player _: some KSPlayer.MediaPlayerProtocol) {}
|
||||
|
||||
func changeBuffering(player _: some KSPlayer.MediaPlayerProtocol, progress _: Int) {}
|
||||
|
||||
func playBack(player _: some KSPlayer.MediaPlayerProtocol, loopCount _: Int) {}
|
||||
|
||||
func finish(player _: some KSPlayer.MediaPlayerProtocol, error _: Error?) {}
|
||||
}
|
||||
69
KSPlayer-main/Tests/KSPlayerTests/KSPlayerLayerTest.swift
Normal file
69
KSPlayer-main/Tests/KSPlayerTests/KSPlayerLayerTest.swift
Normal file
@@ -0,0 +1,69 @@
|
||||
@testable import KSPlayer
|
||||
import XCTest
|
||||
|
||||
class KSPlayerLayerTest: XCTestCase {
|
||||
private var readyToPlayExpectation: XCTestExpectation?
|
||||
override func setUp() {
|
||||
KSOptions.secondPlayerType = KSMEPlayer.self
|
||||
KSOptions.isSecondOpen = true
|
||||
KSOptions.isAccurateSeek = true
|
||||
}
|
||||
|
||||
func testPlayerLayer() {
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "h264", ofType: "MP4") {
|
||||
set(path: path)
|
||||
}
|
||||
// if let path = Bundle(for: type(of: self)).path(forResource: "google-help-vr", ofType: "mp4") {
|
||||
// set(path: path)
|
||||
// }
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "mjpeg", ofType: "flac") {
|
||||
set(path: path)
|
||||
}
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "hevc", ofType: "mkv") {
|
||||
set(path: path)
|
||||
}
|
||||
}
|
||||
|
||||
func set(path: String) {
|
||||
let options = KSOptions()
|
||||
let playerLayer = KSPlayerLayer(url: URL(fileURLWithPath: path), options: options)
|
||||
playerLayer.delegate = self
|
||||
XCTAssertEqual(playerLayer.state, .preparing)
|
||||
readyToPlayExpectation = expectation(description: "openVideo")
|
||||
waitForExpectations(timeout: 2) { _ in
|
||||
XCTAssert(playerLayer.player.isReadyToPlay == true)
|
||||
XCTAssertEqual(playerLayer.state, .readyToPlay)
|
||||
playerLayer.play()
|
||||
playerLayer.pause()
|
||||
XCTAssertEqual(playerLayer.state, .paused)
|
||||
let seekExpectation = self.expectation(description: "seek")
|
||||
playerLayer.seek(time: 2, autoPlay: true) { _ in
|
||||
seekExpectation.fulfill()
|
||||
}
|
||||
XCTAssertEqual(playerLayer.state, .buffering)
|
||||
self.waitForExpectations(timeout: 1000) { _ in
|
||||
playerLayer.finish(player: playerLayer.player, error: nil)
|
||||
XCTAssertEqual(playerLayer.state, .playedToTheEnd)
|
||||
playerLayer.stop()
|
||||
XCTAssertEqual(playerLayer.state, .initialized)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension KSPlayerLayerTest: KSPlayerLayerDelegate {
|
||||
func player(layer _: KSPlayerLayer, state: KSPlayerState) {
|
||||
if state == .readyToPlay {
|
||||
readyToPlayExpectation?.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
func player(layer _: KSPlayerLayer, currentTime _: TimeInterval, totalTime _: TimeInterval) {}
|
||||
|
||||
func player(layer _: KSPlayerLayer, finish _: Error?) {}
|
||||
func player(layer _: KSPlayerLayer, bufferedCount: Int, consumeTime _: TimeInterval) {
|
||||
if bufferedCount > 0 {
|
||||
XCTFail()
|
||||
}
|
||||
}
|
||||
}
|
||||
27
KSPlayer-main/Tests/KSPlayerTests/M3UParseTest.swift
Normal file
27
KSPlayer-main/Tests/KSPlayerTests/M3UParseTest.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
@testable import KSPlayer
|
||||
import XCTest
|
||||
|
||||
class M3UParseTest: XCTestCase {
|
||||
func testParsePlaylist() {
|
||||
let data = """
|
||||
#EXTM3U url-tvg="http://epg.tvfor.pro/epgtv.xml"
|
||||
#EXTINF:-1 tvg-id="2365" tvg-name="Первый канал" tvg-logo="http://tvfor.pro/img/images/Chanels/perviy_k.png" group-title="Базовые" catchup="default" catchup-source="http://vandijk.tvfor.pro/ORT/TOKEN?utc=${start}" catchup-days="5" timeshift="5",Первый канал
|
||||
#EXTGRP:Базовые
|
||||
http://vandijk.tvfor.pro/Perviykanal/TOKEN
|
||||
#EXTINF:-1 tvg-id="2379" tvg-name="Первый канал HD" tvg-logo="http://tvfor.pro/img/images/Chanels/1tv_hd.png" group-title="Базовые" catchup="default" catchup-source="http://vandijk.tvfor.pro/CupLeTaWkn/TOKEN?utc=${start}" catchup-days="3" timeshift="3",Первый канал HD
|
||||
#EXTGRP:Базовые
|
||||
http://vandijk.tvfor.pro/CupLeTaWkn/TOKEN
|
||||
""".data(using: .utf8)
|
||||
if let data {
|
||||
let result = data.parsePlaylist()
|
||||
XCTAssertEqual(result.count == 2, true)
|
||||
}
|
||||
}
|
||||
|
||||
func testURLParse() async {
|
||||
// let url = Bundle(for: M3UParseTest.self).url(forResource: "test.m3u", withExtension: nil)!
|
||||
// if let result = try? await url.parsePlaylist() {
|
||||
// XCTAssertEqual(result.count > 0, true)
|
||||
// }
|
||||
}
|
||||
}
|
||||
17
KSPlayer-main/Tests/KSPlayerTests/Resources/test.m3u
Normal file
17
KSPlayer-main/Tests/KSPlayerTests/Resources/test.m3u
Normal file
@@ -0,0 +1,17 @@
|
||||
#EXTM3U
|
||||
#EXTINF:-1 group-title="test",mp4视频
|
||||
http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
|
||||
#EXTINF:-1 group-title="test",m3u8视频
|
||||
http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
|
||||
#EXTINF:-1 group-title="test",fmp4
|
||||
https://bitmovin-a.akamaihd.net/content/dataset/multi-codec/hevc/stream_fmp4.m3u8
|
||||
#EXTINF:-1 group-title="test",tvb视频
|
||||
http://116.199.5.51:8114/00000000/hls/index.m3u8?Fsv_chan_hls_se_idx=188&FvSeid=1&Fsv_ctype=LIVES&Fsv_otype=1&Provider_id=&Pcontent_id=.m3u8
|
||||
#EXTINF:-1 group-title="test",dash视频
|
||||
http://dash.edgesuite.net/akamai/bbb_30fps/bbb_30fps.mpd
|
||||
#EXTINF:-1 group-title="test",https视频
|
||||
https://devstreaming-cdn.apple.com/videos/wwdc/2019/244gmopitz5ezs2kkq/244/hls_vod_mvp.m3u8
|
||||
#EXTINF:-1 group-title="test",rtsp video
|
||||
rtsp://rtsp.stream/pattern
|
||||
#EXTINF:-1 group-title="test",HDR MKV
|
||||
https://github.com/qiudaomao/MPVColorIssue/raw/master/MPVColorIssue/resources/captain.marvel.2019.2160p.uhd.bluray.x265-terminal.sample.mkv
|
||||
102
KSPlayer-main/Tests/KSPlayerTests/SubtitleTest.swift
Normal file
102
KSPlayer-main/Tests/KSPlayerTests/SubtitleTest.swift
Normal file
@@ -0,0 +1,102 @@
|
||||
@testable import KSPlayer
|
||||
import XCTest
|
||||
|
||||
class SubtitleTest: XCTestCase {
|
||||
func testSrt() {
|
||||
let string = """
|
||||
1
|
||||
00:00:00,050 --> 00:00:11,000
|
||||
<font color="#4096d1">本字幕仅供学习交流,严禁用于商业用途</font>
|
||||
|
||||
2
|
||||
00:00:13,000 --> 00:00:18,000
|
||||
<font color=#4096d1>-=破烂熊字幕组=-
|
||||
翻译:风铃
|
||||
校对&时间轴:小白</font>
|
||||
|
||||
3
|
||||
00:01:00,840 --> 00:01:02,435
|
||||
你现在必须走了吗?
|
||||
|
||||
4
|
||||
00:01:02,680 --> 00:01:04,318
|
||||
我说过我会去找他的
|
||||
|
||||
5
|
||||
00:01:07,194 --> 00:01:08,239
|
||||
- 很多事情我们都说过
|
||||
- 我承诺过他
|
||||
|
||||
907
|
||||
00:59:47,520 --> 00:59:49,720
|
||||
有两个人在我们镇上
|
||||
There were two men in my hometown
|
||||
|
||||
908
|
||||
00:59:51,370 --> 00:59:55,170
|
||||
被判4F不合格,他们就自杀了,因为不能服役
|
||||
Declared 4-F unfit, they killed themselves cause they couldn't serve.
|
||||
|
||||
909
|
||||
00:59:55,750 --> 00:59:58,360
|
||||
注:4-F,二战服役有关的物理,心理,或道德标准。
|
||||
https://en.wikipedia.org/wiki/Selective_Service_System
|
||||
|
||||
http://www.apd.army.mil/pdffiles/r40_501.pdf
|
||||
|
||||
910
|
||||
00:59:59,220 --> 01:00:01,140
|
||||
为何?我在国防工厂有份工作
|
||||
Why, I had a job in a defense plant.
|
||||
|
||||
"""
|
||||
let scanner = Scanner(string: string)
|
||||
let parse = SrtParse()
|
||||
XCTAssertEqual(parse.canParse(scanner: scanner), true)
|
||||
let parts = parse.parse(scanner: scanner)
|
||||
XCTAssertEqual(parts.count, 9)
|
||||
XCTAssertEqual(parts[8].end, 3601.14)
|
||||
}
|
||||
|
||||
func testVtt() {
|
||||
let string = """
|
||||
WEBVTT
|
||||
1
|
||||
00:00:00,050 --> 00:00:11,000
|
||||
<font color="#4096d1">本字幕仅供学习交流,严禁用于商业用途</font>
|
||||
|
||||
2
|
||||
00:00:13,000 --> 00:00:18,000
|
||||
<font color=#4096d1>-=破烂熊字幕组=-
|
||||
翻译:风铃
|
||||
校对&时间轴:小白</font>
|
||||
|
||||
3
|
||||
00:01:00,840 --> 00:01:02,435
|
||||
你现在必须走了吗?
|
||||
|
||||
4
|
||||
00:01:02,680 --> 00:01:04,318
|
||||
我说过我会去找他的
|
||||
|
||||
5
|
||||
00:01:07,194 --> 00:01:08,239
|
||||
- 很多事情我们都说过
|
||||
- 我承诺过他
|
||||
|
||||
6
|
||||
00:01:08,280 --> 00:01:10,661
|
||||
我希望你明白
|
||||
|
||||
7
|
||||
00:01:12,814 --> 00:01:14,702
|
||||
等等! 你是不可能活着回来的!
|
||||
|
||||
"""
|
||||
let scanner = Scanner(string: string)
|
||||
let parse = VTTParse()
|
||||
XCTAssertEqual(parse.canParse(scanner: scanner), true)
|
||||
let parts = parse.parse(scanner: scanner)
|
||||
XCTAssertEqual(parts.count, 7)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@testable import KSPlayer
|
||||
import XCTest
|
||||
|
||||
class VideoPlayerControllerTest: XCTestCase {
|
||||
func testResize() {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@testable import KSPlayer
|
||||
import XCTest
|
||||
|
||||
class VideoPlayerViewTest: XCTestCase {
|
||||
func testResize() {}
|
||||
}
|
||||
Reference in New Issue
Block a user