Skip to content

Commit

Permalink
Merge develop into master.0.3.5 (18091719)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjbeta committed Sep 17, 2018
2 parents d75f676 + 0ac3e9a commit 4f1238d
Show file tree
Hide file tree
Showing 9 changed files with 3,812 additions and 57 deletions.
4 changes: 4 additions & 0 deletions iina+.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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 */; };
013850FA214EA2AA003817CE /* huya.js in Resources */ = {isa = PBXBuildFile; fileRef = 013850F9214EA2AA003817CE /* huya.js */; };
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 Down Expand Up @@ -147,6 +148,7 @@
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>"; };
013850F9214EA2AA003817CE /* huya.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = huya.js; 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 Down Expand Up @@ -337,6 +339,7 @@
isa = PBXGroup;
children = (
019EB39B21453A0F000FD123 /* devmate.pem */,
013850F9214EA2AA003817CE /* huya.js */,
);
name = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -509,6 +512,7 @@
019EB39C21453A0F000FD123 /* devmate.pem in Resources */,
016792E7212BDEE5003517A7 /* SelectVideoCollectionViewItem.xib in Resources */,
01E8CAC9213D236E00C4939B /* main.js in Resources */,
013850FA214EA2AA003817CE /* huya.js in Resources */,
01AEC8B220EDFD02001406E8 /* Main.storyboard in Resources */,
01E8CAC7213D236E00C4939B /* default.css in Resources */,
);
Expand Down
1 change: 0 additions & 1 deletion iina+/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {

HTTP.globalRequest { req in
req.timeoutInterval = 3
req.allHTTPHeaderFields = ["User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15"]
}

DevMateKit.sendTrackingReport(nil, delegate: nil)
Expand Down
2 changes: 1 addition & 1 deletion iina+/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.3.4</string>
<string>0.3.5</string>
<key>CFBundleVersion</key>
<string>0</string>
<key>LSApplicationCategoryType</key>
Expand Down
10 changes: 5 additions & 5 deletions iina+/Views/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.13.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.13.2"/>
<plugIn identifier="com.apple.WebKit2IBPlugin" version="14313.13.2"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
<plugIn identifier="com.apple.WebKit2IBPlugin" version="14313.18"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -459,7 +459,7 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="K8h-eq-wfR" name="value" keyPath="self.enableDanmaku" id="Xfx-r0-Gz5"/>
<action selector="enableDanmaku:" target="LMy-Ki-0Sg" id="F2E-R4-BDF"/>
</connections>
</button>
</gridCell>
Expand All @@ -469,11 +469,11 @@
</view>
<connections>
<outlet property="decoderPopUpButton" destination="0Y9-RS-vhV" id="4TR-OL-CVY"/>
<outlet property="enableDanmaku" destination="dEe-RI-KK4" id="TIy-iV-lgb"/>
<outlet property="playerPopUpButton" destination="bjh-ng-iw0" id="GBM-ep-Aq2"/>
</connections>
</viewController>
<customObject id="pvU-Zd-8Ob" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<customObject id="K8h-eq-wfR" customClass="Preferences" customModule="iina_" customModuleProvider="target"/>
</objects>
<point key="canvasLocation" x="1569" y="903.5"/>
</scene>
Expand Down
132 changes: 132 additions & 0 deletions iina+/Views/Danmaku/DanmakuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Marshal
import SocketRocket
import Gzip
import Socket
import JavaScriptCore

class DanmakuViewController: NSViewController {

Expand All @@ -29,9 +30,15 @@ class DanmakuViewController: NSViewController {

var douyuSocket: Socket? = nil

let huyaServer = URL(string: "ws://ws.api.huya.com")
let huyaFilePath = Bundle.main.path(forResource: "huya", ofType: "js")
var huyaSubSid = ""

override func viewDidLoad() {
super.viewDidLoad()
#if DEBUG
webView.configuration.preferences.setValue(true, forKey: "developerExtrasEnabled")
#endif
webView.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
webView.setValue(false, forKey: "drawsBackground")

Expand Down Expand Up @@ -123,6 +130,17 @@ class DanmakuViewController: NSViewController {
case .douyu:
let roomID = URL(string: url)?.lastPathComponent ?? ""
initDouYuSocket(roomID)
case .huya:
let roomID = URL(string: url)?.lastPathComponent ?? ""
let header = ["User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"]

HTTP.GET("https://m.huya.com/\(roomID)", headers: header) {
let id = $0.text?.subString(from: "var SUBSID = '", to: "';") ?? ""
self.huyaSubSid = id
self.socket = SRWebSocket(url: self.huyaServer!)
self.socket?.delegate = self
self.socket?.open()
}
default:
break
}
Expand Down Expand Up @@ -185,6 +203,8 @@ class DanmakuViewController: NSViewController {
// let keeplive = "type@=keeplive/tick@=\(Int(Date().timeIntervalSince1970))/"
let keeplive = "type@=mrkl/"
try self.douyuSocket?.write(from: self.douyuSocketFormatter(keeplive))
case .huya:
try self.socket?.sendPing(nil)
default:
break
}
Expand Down Expand Up @@ -390,6 +410,21 @@ extension DanmakuViewController: SRWebSocketDelegate {
data.append(pandaInitStr.data(using: .utf8)!)
try? webSocket.send(data: data as Data)
startTimer()
case .huya:
let jsContext = JSContext()
jsContext?.evaluateScript(try? String(contentsOfFile: huyaFilePath!))
jsContext?.evaluateScript("""
var wsUserInfo = new HUYA.WSUserInfo;
wsUserInfo.lSid = "\(huyaSubSid)";
""")

let result = jsContext?.evaluateScript("""
new Uint8Array(sendRegister(wsUserInfo));
""")

let data = Data(bytes: result?.toArray() as? [UInt8] ?? [])
try? webSocket.send(data: data)
startTimer()
default:
break
}
Expand Down Expand Up @@ -527,6 +562,103 @@ extension DanmakuViewController: SRWebSocketDelegate {
// 😞[:可怜]
// 🤣[:233]
// 👏[:666]
case .huya:
let jsContext = JSContext()
jsContext?.evaluateScript(try? String(contentsOfFile: huyaFilePath!))
let bytes = [UInt8](data)

if let re = jsContext?.evaluateScript("test(\(bytes));"),
re.isString {
let str = re.toString() ?? ""
guard str != "HUYA.EWebSocketCommandType.EWSCmd_RegisterRsp" else {
Logger.log("huya websocket inited EWSCmd_RegisterRsp")
return
}
guard str != "HUYA.EWebSocketCommandType.Default" else {
Logger.log("huya websocket WebSocketCommandType.Default \(data)")
return
}
guard !str.contains("分享了直播间,房间号") else { return }
sendDM(str)
}

// "/{dx" = "[大笑]",
// "/{sh" = "[送花]",
// "/{tx" = "[偷笑]",
// "/{dk" = "[大哭]",
// "/{hh" = "[嘿哈]",
// "/{66" = "[666]"},
// "/{gd" = "[感动]",
// "/{yw" = "[疑问]",
// "/{xh" = "[喜欢]",
// "/{jx" = "[奸笑]",
// "/{zan" = "[赞]",
// "/{ka" = "[可爱]",
// "/{am" = "[傲慢]",
// "/{kx" = "[开心]",
// "/{88" = "[拜拜]",
// "/{hx" = "[害羞]",
// "/{zs" = "[衰]",
// "/{pu" = "[吐血]",
// "/{zc" = "[嘴馋]",
// "/{sq" = "[生气]",
// "/{fe" = "[扶额]",
// "/{bz" = "[闭嘴]",
// "/{kw" = "[枯萎]",
// "/{xu" = "[嘘]",
// "/{xk" = "[笑哭]",
// "/{lh" = "[流汗]",
// "/{bk" = "[不看]",
// "/{hq" = "[哈欠]",
// "/{tp" = "[调皮]",
// "/{gl" = "[鬼脸]",
// "/{cl" = "[戳脸]",
// "/{dg" = "[大哥]",
// "/{kun" = "[困]",
// "/{yb" = "[拥抱]",
// "/{zt" = "[猪头]",
// "/{kl" = "[骷髅]",
// "/{cc" = "[臭臭]",
// "/{xd" = "[心动]",
// "/{dao" = "[刀]",
// "/{wx" = "[微笑]",
// "/{ll" = "[流泪]",
// "/{dy" = "[得意]",
// "/{jy" = "[惊讶]",
// "/{pz" = "[撇嘴]",
// "/{yun" = "[晕]",
// "/{ng" = "[难过]",
// "/{se" = "[色]",
// "/{cy" = "[抽烟]",
// "/{qd" = "[敲打]"},
// "/{mg" = "[玫瑰]",
// "/{wen" = "[吻]",
// "/{xs" = "[心碎]",
// "/{zd" = "[*屏蔽的关键字*]",
// "/{sj" = "[睡觉]",
// "/{hk" = "[很酷]",
// "/{by" = "[白眼]",
// "/{ot" = "[呕吐]",
// "/{fd" = "[奋斗]",
// "/{kz" = "[口罩]",
// "/{hp" = "[害怕]",
// "/{dai" = "[发呆]",
// "/{fn" = "[发怒]",
// "/{ruo" = "[弱]",
// "/{ws" = "[握手]",
// "/{sl" = "[胜利]",
// "/{lw" = "[礼物]",
// "/{sd" = "[闪电]",
// "/{gz" = "[鼓掌]",
// "/{qq" = "[亲亲]",
// "/{kb" = "[抠鼻]",
// "/{wq" = "[委屈]",
// "/{yx" = "[阴险]",
// "/{kel" = "[可怜]",
// "/{bs" = "[鄙视]",
// "/{zk" = "[抓狂]",
// "/{bq" = "[抱拳]",
// "/{ok" = "[OK]"

default:
break
Expand Down
98 changes: 49 additions & 49 deletions iina+/Views/Danmaku/DanmakuWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DanmakuWindowController: NSWindowController, NSWindowDelegate {
override func windowDidLoad() {
super.windowDidLoad()

window?.level = NSWindow.Level(NSWindow.Level.floating.rawValue)
window?.level = .floating
window?.backgroundColor = NSColor.clear
window?.isOpaque = false
window?.ignoresMouseEvents = true
Expand Down Expand Up @@ -53,7 +53,7 @@ class DanmakuWindowController: NSWindowController, NSWindowDelegate {

func initDanmaku(_ site: LiveSupportList, _ title: String, _ url: String) {
waittingSocket = true
targeTitle = title
targeTitle = site == .huya ? "yes" : title
if let danmakuViewController = self.contentViewController as? DanmakuViewController {
danmakuViewController.initDanmaku(site, url)
}
Expand All @@ -66,67 +66,67 @@ class DanmakuWindowController: NSWindowController, NSWindowDelegate {
}

@objc func foremostAppActivated(_ notification: NSNotification) {
guard let app = notification.userInfo?["NSWorkspaceApplicationKey"] as? NSRunningApplication,
guard Preferences.shared.enableDanmaku else { return }
guard let app = NSWorkspace.shared.frontmostApplication,
app.bundleIdentifier == "com.colliderli.iina" else {
if let window = window, window.isVisible {
window.orderOut(self)
Logger.log("hide danmaku window")
}
return
}

Logger.log("AXIsProcessTrusted \(AXIsProcessTrusted())")
assert(AXIsProcessTrusted(), "No accessibility API permission.")

resizeWindow()

if waittingSocket {
initMpvSocket()
waittingSocket = false
setObserver(app.processIdentifier)
}
}

func resizeWindow() {
let tt = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .optionOnScreenAboveWindow], kCGNullWindowID) as? [[String: AnyObject]]
if let d = tt?.filter ({
if let owner = $0["kCGWindowOwnerName"] as? String,
owner == "IINA",
let title = $0["kCGWindowName"] as? String,
title == targeTitle {
guard let pid = NSWorkspace.shared.frontmostApplication?.processIdentifier else { return }

let app = AXUIElementCreateApplication(pid)
var children: CFTypeRef?
AXUIElementCopyAttributeValue(app, kAXChildrenAttribute as CFString, &children)

guard let windows = children as? [AXUIElement] else { return }

let targeWindows = windows.filter { element in
var title: CFTypeRef?
AXUIElementCopyAttributeValue(element, kAXTitleAttribute as CFString, &title)
if let t = title as? String, t == targeTitle {
return true
} else {
return false
}
}).first {
var re = WindowData(d).frame
re.origin.y = (NSScreen.main?.frame.size.height)! - re.size.height - re.origin.y
guard let window = window else { return }
window.setFrame(re, display: true)
if !window.isVisible {
window.orderFront(self)
Logger.log("show danmaku window")
}
if waittingSocket {
initMpvSocket()
waittingSocket = false
setObserver(pid_t(WindowData(d).pid))
}
return false
}
}
}



guard let targeWindow = targeWindows.first else { return }

var position: CFTypeRef?
var size: CFTypeRef?
var p = CGPoint()
var s = CGSize()
AXUIElementCopyAttributeValue(targeWindow, kAXPositionAttribute as CFString, &position)
AXUIElementCopyAttributeValue(targeWindow, kAXSizeAttribute as CFString, &size)

struct WindowData {
public let name: String
public let pid: Int
public let wid: Int
public let layer: Int
public let opacity: CGFloat
public let frame: CGRect

init(_ d: [String: AnyObject]) {
let _r = d[kCGWindowBounds as String] as? [String: Int]
frame = NSRect(x: _r?["X"] ?? 0,
y: _r?["Y"] ?? 0,
width: _r?["Width"] ?? 0,
height: _r?["Height"] ?? 0)
name = d[kCGWindowName as String] as? String ?? ""
pid = d[kCGWindowOwnerPID as String] as? Int ?? -1
wid = d[kCGWindowNumber as String] as? Int ?? -1
layer = d[kCGWindowLayer as String] as? Int ?? 0
opacity = d[kCGWindowAlpha as String] as? CGFloat ?? 0.0
guard position != nil, size != nil else { return }
AXValueGetValue(position as! AXValue, AXValueType.cgPoint, &p)
AXValueGetValue(size as! AXValue, AXValueType.cgSize, &s)

var rect = NSRect(origin: p, size: s)

rect.origin.y = (NSScreen.main?.frame.size.height)! - rect.size.height - rect.origin.y
guard let window = window else { return }
window.setFrame(rect, display: true)
if !window.isVisible {
window.orderFront(self)
Logger.log("show danmaku window")
}
}
}

Loading

0 comments on commit 4f1238d

Please sign in to comment.