Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xjbeta committed Jun 5, 2024
2 parents 3135258 + 000354e commit b08a154
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 82 deletions.
4 changes: 2 additions & 2 deletions IINA+.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.7.28;
MARKETING_VERSION = 0.7.29;
PRODUCT_BUNDLE_IDENTIFIER = "com.xjbeta.iina-plus";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1068,7 +1068,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.7.28;
MARKETING_VERSION = 0.7.29;
PRODUCT_BUNDLE_IDENTIFIER = "com.xjbeta.iina-plus";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/SDWebImage/SDWebImage",
"state" : {
"revision" : "5642d1ffe3dbe628592443bd14154e31929727b4",
"version" : "5.19.2"
"revision" : "b8523c1642f3c142b06dd98443ea7c48343a4dfd",
"version" : "5.19.3"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions IINA+/Utils/Danmaku/DanmakuBiliLive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension Danmaku {
init(object: MarshaledObject) throws {
emoji = try object.value(for: "emoji")
let u: String = try object.value(for: "url")
url = u.replacingOccurrences(of: "http://", with: "https://")
url = u.https()
width = try object.value(for: "width")
height = try object.value(for: "height")
// identity = try object.value(for: "identity")
Expand Down Expand Up @@ -360,7 +360,7 @@ extension Danmaku {
return emoticon.comment()
}

let url = url.replacingOccurrences(of: "http://", with: "https://")
let url = url.https()
var emoticon = BiliLiveEmoticon(unique, url: url)

emoticon.width = width
Expand Down
4 changes: 4 additions & 0 deletions IINA+/Utils/Extensions/StringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ extension String {
}
return s
}

func https() -> String {
self.replacingOccurrences(of: "http://", with: "https://")
}
}


Expand Down
6 changes: 3 additions & 3 deletions IINA+/Utils/VideoDecoder/Bilibili.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Bilibili: NSObject, SupportSiteProtocol {
var info = BilibiliInfo()
info.title = try initialStateJson.value(for: "videoData.title")
info.cover = try initialStateJson.value(for: "videoData.pic")
info.cover = info.cover.replacingOccurrences(of: "http://", with: "https://")
info.cover = info.cover.https()
info.name = try initialStateJson.value(for: "videoData.owner.name")
info.isLiving = true
return info
Expand Down Expand Up @@ -474,7 +474,7 @@ class BilibiliCard: NSObject, Unmarshaling {
aid = try json.value(for: "aid")
title = try json.value(for: "title")
let picUrl: String = try json.value(for: "pic")
self.picUrl = picUrl.replacingOccurrences(of: "http://", with: "https://")
self.picUrl = picUrl.https()
duration = try json.value(for: "duration")
name = try json.value(for: "owner.name")
views = try json.value(for: "stat.view")
Expand Down Expand Up @@ -503,7 +503,7 @@ struct BilibiliPvideo: Unmarshaling {
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://")) {
// if let url = URL(string: str.https()) {
// return NSImage(contentsOf: url)
// } else {
// return nil
Expand Down
6 changes: 3 additions & 3 deletions IINA+/Utils/VideoDecoder/CC163.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct CC163Info: Unmarshaling, LiveInfo {
title = try object.value(for: "props.pageProps.roomInfoInitData.live.title")
name = try object.value(for: "props.pageProps.roomInfoInitData.micfirst.nickname")
avatar = try object.value(for: "props.pageProps.roomInfoInitData.micfirst.purl")
avatar = avatar.replacingOccurrences(of: "http://", with: "https://")
avatar = avatar.https()
cover = avatar
let living: Bool? = try? object.value(for: "props.pageProps.roomInfoInitData.is_show_live_rcm")

Expand Down Expand Up @@ -248,9 +248,9 @@ struct CC163ChannelInfo: Unmarshaling, LiveInfo {
if isLiving {
title = try object.value(for: "title")
cover = try object.value(for: "cover")
cover = cover.replacingOccurrences(of: "http://", with: "https://")
cover = cover.https()
avatar = (try? object.value(for: "purl")) ?? ""
avatar = avatar.replacingOccurrences(of: "http://", with: "https://")
avatar = avatar.https()
} else {
title = (try? object.value(for: "title")) ?? name
cover = ""
Expand Down
4 changes: 2 additions & 2 deletions IINA+/Utils/VideoDecoder/DouYin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ struct DouYinInfo: Unmarshaling, LiveInfo {


urls.map {
($0.key, $0.value.replacingOccurrences(of: "http://", with: "https://"))
($0.key, $0.value.https())
}.sorted { v0, v1 in
v0.0 < v1.0
}.enumerated().forEach {
Expand Down Expand Up @@ -526,7 +526,7 @@ struct DouYinEnterData: Unmarshaling {


urls.map {
($0.key, $0.value.replacingOccurrences(of: "http://", with: "https://"))
($0.key, $0.value.https())
}.sorted { v0, v1 in
v0.0 < v1.0
}.enumerated().forEach {
Expand Down
117 changes: 103 additions & 14 deletions IINA+/Utils/VideoDecoder/Huya.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@ class Huya: NSObject, SupportSiteProtocol {
return Session(configuration: configuration)
}()

private let huyaUid = Int.random(in: Int(1e12)..<Int(1e13))
// T.a.uid
private let huyaUid = (Int(Date().timeIntervalSince1970 * 1000) % Int(1e10) * Int(1e3) + Int.random(in: Int(1e2)..<Int(1e3))) % 4294967295

func liveInfo(_ url: String) -> Promise<LiveInfo> {
getHuyaInfo(url).map {
getHuyaInfoMP(url).map {
$0
}
}

func decodeUrl(_ url: String) -> Promise<YouGetJSON> {
getHuyaVideos(url)
/*
getHuyaInfoM(url).map {
var yougetJson = YouGetJSON(rawUrl: url)
yougetJson.title = $0.title
return $0.write(to: yougetJson, uid: self.huyaUid)
}
*/
getHuyaInfoMP(url).map {
$0.videos(url, uid: self.huyaUid)
}
}

// MARK: - Huya
Expand Down Expand Up @@ -137,6 +133,19 @@ class Huya: NSObject, SupportSiteProtocol {
return info
}
}

func getHuyaInfoMP(_ url: String) -> Promise<HuyaInfoMP> {
let ucs = url.pathComponents
guard ucs.count >= 3 else {
return .init(error: VideoGetError.invalidLink)
}
let rid = ucs[2]

return pSession.request("https://mp.huya.com/cache.php?m=Live&do=profileRoom&roomid=\(rid)").responseData().map {
let jsonObj: JSONObject = try JSONParser.JSONObjectWithData($0.data)
return try HuyaInfoMP(object: jsonObj)
}
}
}

/*
Expand All @@ -155,10 +164,10 @@ struct HuyaInfo: Unmarshaling, LiveInfo {
title = try object.value(for: "introduction")
name = try object.value(for: "nick")
avatar = try object.value(for: "avatar")
avatar = avatar.replacingOccurrences(of: "http://", with: "https://")
avatar = avatar.https()
isLiving = "\(try object.any(for: "isOn"))" == "1"
cover = try object.value(for: "screenshot")
cover = cover.replacingOccurrences(of: "http://", with: "https://")
cover = cover.https()
rid = try object.value(for: "profileRoom")
Expand Down Expand Up @@ -272,8 +281,10 @@ struct HuyaStream: Unmarshaling {
name = try object.value(for: "nick")

avatar = try object.value(for: "avatar180")
avatar = avatar.https()
rid = try object.value(for: "profileRoom")
cover = try object.value(for: "screenshot")
cover = cover.https()

if let uid: Int = try? object.value(for: "uid") {
self.uid = uid
Expand Down Expand Up @@ -359,8 +370,8 @@ struct HuyaInfoM: Unmarshaling, LiveInfo {
init(object: MarshaledObject) throws {
name = try object.value(for: "roomInfo.tProfileInfo.sNick")

let ava: String = try object.value(for: "roomInfo.tProfileInfo.sAvatar180")
avatar = ava.replacingOccurrences(of: "http://", with: "https://")
avatar = try object.value(for: "roomInfo.tProfileInfo.sAvatar180")
avatar = avatar.https()

let state: Int = try object.value(for: "roomInfo.eLiveStatus")
isLiving = state == 2
Expand Down Expand Up @@ -430,6 +441,84 @@ struct HuyaInfoM: Unmarshaling, LiveInfo {
}
}

struct HuyaInfoMP: Unmarshaling, LiveInfo {

var title: String
var name: String
var avatar: String
var cover: String
var isLiving: Bool
var site: SupportSites = .huya

var streamInfos: [HuyaInfoM.StreamInfo]
var bitRateInfos: [HuyaInfoM.BitRateInfo]

init(object: any Marshal.MarshaledObject) throws {
let name1: String = try object.value(for: "data.liveData.roomName")
let name2: String = try object.value(for: "data.liveData.introduction")

title = name1 == "" ? name2 : name1

name = try object.value(for: "data.liveData.nick")
avatar = try object.value(for: "data.liveData.avatar180")
avatar = avatar.https()
cover = try object.value(for: "data.liveData.screenshot")
cover = cover.https()

let liveStatus: String = try object.value(for: "data.liveStatus")
isLiving = liveStatus == "ON"

streamInfos = try object.value(for: "data.stream.baseSteamInfoList")

let bitRateInfoString: String = try object.value(for: "data.liveData.bitRateInfo")
guard let data = bitRateInfoString.data(using: .utf8) else {
throw VideoGetError.notFountData
}
let jsonObj: [JSONObject] = try JSONParser.JSONArrayWithData(data)
bitRateInfos = try jsonObj.map(HuyaInfoM.BitRateInfo.init)
}


func videos(_ url: String, uid: Int) -> YouGetJSON {
var yougetJson = YouGetJSON(rawUrl: url)
yougetJson.title = title

let urls = streamInfos
// .sorted { i1, i2 -> Bool in
// i1.sCdnType == defaultCDN
// }
.sorted { i1, i2 -> Bool in
!i1.sFlvUrl.contains("txdirect.flv.huya.com")
}.compactMap {
HuyaUrl.format(
uid,
sStreamName: $0.sStreamName,
sFlvUrl: $0.sFlvUrl,
sFlvUrlSuffix: $0.sFlvUrlSuffix,
sFlvAntiCode: $0.sFlvAntiCode)
}

guard urls.count > 0 else {
return yougetJson
}

bitRateInfos.map {
($0.sDisplayName, $0.iBitRate)
}.forEach { (name, rate) in
var us = urls.map {
$0.replacingOccurrences(of: "&ratio=0", with: "&ratio=\(rate)")
}
var s = Stream(url: us.removeFirst())
s.src = us
s.quality = rate == 0 ? 9999999 : rate

yougetJson.streams[name] = s
}

return yougetJson
}
}


struct HuyaVideoSelector: VideoSelector {
var id: String
Expand Down
Loading

0 comments on commit b08a154

Please sign in to comment.