Skip to content

Commit

Permalink
Merge develop into master.v0.3-build(b97b850).
Browse files Browse the repository at this point in the history
  • Loading branch information
xjbeta committed Aug 22, 2018
2 parents 1b06faa + b97b850 commit b2b2ba1
Show file tree
Hide file tree
Showing 17 changed files with 823 additions and 93 deletions.
53 changes: 53 additions & 0 deletions iina+.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
01260171211948BF00C9C639 /* PreferencesTabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01260170211948BF00C9C639 /* PreferencesTabViewController.swift */; };
012601742119FBF400C9C639 /* BilibiliCardTableCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012601732119FBF400C9C639 /* BilibiliCardTableCellView.swift */; };
01260178211ABD3B00C9C639 /* VideoViewsFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01260177211ABD3B00C9C639 /* VideoViewsFormatter.swift */; };
0132B2E32123D05E001EB7DC /* BilibiliCardProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0132B2E22123D05E001EB7DC /* BilibiliCardProgressView.swift */; };
0132B2E52123D68D001EB7DC /* BilibiliCardImageBoxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0132B2E42123D68D001EB7DC /* BilibiliCardImageBoxView.swift */; };
01398983210F273200B7042F /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01398982210F273200B7042F /* PreferencesView.swift */; };
01398985210F27A600B7042F /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01398984210F27A600B7042F /* PreferencesWindowController.swift */; };
01398987210F58E500B7042F /* MainWindowTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01398986210F58E500B7042F /* MainWindowTableRowView.swift */; };
Expand All @@ -36,6 +38,10 @@
01479CD7210B35480046AAAD /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01479CD6210B35480046AAAD /* MainMenu.swift */; };
014B447D210069FF00E7AA6A /* Bookmark.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014B447B210069FF00E7AA6A /* Bookmark.swift */; };
014B447E210069FF00E7AA6A /* BookmarkExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014B447C210069FF00E7AA6A /* BookmarkExtension.swift */; };
016792E1212BBB43003517A7 /* SelectVideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016792E0212BBB43003517A7 /* SelectVideoViewController.swift */; };
016792E6212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016792E4212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift */; };
016792E7212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 016792E5212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib */; };
016792EE212C421F003517A7 /* SelectVideoCollectionViewItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016792ED212C421F003517A7 /* SelectVideoCollectionViewItemView.swift */; };
01683DD9211869AE0016A886 /* BilibiliLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01683DD8211869AE0016A886 /* BilibiliLoginViewController.swift */; };
01683DDB2118905D0016A886 /* Bilibili.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01683DDA2118905D0016A886 /* Bilibili.swift */; };
01683DDE211924160016A886 /* BilibiliViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01683DDD211924160016A886 /* BilibiliViewController.swift */; };
Expand Down Expand Up @@ -101,6 +107,8 @@
01260170211948BF00C9C639 /* PreferencesTabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesTabViewController.swift; sourceTree = "<group>"; };
012601732119FBF400C9C639 /* BilibiliCardTableCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliCardTableCellView.swift; sourceTree = "<group>"; };
01260177211ABD3B00C9C639 /* VideoViewsFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoViewsFormatter.swift; sourceTree = "<group>"; };
0132B2E22123D05E001EB7DC /* BilibiliCardProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliCardProgressView.swift; sourceTree = "<group>"; };
0132B2E42123D68D001EB7DC /* BilibiliCardImageBoxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliCardImageBoxView.swift; sourceTree = "<group>"; };
01398982210F273200B7042F /* PreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
01398984210F27A600B7042F /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
01398986210F58E500B7042F /* MainWindowTableRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowTableRowView.swift; sourceTree = "<group>"; };
Expand All @@ -110,6 +118,10 @@
014B447B210069FF00E7AA6A /* Bookmark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bookmark.swift; sourceTree = "<group>"; };
014B447C210069FF00E7AA6A /* BookmarkExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkExtension.swift; sourceTree = "<group>"; };
014FD3A42115CB3000F05399 /* Bookmark v0.2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Bookmark v0.2.xcdatamodel"; sourceTree = "<group>"; };
016792E0212BBB43003517A7 /* SelectVideoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectVideoViewController.swift; sourceTree = "<group>"; };
016792E4212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectVideoCollectionViewItem.swift; sourceTree = "<group>"; };
016792E5212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SelectVideoCollectionViewItem.xib; sourceTree = "<group>"; };
016792ED212C421F003517A7 /* SelectVideoCollectionViewItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectVideoCollectionViewItemView.swift; sourceTree = "<group>"; };
01683DD8211869AE0016A886 /* BilibiliLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliLoginViewController.swift; sourceTree = "<group>"; };
01683DDA2118905D0016A886 /* Bilibili.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bilibili.swift; sourceTree = "<group>"; };
01683DDD211924160016A886 /* BilibiliViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BilibiliViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -164,6 +176,8 @@
012601732119FBF400C9C639 /* BilibiliCardTableCellView.swift */,
0101012F211E987D002F0F7F /* SuggestionsTableCellView.swift */,
01010130211E987D002F0F7F /* WaitingTableCellView.swift */,
0132B2E22123D05E001EB7DC /* BilibiliCardProgressView.swift */,
0132B2E42123D68D001EB7DC /* BilibiliCardImageBoxView.swift */,
);
path = TableViewCustomViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -222,6 +236,7 @@
isa = PBXGroup;
children = (
01010133211E9AA1002F0F7F /* TableViewCustomViews */,
016792E8212BF89A003517A7 /* SelectVideoCollectionView */,
010F0EF120F890DB00F33553 /* MainWindowController.swift */,
01AEC8AC20EDFD01001406E8 /* MainViewController.swift */,
01010134211EC63D002F0F7F /* MainTabView.swift */,
Expand All @@ -232,6 +247,17 @@
path = MainWindow;
sourceTree = "<group>";
};
016792E8212BF89A003517A7 /* SelectVideoCollectionView */ = {
isa = PBXGroup;
children = (
016792E0212BBB43003517A7 /* SelectVideoViewController.swift */,
016792E4212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift */,
016792ED212C421F003517A7 /* SelectVideoCollectionViewItemView.swift */,
016792E5212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib */,
);
path = SelectVideoCollectionView;
sourceTree = "<group>";
};
01AEC89E20EDFD01001406E8 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -298,6 +324,7 @@
01AEC8A520EDFD01001406E8 /* Resources */,
010F0F0E20FCC18000F33553 /* Embed Frameworks */,
010F0F0F20FCC1D200F33553 /* CopyFiles */,
019BFF5D212485B900E715CC /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -359,25 +386,48 @@
buildActionMask = 2147483647;
files = (
01AEC8AF20EDFD02001406E8 /* Assets.xcassets in Resources */,
016792E7212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib in Resources */,
01AEC8B220EDFD02001406E8 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
019BFF5D212485B900E715CC /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 8;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 1;
shellPath = /bin/sh;
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";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
01AEC8A320EDFD01001406E8 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
010F0F1920FE4F0900F33553 /* DataModel.xcdatamodeld in Sources */,
016792E6212BDEE5003517A7 /* SelectVideoCollectionViewItem.swift in Sources */,
0101013921200DC5002F0F7F /* LiveUrlTableCellView.swift in Sources */,
01479CD3210AF5F40046AAAD /* DataManager.swift in Sources */,
01398985210F27A600B7042F /* PreferencesWindowController.swift in Sources */,
01AEC8BE20EE108B001406E8 /* Processes.swift in Sources */,
012601742119FBF400C9C639 /* BilibiliCardTableCellView.swift in Sources */,
01010127211DCAE8002F0F7F /* SidebarViewController.swift in Sources */,
01AEC8C220EFBCCF001406E8 /* MPVOption.swift in Sources */,
016792EE212C421F003517A7 /* SelectVideoCollectionViewItemView.swift in Sources */,
01AEC8C920F1081C001406E8 /* Identifiers.swift in Sources */,
01010125211DBC27002F0F7F /* StringExtension.swift in Sources */,
0196CB6421214B4200BCD29E /* AdvancedViewController.swift in Sources */,
Expand All @@ -396,6 +446,7 @@
014B447D210069FF00E7AA6A /* Bookmark.swift in Sources */,
01398987210F58E500B7042F /* MainWindowTableRowView.swift in Sources */,
01AEC8BC20EDFFBD001406E8 /* YouGetJSON.swift in Sources */,
0132B2E52123D68D001EB7DC /* BilibiliCardImageBoxView.swift in Sources */,
01683DD9211869AE0016A886 /* BilibiliLoginViewController.swift in Sources */,
0196CB62212143D600BCD29E /* Logger.swift in Sources */,
010F0F1320FE1DD100F33553 /* Preferences.swift in Sources */,
Expand All @@ -407,6 +458,8 @@
01AEC8AB20EDFD01001406E8 /* AppDelegate.swift in Sources */,
01010137211EFA75002F0F7F /* SuggestionsTableView.swift in Sources */,
01E6A09C211AD62800C6EF98 /* VideoDurationFormatter.swift in Sources */,
0132B2E32123D05E001EB7DC /* BilibiliCardProgressView.swift in Sources */,
016792E1212BBB43003517A7 /* SelectVideoViewController.swift in Sources */,
0101012E211DE83B002F0F7F /* SidebarTableView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
14 changes: 7 additions & 7 deletions iina+/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// 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.
let context = persistentContainer.viewContext

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

if !context.commitEditing() {
NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate")
return .terminateCancel
}
// if !context.commitEditing() {
// NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate")
// return .terminateCancel
// }

if !context.hasChanges {
return .terminateNow
Expand Down
4 changes: 2 additions & 2 deletions iina+/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.2</string>
<string>0.3</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>0</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.video</string>
<key>LSMinimumSystemVersion</key>
Expand Down
125 changes: 124 additions & 1 deletion iina+/Utils/Bilibili.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Cocoa
import SwiftHTTP
import Marshal
import PromiseKit

@objc(BilibiliCard)
class BilibiliCard: NSObject, Unmarshaling {
Expand All @@ -20,6 +19,7 @@ class BilibiliCard: NSObject, Unmarshaling {
@objc var name: String = ""
@objc var duration: TimeInterval = 0
@objc var views: Int = 0
@objc var videos: Int = 0
// var pubdate = 1533581945


Expand All @@ -43,6 +43,7 @@ class BilibiliCard: NSObject, Unmarshaling {
duration = try json.value(for: "duration")
name = try json.value(for: "owner.name")
views = try json.value(for: "stat.view")
videos = try json.value(for: "videos")
}
}
}
Expand All @@ -51,6 +52,101 @@ enum BilibiliDynamicAction {
case `init`, new, history
}

struct BilibiliPvideo: Unmarshaling {
var images: [NSImage] = []
var pImages: [NSImage] = []
var xLen: Int = 0
var yLen: Int = 0
var xSize: Int = 0
var ySize: Int = 0
var imagesCount: Int = 0

enum CropImagesError: Error {
case zeroImagesCount
}

init(object: MarshaledObject) throws {
let imageStrs: [String] = try object.value(for: "data.image")
// images = imageStrs.compactMap { str -> NSImage? in
// if let url = URL(string: str.replacingOccurrences(of: "http://", with: "https://")) {
// return NSImage(contentsOf: url)
// } else {
// return nil
// }
// }
let indexs: [Int] = try object.value(for: "data.index")
imagesCount = indexs.count
// limit image count for performance
if imagesCount > 100 {
imagesCount = 100
} else if imagesCount == 0 {
throw CropImagesError.zeroImagesCount
}
if let iamgeStr = imageStrs.first,
let url = URL(string: iamgeStr.replacingOccurrences(of: "http://", with: "https://")),
let image = NSImage(contentsOf: url) {
images = [image]
}

xLen = try object.value(for: "data.img_x_len")
yLen = try object.value(for: "data.img_y_len")
xSize = try object.value(for: "data.img_x_size")
ySize = try object.value(for: "data.img_y_size")
}

mutating func cropImages() {
var pImages: [NSImage] = []
var limitCount = 0
images.forEach { image in
var xIndex = 0
var yIndex = 0

if limitCount < imagesCount {
while yIndex < yLen {
while xIndex < xLen {
let rect = NSRect(x: xIndex * xSize, y: yIndex * ySize, width: xSize, height: ySize)

if let croppedImage = crop(image, with: rect) {
pImages.append(croppedImage)
}
limitCount += 1
if limitCount == imagesCount {
xIndex = 10
yIndex = 10
}
xIndex += 1
if xIndex == xLen {
xIndex = 0
yIndex += 1
}
}
}
}
}
self.pImages = pImages
}

func crop(_ image: NSImage, with rect: NSRect) -> NSImage? {
guard let croppedImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)?.cropping(to: rect) else {
return nil
}
let reImage = NSImage(cgImage: croppedImage, size: rect.size)
return reImage
}
}

struct BilibiliSimpleVideoInfo: Unmarshaling {
var page: Int = 0
var part: String = ""
var duration: TimeInterval = 0

init(object: MarshaledObject) throws {
page = try object.value(for: "page")
part = try object.value(for: "part")
duration = try object.value(for: "duration")
}
}

class Bilibili: NSObject {

func isLogin(_ isLoginBlock: ((Bool) -> Void)?,
Expand Down Expand Up @@ -132,6 +228,33 @@ class Bilibili: NSObject {
}
}

func getPvideo(_ aid: Int,
_ block: @escaping ((BilibiliPvideo) -> Void),
_ error: @escaping ((HTTPErrorCallback) -> Void)) {
guard aid != 0 else { return }
HTTP.GET("https://api.bilibili.com/pvideo?aid=\(aid)") { response in
error {
let json: JSONObject = try JSONParser.JSONObjectWithData(response.data)
var pvideo = try BilibiliPvideo.init(object: json)
pvideo.cropImages()
block(pvideo)
return false
}
}
}

func getVideoList(_ aid: Int,
_ block: @escaping (([BilibiliSimpleVideoInfo]) -> Void),
_ error: @escaping ((HTTPErrorCallback) -> Void)) {
HTTP.GET("https://api.bilibili.com/x/player/pagelist?aid=\(aid)") { response in
error {
let json: JSONObject = try JSONParser.JSONObjectWithData(response.data)
let infos: [BilibiliSimpleVideoInfo] = try json.value(for: "data")
block(infos)
return false
}
}
}
}


Expand Down
Loading

0 comments on commit b2b2ba1

Please sign in to comment.