-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Course bars: Download videos to device and Select download quality bars #239
Changes from 55 commits
5370d1d
9e16130
32ad2ea
f88fe44
82bb2ff
f1d9872
f191a36
fdca041
e6a448a
d2258ef
68b6e17
4030157
ae7db32
02ccce8
1f40b96
ebc81cd
0b1a83e
451ee45
4b5ea44
0f8a930
16b956f
930b1c8
7e6c218
24983d2
6d9e3cb
a868a69
fcdb31d
348b1bc
5257f37
23b01a4
269a084
a1f9f1d
f288e68
d50e4d1
acfc9c8
c1d65e4
2f8709a
b5761cc
bb69379
a3972ad
02a59d0
71460e1
209c1a0
6298260
475328e
7b30bf0
8b7723b
86c9d48
5f698fe
e18a7f1
320daf6
63512f7
0c3a656
19c3564
6125d9a
6b635c2
0b16dc6
8dc472b
50b1649
ab1792a
e7c3b61
ccca6a7
fb20cae
d5f904b
318b1ab
d4c88cf
d67ef53
d705e59
57aad7f
baca08c
3c099bf
376368d
81a4512
22fa31f
f7f1ad5
a64de26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,15 @@ import Combine | |
|
||
public protocol CorePersistenceProtocol { | ||
func publisher() -> AnyPublisher<Int, Never> | ||
func getAllDownloadData() -> [DownloadData] | ||
func addToDownloadQueue(blocks: [CourseBlock]) | ||
func addToDownloadQueue(blocks: [CourseBlock], quality: DownloadQuality) | ||
func getNextBlockForDownloading() -> DownloadData? | ||
func getDownloadsForCourse(_ courseId: String) -> [DownloadData] | ||
func downloadData(by blockId: String) -> DownloadData? | ||
func updateDownloadState(id: String, state: DownloadState, resumeData: Data?) | ||
func deleteDownloadData(id: String) throws | ||
func saveDownloadData(data: DownloadData) | ||
func downloadData(by blockId: String) -> DownloadData? | ||
func downloadData(by blockId: String, completion: @escaping (DownloadData?) -> Void) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming |
||
func getAllDownloadData(completion: @escaping ([DownloadData]) -> Void) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about renaming it to |
||
func getDownloadsForCourse(_ courseId: String, completion: @escaping ([DownloadData]) -> Void) | ||
} | ||
|
||
public final class CoreBundle { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ | |
import Foundation | ||
|
||
public struct CourseStructure: Equatable { | ||
public static func == (lhs: CourseStructure, rhs: CourseStructure) -> Bool { | ||
return lhs.id == rhs.id | ||
} | ||
|
||
public let id: String | ||
public let graded: Bool | ||
public let completion: Double | ||
|
@@ -42,11 +46,24 @@ public struct CourseStructure: Equatable { | |
self.media = media | ||
self.certificate = certificate | ||
} | ||
|
||
public static func == (lhs: CourseStructure, rhs: CourseStructure) -> Bool { | ||
return lhs.id == rhs.id | ||
|
||
public func blocksTotalSizeInBytes(quality: DownloadQuality) -> Int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming it to |
||
childs.flatMap { | ||
$0.childs.flatMap { $0.childs.flatMap { $0.childs.compactMap { $0 } } } | ||
} | ||
.filter { $0.isDownloadable } | ||
.compactMap { $0.video(quality: quality)?.fileSize } | ||
.reduce(.zero) { $0 + $1 } | ||
} | ||
|
||
|
||
public func blocksTotalSizeInMb(quality: DownloadQuality) -> Double { | ||
Double(blocksTotalSizeInBytes(quality: quality)) / 1024.0 / 1024.0 | ||
} | ||
|
||
public func blocksTotalSizeInGb(quality: DownloadQuality) -> Double { | ||
Double(blocksTotalSizeInBytes(quality: quality)) / 1024.0 / 1024.0 / 1024.0 | ||
} | ||
|
||
} | ||
|
||
public struct CourseChapter: Identifiable { | ||
|
@@ -102,7 +119,11 @@ public struct CourseSequential: Identifiable { | |
} | ||
} | ||
|
||
public struct CourseVertical { | ||
public struct CourseVertical: Identifiable, Hashable { | ||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(id) | ||
} | ||
|
||
public let blockId: String | ||
public let id: String | ||
public let courseId: String | ||
|
@@ -114,7 +135,7 @@ public struct CourseVertical { | |
public var isDownloadable: Bool { | ||
return childs.first(where: { $0.isDownloadable }) != nil | ||
} | ||
|
||
public init( | ||
blockId: String, | ||
id: String, | ||
|
@@ -144,7 +165,11 @@ public struct SubtitleUrl: Equatable { | |
} | ||
} | ||
|
||
public struct CourseBlock: Equatable { | ||
public struct CourseBlock: Hashable { | ||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(id) | ||
} | ||
|
||
public let blockId: String | ||
public let id: String | ||
public let courseId: String | ||
|
@@ -155,13 +180,43 @@ public struct CourseBlock: Equatable { | |
public let displayName: String | ||
public let studentUrl: String | ||
public let subtitles: [SubtitleUrl]? | ||
public let videoUrl: String? | ||
public let youTubeUrl: String? | ||
|
||
public let fallback: CourseBlockVideo? | ||
public let desktopMP4: CourseBlockVideo? | ||
public let mobileHigh: CourseBlockVideo? | ||
public let mobileLow: CourseBlockVideo? | ||
public let hls: CourseBlockVideo? | ||
public let youTube: CourseBlockVideo? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo, youtube. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we bundle it somehow? passing all the supported encodings as parameters seems a bit odd. |
||
|
||
public var isDownloadable: Bool { | ||
return videoUrl != nil | ||
[hls, desktopMP4, mobileHigh, mobileLow, fallback] | ||
.contains { $0?.isDownloadable == true } | ||
} | ||
|
||
|
||
public func video(quality: DownloadQuality) -> CourseBlockVideo? { | ||
switch quality { | ||
case .auto: | ||
[mobileLow, mobileHigh, desktopMP4, fallback, hls] | ||
.first(where: { $0?.isDownloadable == true })? | ||
.flatMap { $0 } | ||
case .high_720: | ||
[desktopMP4, mobileHigh, mobileLow, fallback, hls] | ||
.first(where: { $0?.isDownloadable == true })? | ||
.flatMap { $0 } | ||
case .medium_540: | ||
[mobileHigh, mobileLow, desktopMP4, fallback, hls] | ||
.first(where: { $0?.isDownloadable == true })? | ||
.flatMap { $0 } | ||
case .low_360: | ||
[mobileLow, mobileHigh, desktopMP4, fallback, hls] | ||
.first(where: { $0?.isDownloadable == true })? | ||
.flatMap { $0 } | ||
} | ||
} | ||
|
||
public var youTubeUrl: String? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming it to youtubeVideoUrl? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming it to youtubeUrl? |
||
youTube?.url | ||
} | ||
|
||
public init( | ||
blockId: String, | ||
id: String, | ||
|
@@ -173,8 +228,12 @@ public struct CourseBlock: Equatable { | |
displayName: String, | ||
studentUrl: String, | ||
subtitles: [SubtitleUrl]? = nil, | ||
videoUrl: String? = nil, | ||
youTubeUrl: String? = nil | ||
fallback: CourseBlockVideo?, | ||
youTube: CourseBlockVideo?, | ||
desktopMP4: CourseBlockVideo?, | ||
mobileHigh: CourseBlockVideo?, | ||
mobileLow: CourseBlockVideo?, | ||
hls: CourseBlockVideo? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we bundle it because it seems a bit odd to pass all the encodings as parameters? |
||
) { | ||
self.blockId = blockId | ||
self.id = id | ||
|
@@ -186,7 +245,31 @@ public struct CourseBlock: Equatable { | |
self.displayName = displayName | ||
self.studentUrl = studentUrl | ||
self.subtitles = subtitles | ||
self.videoUrl = videoUrl | ||
self.youTubeUrl = youTubeUrl | ||
self.fallback = fallback | ||
self.youTube = youTube | ||
self.desktopMP4 = desktopMP4 | ||
self.mobileHigh = mobileHigh | ||
self.mobileLow = mobileLow | ||
self.hls = hls | ||
} | ||
} | ||
|
||
public struct CourseBlockVideo: Equatable { | ||
public let url: String? | ||
public let fileSize: Int? | ||
public let streamPriority: Int? | ||
|
||
public init(url: String?, fileSize: Int?, streamPriority: Int?) { | ||
self.url = url | ||
self.fileSize = fileSize | ||
self.streamPriority = streamPriority | ||
} | ||
|
||
public var isVideoURL: Bool { | ||
[".mp4", ".m3u8"].contains(where: { url?.contains($0) == true }) | ||
} | ||
|
||
public var isDownloadable: Bool { | ||
[".mp4"].contains(where: { url?.contains($0) == true }) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about renaming it to
downloadedData(for blockId.....)
because it's returning data frompersistence
Thoughts?