-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
2,886 additions
and
126 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,96 @@ | ||
import 'package:simple_live_core/simple_live_core.dart'; | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:simple_live_core/src/model/tars/get_cdn_token_req.dart'; | ||
import 'package:simple_live_core/src/model/tars/get_cdn_token_resp.dart'; | ||
import 'package:tars_dart/tars/net/base_tars_http.dart'; | ||
import 'package:tars_dart/tars/tup/uni_packet.dart'; | ||
|
||
void main() async { | ||
CoreLog.enableLog = true; | ||
CoreLog.requestLogType = RequestLogType.short; | ||
LiveSite site = BiliBiliSite(); | ||
var danmaku = site.getDanmaku(); | ||
danmaku.onMessage = (event) { | ||
if (event.type == LiveMessageType.chat) { | ||
print("[${event.color}]${event.userName}:${event.message}"); | ||
} else if (event.type == LiveMessageType.online) { | ||
print("-----人气:${event.data}-----"); | ||
} else if (event.type == LiveMessageType.superChat) { | ||
var scMessage = event.data as LiveSuperChatMessage; | ||
print("[SC]${scMessage.userName}:${scMessage.message}"); | ||
} | ||
}; | ||
danmaku.onClose = (event) { | ||
print(event); | ||
}; | ||
|
||
//var search = await site.searchRooms("东方"); | ||
|
||
//var categores = await site.getCategores(); | ||
//print(categores.length); | ||
var detail = await site.getRoomDetail(roomId: '7734200'); | ||
// var playQualites = await site.getPlayQualites(detail: detail); | ||
// print(playQualites); | ||
// var playUrls = | ||
// await site.getPlayUrls(detail: detail, quality: playQualites.first); | ||
// for (var element in playUrls) { | ||
// print(element); | ||
// } | ||
//print(detail); | ||
|
||
danmaku.start(detail.danmakuData); | ||
|
||
await Future.wait({}); | ||
// CoreLog.enableLog = true; | ||
// CoreLog.requestLogType = RequestLogType.short; | ||
// LiveSite site = BiliBiliSite(); | ||
// var danmaku = site.getDanmaku(); | ||
// danmaku.onMessage = (event) { | ||
// if (event.type == LiveMessageType.chat) { | ||
// print("[${event.color}]${event.userName}:${event.message}"); | ||
// } else if (event.type == LiveMessageType.online) { | ||
// print("-----人气:${event.data}-----"); | ||
// } else if (event.type == LiveMessageType.superChat) { | ||
// var scMessage = event.data as LiveSuperChatMessage; | ||
// print("[SC]${scMessage.userName}:${scMessage.message}"); | ||
// } | ||
// }; | ||
// danmaku.onClose = (event) { | ||
// print(event); | ||
// }; | ||
|
||
// //var search = await site.searchRooms("东方"); | ||
|
||
// //var categores = await site.getCategores(); | ||
// //print(categores.length); | ||
// var detail = await site.getRoomDetail(roomId: '7734200'); | ||
// // var playQualites = await site.getPlayQualites(detail: detail); | ||
// // print(playQualites); | ||
// // var playUrls = | ||
// // await site.getPlayUrls(detail: detail, quality: playQualites.first); | ||
// // for (var element in playUrls) { | ||
// // print(element); | ||
// // } | ||
// //print(detail); | ||
|
||
// danmaku.start(detail.danmakuData); | ||
|
||
// await Future.wait({}); | ||
sendReq(); | ||
} | ||
|
||
void testHuyaReq() async { | ||
var reqBytes = await File('demo/getCdnTokenInfoReq.bin').readAsBytes(); | ||
// RequestPacket req = RequestPacket(); | ||
// req.readFrom(TarsInputStream(reqBytes)); | ||
// print(req.iVersion); | ||
|
||
UniPacket uniPacket = UniPacket(); | ||
//uniPacket.readFrom(TarsInputStream(reqBytes)); | ||
uniPacket.decode(reqBytes); | ||
var value = uniPacket.get<GetCdnTokenReq>('tReq', GetCdnTokenReq()); | ||
// GetCdnTokenReq reqData = GetCdnTokenReq(); | ||
// reqData.readFrom(TarsInputStream(req.sBuffer)); | ||
print(value.toString()); | ||
} | ||
|
||
void sendReq() async { | ||
var req = GetCdnTokenReq(); | ||
req.cdnType = "HW"; | ||
req.streamName = | ||
"1199637826638-1199637826638-5763635889762729984-2399275776732-10057-A-0-1"; | ||
|
||
BaseTarsHttp http = BaseTarsHttp("http://wup.huya.com", "liveui"); | ||
|
||
var data = await http.tupRequest("getCdnTokenInfo", req, GetCdnTokenResp()); | ||
|
||
var url = | ||
'http://hw.flv.huya.com/src/${data.streamName}.flv?${data.flvAntiCode}&codec=264'; | ||
print(url); | ||
await Dio().download( | ||
url, | ||
'live-stream.flv', | ||
options: Options( | ||
responseType: ResponseType.bytes, | ||
headers: {"user-agent": "HYSDK(Windows, 20000308)"}, | ||
), | ||
onReceiveProgress: (count, total) { | ||
var downBytes = count / 1024 / 1024; | ||
print('downloading: $downBytes MB'); | ||
}, | ||
); | ||
} | ||
|
||
void testHuyaResp() async { | ||
var respBytes = await File('demo/getCdnTokenInfoResp.bin').readAsBytes(); | ||
UniPacket uniPacket = UniPacket(); | ||
uniPacket.decode(respBytes); | ||
var value = uniPacket.get<GetCdnTokenResp>('tRsp', GetCdnTokenResp()); | ||
print(value.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ class CoreLog { | |
lineLength: 120, | ||
colors: true, | ||
printEmojis: true, | ||
printTime: false, | ||
), | ||
); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
simple_live_core/lib/src/model/tars/get_cdn_token_req.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ignore_for_file: no_leading_underscores_for_local_identifiers | ||
|
||
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'; | ||
import 'package:tars_dart/tars/codec/tars_struct.dart'; | ||
|
||
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"); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
simple_live_core/lib/src/model/tars/get_cdn_token_resp.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// ignore_for_file: no_leading_underscores_for_local_identifiers | ||
|
||
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'; | ||
import 'package:tars_dart/tars/codec/tars_struct.dart'; | ||
|
||
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"); | ||
} | ||
} |
Oops, something went wrong.