Skip to content

Commit

Permalink
fix(修复虎牙一起看)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchuancong committed Dec 3, 2024
1 parent 174d6b3 commit 320ec8c
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 47 deletions.
2 changes: 1 addition & 1 deletion assets/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.7.7",
"version": "1.7.8",
"version_num": 10507,
"version_desc": "-Fix: 修复虎牙一起看直播问题",
"prerelease":false,
Expand Down
2 changes: 1 addition & 1 deletion inno.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "纯粹直播"
#define MyAppVersion "1.0.0.69"
#define MyAppVersion "1.0.0.70"
#define MyAppPublisher "My Company, Inc."
#define MyAppExeName "pure_live.exe"
#define MyAppAssocName MyAppName + " File"
Expand Down
2 changes: 1 addition & 1 deletion lib/common/utils/version_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:convert';
import 'package:http/http.dart' as http;

class VersionUtil {
static const String version = '1.7.7';
static const String version = '1.7.8';
static const String projectUrl = 'https://github.com/liuchuancong/pure_live';
static const String releaseUrl = 'https://api.github.com/repos/liuchuancong/pure_live/releases';
static const String issuesUrl = 'https://github.com/liuchuancong/pure_live/issues';
Expand Down
54 changes: 32 additions & 22 deletions lib/core/site/huya_site.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest.dart' as tz;
import 'package:pure_live/model/live_category.dart';
import 'package:pure_live/model/live_anchor_item.dart';
import 'package:tars_dart/tars/net/base_tars_http.dart';
import 'package:pure_live/core/common/http_client.dart';
import 'package:pure_live/model/live_play_quality.dart';
import 'package:pure_live/core/interface/live_site.dart';
import 'package:pure_live/model/live_search_result.dart';
import 'package:pure_live/core/danmaku/huya_danmaku.dart';
import 'package:pure_live/model/live_category_result.dart';
import 'package:pure_live/core/interface/live_danmaku.dart';
import 'package:pure_live/model/tars/get_cdn_token_req.dart';
import 'package:pure_live/model/tars/get_cdn_token_resp.dart';

class HuyaSite implements LiveSite {
@override
String id = "huya";

@override
String name = "虎牙直播";

final BaseTarsHttp tupClient = BaseTarsHttp("http://wup.huya.com", "liveui");
@override
LiveDanmaku getDanmaku() => HuyaDanmaku();

Expand Down Expand Up @@ -129,26 +132,11 @@ class HuyaSite implements LiveSite {
];
}
for (var item in urlData.bitRates) {
var urls = <String>[];
for (var line in urlData.lines) {
var src = line.line;
src += "/${line.streamName}.flv";
src = src.replaceAll("http://", "https://");
var parms = urlData.isXingxiu
? line.flvAntiCode
: processAnticode(
line.flvAntiCode,
line.streamName,
);
src += "?$parms";
if (item.bitRate > 0) {
src += "&ratio=${item.bitRate}";
}

urls.add(src);
}
qualities.add(LivePlayQuality(
data: urls,
data: {
"urls": urlData.lines,
"bitRate": item.bitRate,
},
quality: item.name,
));
}
Expand All @@ -158,7 +146,25 @@ class HuyaSite implements LiveSite {

@override
Future<List<String>> getPlayUrls({required LiveRoom detail, required LivePlayQuality quality}) async {
return quality.data as List<String>;
var ls = <String>[];
for (var element in quality.data["urls"]) {
var line = element as HuyaLineModel;
var url = await getPlayUrl(line, quality.data["bitRate"]);
ls.add(url);
}
return ls;
}

Future<String> getPlayUrl(HuyaLineModel line, int bitRate) async {
var req = GetCdnTokenReq();
req.cdnType = line.cdnType;
req.streamName = line.streamName;
var resp = await tupClient.tupRequest("getCdnTokenInfo", req, GetCdnTokenResp());
var url = '${line.line}/${resp.streamName}.flv?${resp.flvAntiCode}&codec=264';
if (bitRate > 0) {
url += "&ratio=$bitRate";
}
return url;
}

@override
Expand Down Expand Up @@ -243,6 +249,7 @@ class HuyaSite implements LiveSite {
flvAntiCode: currentStream["sFlvAntiCode"].toString(),
hlsAntiCode: currentStream["sHlsAntiCode"].toString(),
streamName: currentStream["sStreamName"].toString(),
cdnType: item["sCdnType"].toString(),
));
}
}
Expand Down Expand Up @@ -511,17 +518,20 @@ enum HuyaLineType {

class HuyaLineModel {
final String line;
final String cdnType;
final String flvAntiCode;
final String hlsAntiCode;
final String streamName;
final HuyaLineType lineType;

int bitRate;
HuyaLineModel({
required this.line,
required this.lineType,
required this.flvAntiCode,
required this.hlsAntiCode,
required this.streamName,
required this.cdnType,
this.bitRate = 0,
});
@override
String toString() {
Expand Down
49 changes: 49 additions & 0 deletions lib/model/tars/get_cdn_token_req.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:tars_dart/tars/codec/tars_struct.dart';
import 'package:tars_dart/tars/codec/tars_displayer.dart';
import 'package:tars_dart/tars/codec/tars_input_stream.dart';
import 'package:tars_dart/tars/codec/tars_output_stream.dart';
// ignore_for_file: no_leading_underscores_for_local_identifiers

class GetCdnTokenReq extends TarsStruct {
String url = "";

String cdnType = "";

String streamName = "";

int presenterUid = 0;

@override
void readFrom(TarsInputStream _is) {
url = _is.read(url, 0, false);
cdnType = _is.read(cdnType, 1, false);
streamName = _is.read(streamName, 2, false);
presenterUid = _is.read(presenterUid, 3, false);
}

@override
void writeTo(TarsOutputStream _os) {
_os.write(url, 0);
_os.write(cdnType, 1);
_os.write(streamName, 2);
_os.write(presenterUid, 3);
}

@override
Object deepCopy() {
return GetCdnTokenReq()
..url = url
..cdnType = cdnType
..streamName = streamName
..presenterUid = presenterUid;
}

@override
void displayAsString(StringBuffer sb, int level) {
TarsDisplayer _ds = TarsDisplayer(sb, level: level);
_ds.DisplayString(url, "url");
_ds.DisplayString(cdnType, "cdnType");
_ds.DisplayString(streamName, "streamName");
_ds.DisplayInt(presenterUid, "presenterUid");
}
}
73 changes: 73 additions & 0 deletions lib/model/tars/get_cdn_token_resp.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:tars_dart/tars/codec/tars_struct.dart';
import 'package:tars_dart/tars/codec/tars_displayer.dart';
import 'package:tars_dart/tars/codec/tars_input_stream.dart';
import 'package:tars_dart/tars/codec/tars_output_stream.dart';
// ignore_for_file: no_leading_underscores_for_local_identifiers

class GetCdnTokenResp extends TarsStruct {
String url = "";

String cdnType = "";

String streamName = "";

int presenterUid = 0;

String antiCode = "";

String sTime = "";

String flvAntiCode = "";

String hlsAntiCode = "";

@override
void readFrom(TarsInputStream _is) {
url = _is.read(url, 0, false);
cdnType = _is.read(cdnType, 1, false);
streamName = _is.read(streamName, 2, false);
presenterUid = _is.read(presenterUid, 3, false);
antiCode = _is.read(antiCode, 4, false);
sTime = _is.read(sTime, 5, false);
flvAntiCode = _is.read(flvAntiCode, 6, false);
hlsAntiCode = _is.read(hlsAntiCode, 7, false);
}

@override
void writeTo(TarsOutputStream _os) {
_os.write(url, 0);
_os.write(cdnType, 1);
_os.write(streamName, 2);
_os.write(presenterUid, 3);
_os.write(antiCode, 4);
_os.write(sTime, 5);
_os.write(flvAntiCode, 6);
_os.write(hlsAntiCode, 7);
}

@override
Object deepCopy() {
return GetCdnTokenResp()
..url = url
..cdnType = cdnType
..streamName = streamName
..presenterUid = presenterUid
..antiCode = antiCode
..sTime = sTime
..flvAntiCode = flvAntiCode
..hlsAntiCode = hlsAntiCode;
}

@override
void displayAsString(StringBuffer sb, int level) {
TarsDisplayer _ds = TarsDisplayer(sb, level: level);
_ds.DisplayString(url, "url");
_ds.DisplayString(cdnType, "cdnType");
_ds.DisplayString(streamName, "streamName");
_ds.DisplayInt(presenterUid, "presenterUid");
_ds.DisplayString(antiCode, "antiCode");
_ds.DisplayString(sTime, "sTime");
_ds.DisplayString(flvAntiCode, "flvAntiCode");
_ds.DisplayString(hlsAntiCode, "hlsAntiCode");
}
}
121 changes: 121 additions & 0 deletions lib/model/tars/huya_danmaku.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import 'package:tars_dart/tars/codec/tars_struct.dart';
import 'package:tars_dart/tars/codec/tars_input_stream.dart';
import 'package:tars_dart/tars/codec/tars_output_stream.dart';
// ignore_for_file: no_leading_underscores_for_local_identifiers

class HYPushMessage extends TarsStruct {
int pushType = 0;
int uri = 0;
List<int> msg = <int>[];
int protocolType = 0;

@override
void readFrom(TarsInputStream _is) {
pushType = _is.read(pushType, 0, false);
uri = _is.read(uri, 1, false);
msg = _is.readBytes(2, false);
protocolType = _is.read(protocolType, 3, false);
}

@override
void writeTo(TarsOutputStream _os) {}

@override
Object deepCopy() {
return HYPushMessage()
..pushType = pushType
..uri = uri
..msg = List<int>.from(msg)
..protocolType = protocolType;
}

@override
void displayAsString(StringBuffer sb, int level) {}
}

class HYSender extends TarsStruct {
int uid = 0;
int lMid = 0;
String nickName = "";
int gender = 0;

@override
void readFrom(TarsInputStream _is) {
uid = _is.read(uid, 0, false);
lMid = _is.read(lMid, 0, false);
nickName = _is.read(nickName, 2, false);
gender = _is.read(gender, 3, false);
}

@override
void writeTo(TarsOutputStream _os) {}

@override
Object deepCopy() {
return HYSender()
..uid = uid
..lMid = lMid
..nickName = nickName
..gender = gender;
}

@override
void displayAsString(StringBuffer sb, int level) {}
}

class HYMessage extends TarsStruct {
HYSender userInfo = HYSender();
String content = "";
HYBulletFormat bulletFormat = HYBulletFormat();

@override
void readFrom(TarsInputStream _is) {
userInfo = _is.readTarsStruct(userInfo, 0, false) as HYSender;
content = _is.read(content, 3, false);
bulletFormat = _is.readTarsStruct(bulletFormat, 6, false) as HYBulletFormat;
}

@override
void writeTo(TarsOutputStream _os) {}

@override
Object deepCopy() {
return HYMessage()
..userInfo = userInfo.deepCopy() as HYSender
..content = content
..bulletFormat = bulletFormat.deepCopy() as HYBulletFormat;
}

@override
void displayAsString(StringBuffer sb, int level) {}
}

class HYBulletFormat extends TarsStruct {
int fontColor = 0;
int fontSize = 4;
int textSpeed = 0;
int transitionType = 1;

@override
void readFrom(TarsInputStream _is) {
fontColor = _is.read(fontColor, 0, false);
fontSize = _is.read(fontSize, 1, false);
textSpeed = _is.read(textSpeed, 2, false);
transitionType = _is.read(transitionType, 3, false);
}

@override
void writeTo(TarsOutputStream _os) {}

@override
Object deepCopy() {
return HYBulletFormat()
..fontColor = fontColor
..fontSize = fontSize
..textSpeed = textSpeed
..transitionType = transitionType;
}

@override
void displayAsString(StringBuffer sb, int level) {}
}
Loading

0 comments on commit 320ec8c

Please sign in to comment.