Skip to content

Commit ff1d2b8

Browse files
committed
Merge develop into master. v0.1-build3.
2 parents 1190d86 + 7a1c6fe commit ff1d2b8

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

iina+/AppDelegate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
//
88

99
import Cocoa
10+
import SwiftHTTP
1011

1112
@NSApplicationMain
1213
class AppDelegate: NSObject, NSApplicationDelegate {
1314

1415
func applicationDidFinishLaunching(_ aNotification: Notification) {
16+
HTTP.globalRequest { req in
17+
req.timeoutInterval = 1.5
18+
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"]
19+
}
1520

1621
}
1722

iina+/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>0.1</string>
2121
<key>CFBundleVersion</key>
22-
<string>2</string>
22+
<string>3</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.video</string>
2525
<key>LSMinimumSystemVersion</key>

iina+/Processes.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import Marshal
11+
import SwiftHTTP
1112

1213
class Processes: NSObject {
1314

@@ -82,6 +83,11 @@ class Processes: NSObject {
8283
task.standardOutput = pipe
8384
var mpvArgs = ["\(MPVOption.Miscellaneous.forceMediaTitle)=\(title)"]
8485

86+
if url.contains("douyu") {
87+
mpvArgs.append(contentsOf: [MPVOption.Network.cookies,
88+
"\(MPVOption.Network.cookiesFile)=\(getCookies(for: .douyu))"])
89+
}
90+
8591
switch Preferences.shared.livePlayer {
8692
case .iina:
8793
task.launchPath = Preferences.shared.livePlayer.rawValue
@@ -103,3 +109,42 @@ class Processes: NSObject {
103109

104110

105111
}
112+
113+
private extension Processes {
114+
115+
func getCookies(for website: LiveSupportList) -> String {
116+
switch website {
117+
case .douyu:
118+
let douyuCookie = "https://passport.douyu.com/lapi/did/api/get"
119+
let time = UInt32(NSDate().timeIntervalSinceReferenceDate)
120+
srand48(Int(time))
121+
let random = "\(drand48())"
122+
let parameters = ["client_id": "1",
123+
"callback": ("jsonp_" + random).replacingOccurrences(of: ".", with: "")]
124+
let headers = ["Referer": "http://www.douyu.com"]
125+
126+
let httpSemaphore = DispatchSemaphore(value: 0)
127+
var cookiesString = ""
128+
129+
HTTP.GET(douyuCookie, parameters: parameters, headers: headers) { response in
130+
do {
131+
var str = response.text
132+
str = str?.subString(from: "(", to: ")")
133+
let json = try JSONParser.JSONObjectWithData(str?.data(using: .utf8) ?? Data())
134+
let didStr: String = try json.value(for: "data.did")
135+
cookiesString = """
136+
..douyu.com TRUE / FALSE 1535865698 dy_did \(didStr)
137+
.www.douyu.com TRUE / FALSE 1535865771 acf_did \(didStr)
138+
"""
139+
} catch let error {
140+
print(error)
141+
}
142+
httpSemaphore.signal()
143+
}
144+
httpSemaphore.wait()
145+
return cookiesString
146+
default:
147+
return ""
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)