Skip to content

Commit b2b2ba1

Browse files
committed
Merge develop into master.v0.3-build(b97b850).
2 parents 1b06faa + b97b850 commit b2b2ba1

17 files changed

+823
-93
lines changed

iina+.xcodeproj/project.pbxproj

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
01260171211948BF00C9C639 /* PreferencesTabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01260170211948BF00C9C639 /* PreferencesTabViewController.swift */; };
2929
012601742119FBF400C9C639 /* BilibiliCardTableCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012601732119FBF400C9C639 /* BilibiliCardTableCellView.swift */; };
3030
01260178211ABD3B00C9C639 /* VideoViewsFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01260177211ABD3B00C9C639 /* VideoViewsFormatter.swift */; };
31+
0132B2E32123D05E001EB7DC /* BilibiliCardProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0132B2E22123D05E001EB7DC /* BilibiliCardProgressView.swift */; };
32+
0132B2E52123D68D001EB7DC /* BilibiliCardImageBoxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0132B2E42123D68D001EB7DC /* BilibiliCardImageBoxView.swift */; };
3133
01398983210F273200B7042F /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01398982210F273200B7042F /* PreferencesView.swift */; };
3234
01398985210F27A600B7042F /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01398984210F27A600B7042F /* PreferencesWindowController.swift */; };
3335
01398987210F58E500B7042F /* MainWindowTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01398986210F58E500B7042F /* MainWindowTableRowView.swift */; };
@@ -36,6 +38,10 @@
3638
01479CD7210B35480046AAAD /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01479CD6210B35480046AAAD /* MainMenu.swift */; };
3739
014B447D210069FF00E7AA6A /* Bookmark.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014B447B210069FF00E7AA6A /* Bookmark.swift */; };
3840
014B447E210069FF00E7AA6A /* BookmarkExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014B447C210069FF00E7AA6A /* BookmarkExtension.swift */; };
41+
016792E1212BBB43003517A7 /* SelectVideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016792E0212BBB43003517A7 /* SelectVideoViewController.swift */; };
42+
016792E6212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016792E4212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift */; };
43+
016792E7212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 016792E5212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib */; };
44+
016792EE212C421F003517A7 /* SelectVideoCollectionViewItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016792ED212C421F003517A7 /* SelectVideoCollectionViewItemView.swift */; };
3945
01683DD9211869AE0016A886 /* BilibiliLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01683DD8211869AE0016A886 /* BilibiliLoginViewController.swift */; };
4046
01683DDB2118905D0016A886 /* Bilibili.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01683DDA2118905D0016A886 /* Bilibili.swift */; };
4147
01683DDE211924160016A886 /* BilibiliViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01683DDD211924160016A886 /* BilibiliViewController.swift */; };
@@ -101,6 +107,8 @@
101107
01260170211948BF00C9C639 /* PreferencesTabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesTabViewController.swift; sourceTree = "<group>"; };
102108
012601732119FBF400C9C639 /* BilibiliCardTableCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliCardTableCellView.swift; sourceTree = "<group>"; };
103109
01260177211ABD3B00C9C639 /* VideoViewsFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoViewsFormatter.swift; sourceTree = "<group>"; };
110+
0132B2E22123D05E001EB7DC /* BilibiliCardProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliCardProgressView.swift; sourceTree = "<group>"; };
111+
0132B2E42123D68D001EB7DC /* BilibiliCardImageBoxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliCardImageBoxView.swift; sourceTree = "<group>"; };
104112
01398982210F273200B7042F /* PreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
105113
01398984210F27A600B7042F /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
106114
01398986210F58E500B7042F /* MainWindowTableRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowTableRowView.swift; sourceTree = "<group>"; };
@@ -110,6 +118,10 @@
110118
014B447B210069FF00E7AA6A /* Bookmark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bookmark.swift; sourceTree = "<group>"; };
111119
014B447C210069FF00E7AA6A /* BookmarkExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkExtension.swift; sourceTree = "<group>"; };
112120
014FD3A42115CB3000F05399 /* Bookmark v0.2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Bookmark v0.2.xcdatamodel"; sourceTree = "<group>"; };
121+
016792E0212BBB43003517A7 /* SelectVideoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectVideoViewController.swift; sourceTree = "<group>"; };
122+
016792E4212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectVideoCollectionViewItem.swift; sourceTree = "<group>"; };
123+
016792E5212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SelectVideoCollectionViewItem.xib; sourceTree = "<group>"; };
124+
016792ED212C421F003517A7 /* SelectVideoCollectionViewItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectVideoCollectionViewItemView.swift; sourceTree = "<group>"; };
113125
01683DD8211869AE0016A886 /* BilibiliLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliLoginViewController.swift; sourceTree = "<group>"; };
114126
01683DDA2118905D0016A886 /* Bilibili.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bilibili.swift; sourceTree = "<group>"; };
115127
01683DDD211924160016A886 /* BilibiliViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliViewController.swift; sourceTree = "<group>"; };
@@ -164,6 +176,8 @@
164176
012601732119FBF400C9C639 /* BilibiliCardTableCellView.swift */,
165177
0101012F211E987D002F0F7F /* SuggestionsTableCellView.swift */,
166178
01010130211E987D002F0F7F /* WaitingTableCellView.swift */,
179+
0132B2E22123D05E001EB7DC /* BilibiliCardProgressView.swift */,
180+
0132B2E42123D68D001EB7DC /* BilibiliCardImageBoxView.swift */,
167181
);
168182
path = TableViewCustomViews;
169183
sourceTree = "<group>";
@@ -222,6 +236,7 @@
222236
isa = PBXGroup;
223237
children = (
224238
01010133211E9AA1002F0F7F /* TableViewCustomViews */,
239+
016792E8212BF89A003517A7 /* SelectVideoCollectionView */,
225240
010F0EF120F890DB00F33553 /* MainWindowController.swift */,
226241
01AEC8AC20EDFD01001406E8 /* MainViewController.swift */,
227242
01010134211EC63D002F0F7F /* MainTabView.swift */,
@@ -232,6 +247,17 @@
232247
path = MainWindow;
233248
sourceTree = "<group>";
234249
};
250+
016792E8212BF89A003517A7 /* SelectVideoCollectionView */ = {
251+
isa = PBXGroup;
252+
children = (
253+
016792E0212BBB43003517A7 /* SelectVideoViewController.swift */,
254+
016792E4212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift */,
255+
016792ED212C421F003517A7 /* SelectVideoCollectionViewItemView.swift */,
256+
016792E5212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib */,
257+
);
258+
path = SelectVideoCollectionView;
259+
sourceTree = "<group>";
260+
};
235261
01AEC89E20EDFD01001406E8 = {
236262
isa = PBXGroup;
237263
children = (
@@ -298,6 +324,7 @@
298324
01AEC8A520EDFD01001406E8 /* Resources */,
299325
010F0F0E20FCC18000F33553 /* Embed Frameworks */,
300326
010F0F0F20FCC1D200F33553 /* CopyFiles */,
327+
019BFF5D212485B900E715CC /* ShellScript */,
301328
);
302329
buildRules = (
303330
);
@@ -359,25 +386,48 @@
359386
buildActionMask = 2147483647;
360387
files = (
361388
01AEC8AF20EDFD02001406E8 /* Assets.xcassets in Resources */,
389+
016792E7212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib in Resources */,
362390
01AEC8B220EDFD02001406E8 /* Main.storyboard in Resources */,
363391
);
364392
runOnlyForDeploymentPostprocessing = 0;
365393
};
366394
/* End PBXResourcesBuildPhase section */
367395

396+
/* Begin PBXShellScriptBuildPhase section */
397+
019BFF5D212485B900E715CC /* ShellScript */ = {
398+
isa = PBXShellScriptBuildPhase;
399+
buildActionMask = 8;
400+
files = (
401+
);
402+
inputFileListPaths = (
403+
);
404+
inputPaths = (
405+
);
406+
outputFileListPaths = (
407+
);
408+
outputPaths = (
409+
);
410+
runOnlyForDeploymentPostprocessing = 1;
411+
shellPath = /bin/sh;
412+
shellScript = "#!/bin/bash\nBUILD_NUMBER=`git rev-parse --short HEAD`\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $BUILD_NUMBER\" \"${TARGET_BUILD_DIR}\"/\"${INFOPLIST_PATH}\"\n";
413+
};
414+
/* End PBXShellScriptBuildPhase section */
415+
368416
/* Begin PBXSourcesBuildPhase section */
369417
01AEC8A320EDFD01001406E8 /* Sources */ = {
370418
isa = PBXSourcesBuildPhase;
371419
buildActionMask = 2147483647;
372420
files = (
373421
010F0F1920FE4F0900F33553 /* DataModel.xcdatamodeld in Sources */,
422+
016792E6212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift in Sources */,
374423
0101013921200DC5002F0F7F /* LiveUrlTableCellView.swift in Sources */,
375424
01479CD3210AF5F40046AAAD /* DataManager.swift in Sources */,
376425
01398985210F27A600B7042F /* PreferencesWindowController.swift in Sources */,
377426
01AEC8BE20EE108B001406E8 /* Processes.swift in Sources */,
378427
012601742119FBF400C9C639 /* BilibiliCardTableCellView.swift in Sources */,
379428
01010127211DCAE8002F0F7F /* SidebarViewController.swift in Sources */,
380429
01AEC8C220EFBCCF001406E8 /* MPVOption.swift in Sources */,
430+
016792EE212C421F003517A7 /* SelectVideoCollectionViewItemView.swift in Sources */,
381431
01AEC8C920F1081C001406E8 /* Identifiers.swift in Sources */,
382432
01010125211DBC27002F0F7F /* StringExtension.swift in Sources */,
383433
0196CB6421214B4200BCD29E /* AdvancedViewController.swift in Sources */,
@@ -396,6 +446,7 @@
396446
014B447D210069FF00E7AA6A /* Bookmark.swift in Sources */,
397447
01398987210F58E500B7042F /* MainWindowTableRowView.swift in Sources */,
398448
01AEC8BC20EDFFBD001406E8 /* YouGetJSON.swift in Sources */,
449+
0132B2E52123D68D001EB7DC /* BilibiliCardImageBoxView.swift in Sources */,
399450
01683DD9211869AE0016A886 /* BilibiliLoginViewController.swift in Sources */,
400451
0196CB62212143D600BCD29E /* Logger.swift in Sources */,
401452
010F0F1320FE1DD100F33553 /* Preferences.swift in Sources */,
@@ -407,6 +458,8 @@
407458
01AEC8AB20EDFD01001406E8 /* AppDelegate.swift in Sources */,
408459
01010137211EFA75002F0F7F /* SuggestionsTableView.swift in Sources */,
409460
01E6A09C211AD62800C6EF98 /* VideoDurationFormatter.swift in Sources */,
461+
0132B2E32123D05E001EB7DC /* BilibiliCardProgressView.swift in Sources */,
462+
016792E1212BBB43003517A7 /* SelectVideoViewController.swift in Sources */,
410463
0101012E211DE83B002F0F7F /* SidebarTableView.swift in Sources */,
411464
);
412465
runOnlyForDeploymentPostprocessing = 0;

iina+/AppDelegate.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
7575
// Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user.
7676
let context = persistentContainer.viewContext
7777

78-
if !context.commitEditing() {
79-
NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing before saving")
80-
}
78+
// if !context.commitEditing() {
79+
// NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing before saving")
80+
// }
8181
if context.hasChanges {
8282
do {
8383
try context.save()
@@ -98,10 +98,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
9898
// Save changes in the application's managed object context before the application terminates.
9999
let context = persistentContainer.viewContext
100100

101-
if !context.commitEditing() {
102-
NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate")
103-
return .terminateCancel
104-
}
101+
// if !context.commitEditing() {
102+
// NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate")
103+
// return .terminateCancel
104+
// }
105105

106106
if !context.hasChanges {
107107
return .terminateNow

iina+/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>0.2</string>
20+
<string>0.3</string>
2121
<key>CFBundleVersion</key>
22-
<string>2</string>
22+
<string>0</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.video</string>
2525
<key>LSMinimumSystemVersion</key>

iina+/Utils/Bilibili.swift

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import Cocoa
1010
import SwiftHTTP
1111
import Marshal
12-
import PromiseKit
1312

1413
@objc(BilibiliCard)
1514
class BilibiliCard: NSObject, Unmarshaling {
@@ -20,6 +19,7 @@ class BilibiliCard: NSObject, Unmarshaling {
2019
@objc var name: String = ""
2120
@objc var duration: TimeInterval = 0
2221
@objc var views: Int = 0
22+
@objc var videos: Int = 0
2323
// var pubdate = 1533581945
2424

2525

@@ -43,6 +43,7 @@ class BilibiliCard: NSObject, Unmarshaling {
4343
duration = try json.value(for: "duration")
4444
name = try json.value(for: "owner.name")
4545
views = try json.value(for: "stat.view")
46+
videos = try json.value(for: "videos")
4647
}
4748
}
4849
}
@@ -51,6 +52,101 @@ enum BilibiliDynamicAction {
5152
case `init`, new, history
5253
}
5354

55+
struct BilibiliPvideo: Unmarshaling {
56+
var images: [NSImage] = []
57+
var pImages: [NSImage] = []
58+
var xLen: Int = 0
59+
var yLen: Int = 0
60+
var xSize: Int = 0
61+
var ySize: Int = 0
62+
var imagesCount: Int = 0
63+
64+
enum CropImagesError: Error {
65+
case zeroImagesCount
66+
}
67+
68+
init(object: MarshaledObject) throws {
69+
let imageStrs: [String] = try object.value(for: "data.image")
70+
// images = imageStrs.compactMap { str -> NSImage? in
71+
// if let url = URL(string: str.replacingOccurrences(of: "http://", with: "https://")) {
72+
// return NSImage(contentsOf: url)
73+
// } else {
74+
// return nil
75+
// }
76+
// }
77+
let indexs: [Int] = try object.value(for: "data.index")
78+
imagesCount = indexs.count
79+
// limit image count for performance
80+
if imagesCount > 100 {
81+
imagesCount = 100
82+
} else if imagesCount == 0 {
83+
throw CropImagesError.zeroImagesCount
84+
}
85+
if let iamgeStr = imageStrs.first,
86+
let url = URL(string: iamgeStr.replacingOccurrences(of: "http://", with: "https://")),
87+
let image = NSImage(contentsOf: url) {
88+
images = [image]
89+
}
90+
91+
xLen = try object.value(for: "data.img_x_len")
92+
yLen = try object.value(for: "data.img_y_len")
93+
xSize = try object.value(for: "data.img_x_size")
94+
ySize = try object.value(for: "data.img_y_size")
95+
}
96+
97+
mutating func cropImages() {
98+
var pImages: [NSImage] = []
99+
var limitCount = 0
100+
images.forEach { image in
101+
var xIndex = 0
102+
var yIndex = 0
103+
104+
if limitCount < imagesCount {
105+
while yIndex < yLen {
106+
while xIndex < xLen {
107+
let rect = NSRect(x: xIndex * xSize, y: yIndex * ySize, width: xSize, height: ySize)
108+
109+
if let croppedImage = crop(image, with: rect) {
110+
pImages.append(croppedImage)
111+
}
112+
limitCount += 1
113+
if limitCount == imagesCount {
114+
xIndex = 10
115+
yIndex = 10
116+
}
117+
xIndex += 1
118+
if xIndex == xLen {
119+
xIndex = 0
120+
yIndex += 1
121+
}
122+
}
123+
}
124+
}
125+
}
126+
self.pImages = pImages
127+
}
128+
129+
func crop(_ image: NSImage, with rect: NSRect) -> NSImage? {
130+
guard let croppedImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)?.cropping(to: rect) else {
131+
return nil
132+
}
133+
let reImage = NSImage(cgImage: croppedImage, size: rect.size)
134+
return reImage
135+
}
136+
}
137+
138+
struct BilibiliSimpleVideoInfo: Unmarshaling {
139+
var page: Int = 0
140+
var part: String = ""
141+
var duration: TimeInterval = 0
142+
143+
init(object: MarshaledObject) throws {
144+
page = try object.value(for: "page")
145+
part = try object.value(for: "part")
146+
duration = try object.value(for: "duration")
147+
}
148+
}
149+
54150
class Bilibili: NSObject {
55151

56152
func isLogin(_ isLoginBlock: ((Bool) -> Void)?,
@@ -132,6 +228,33 @@ class Bilibili: NSObject {
132228
}
133229
}
134230

231+
func getPvideo(_ aid: Int,
232+
_ block: @escaping ((BilibiliPvideo) -> Void),
233+
_ error: @escaping ((HTTPErrorCallback) -> Void)) {
234+
guard aid != 0 else { return }
235+
HTTP.GET("https://api.bilibili.com/pvideo?aid=\(aid)") { response in
236+
error {
237+
let json: JSONObject = try JSONParser.JSONObjectWithData(response.data)
238+
var pvideo = try BilibiliPvideo.init(object: json)
239+
pvideo.cropImages()
240+
block(pvideo)
241+
return false
242+
}
243+
}
244+
}
245+
246+
func getVideoList(_ aid: Int,
247+
_ block: @escaping (([BilibiliSimpleVideoInfo]) -> Void),
248+
_ error: @escaping ((HTTPErrorCallback) -> Void)) {
249+
HTTP.GET("https://api.bilibili.com/x/player/pagelist?aid=\(aid)") { response in
250+
error {
251+
let json: JSONObject = try JSONParser.JSONObjectWithData(response.data)
252+
let infos: [BilibiliSimpleVideoInfo] = try json.value(for: "data")
253+
block(infos)
254+
return false
255+
}
256+
}
257+
}
135258
}
136259

137260

0 commit comments

Comments
 (0)