Skip to content

Commit

Permalink
Merge pull request #478 from xiaoyaocz/dev
Browse files Browse the repository at this point in the history
Release 1.6.5 / TV 1.1.2
  • Loading branch information
xiaoyaocz authored Jul 18, 2024
2 parents 023bdfc + aceea16 commit 62279e7
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 92 deletions.
6 changes: 3 additions & 3 deletions assets/app_version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "1.6.3",
"version_num": 10603,
"version_desc": "- 修复抖音无法读取直播状态 #431\n- 修复抖音无法读取原画 #429\n- 优化直播状态读取\n-斗鱼默认不使用PCDN链接",
"version": "1.6.5",
"version_num": 10605,
"version_desc": "- 修复抖音弹幕连接失败问题 #458\n- 修复弹幕不消失问题 #454\n- 恢复抖音直播间搜索",
"prerelease":false,
"download_url": "https://github.com/xiaoyaocz/dart_simple_live/releases"
}
6 changes: 3 additions & 3 deletions assets/tv_app_version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "1.1.0",
"version_num": 10100,
"version_desc": "- 修复抖音无法读取原画\n- 优化直播状态读取\n-斗鱼默认不使用PCDN链接",
"version": "1.1.2",
"version_num": 10102,
"version_desc": "- 修复抖音弹幕连接失败问题 #458\n- 修复弹幕不消失问题 #454\n- 恢复抖音直播间搜索",
"prerelease":true,
"download_url": "https://github.com/xiaoyaocz/dart_simple_live/releases"
}
56 changes: 27 additions & 29 deletions simple_live_app/lib/modules/search/search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:simple_live_app/app/constant.dart';
import 'package:simple_live_app/app/sites.dart';
import 'package:simple_live_app/modules/search/douyin/douyin_search_controller.dart';
import 'package:simple_live_app/modules/search/search_list_controller.dart';

class AppSearchController extends GetxController
Expand All @@ -25,9 +23,9 @@ class AppSearchController extends GetxController
}

index = currentIndex;
if (Sites.supportSites[index].id == Constant.kDouyin) {
return;
}
// if (Sites.supportSites[index].id == Constant.kDouyin) {
// return;
// }

var controller =
Get.find<SearchListController>(tag: Sites.supportSites[index].id);
Expand All @@ -47,14 +45,14 @@ class AppSearchController extends GetxController
@override
void onInit() {
for (var site in Sites.supportSites) {
if (site.id == Constant.kDouyin) {
Get.put(DouyinSearchController(site));
} else {
Get.put(
SearchListController(site),
tag: site.id,
);
}
// if (site.id == Constant.kDouyin) {
// Get.put(DouyinSearchController(site));
// } else {
Get.put(
SearchListController(site),
tag: site.id,
);
//}
}

super.onInit();
Expand All @@ -65,23 +63,23 @@ class AppSearchController extends GetxController
return;
}
for (var site in Sites.supportSites) {
if (site.id == Constant.kDouyin) {
var controller = Get.find<DouyinSearchController>();
controller.keyword = searchController.text;
controller.searchMode.value = searchMode.value;
controller.reloadWebView();
} else {
var controller = Get.find<SearchListController>(tag: site.id);
controller.clear();
controller.keyword = searchController.text;
controller.searchMode.value = searchMode.value;
}
}
if (Sites.supportSites[index].id != Constant.kDouyin) {
var controller =
Get.find<SearchListController>(tag: Sites.supportSites[index].id);
controller.refreshData();
// if (site.id == Constant.kDouyin) {
// var controller = Get.find<DouyinSearchController>();
// controller.keyword = searchController.text;
// controller.searchMode.value = searchMode.value;
// controller.reloadWebView();
// } else {
var controller = Get.find<SearchListController>(tag: site.id);
controller.clear();
controller.keyword = searchController.text;
controller.searchMode.value = searchMode.value;
//}
}
// if (Sites.supportSites[index].id != Constant.kDouyin) {
var controller =
Get.find<SearchListController>(tag: Sites.supportSites[index].id);
controller.refreshData();
//}
}

@override
Expand Down
16 changes: 8 additions & 8 deletions simple_live_app/lib/modules/search/search_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:simple_live_app/app/app_style.dart';
import 'package:simple_live_app/app/constant.dart';
import 'package:simple_live_app/app/sites.dart';
import 'package:simple_live_app/modules/search/douyin/douyin_search_view.dart';
import 'package:simple_live_app/modules/search/search_controller.dart';
import 'package:simple_live_app/modules/search/search_list_view.dart';

Expand Down Expand Up @@ -93,13 +91,15 @@ class SearchPage extends GetView<AppSearchController> {
physics: const NeverScrollableScrollPhysics(),
controller: controller.tabController,
children: Sites.supportSites
.map(
(e) => e.id == Constant.kDouyin
? const DouyinSearchView()
: SearchListView(
.map((e) => SearchListView(
e.id,
),
)
)
// (e) => e.id == Constant.kDouyin
// ? const DouyinSearchView()
// : SearchListView(
// e.id,
// ),
)
.toList(),
),
);
Expand Down
4 changes: 2 additions & 2 deletions simple_live_app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: simple_live_app
version: 1.6.3+10603
version: 1.6.5+10605
publish_to: none
description: "Simple Live APP"
environment:
Expand Down Expand Up @@ -35,7 +35,7 @@ dependencies:
ns_danmaku: #弹幕
git:
url: https://github.com/xiaoyaocz/flutter_ns_danmaku.git
tag: v0.0.8
tag: v0.0.9


#系统交互
Expand Down
21 changes: 12 additions & 9 deletions simple_live_core/example/simple_live_core_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:simple_live_core/simple_live_core.dart';
void main() async {
CoreLog.enableLog = true;
CoreLog.requestLogType = RequestLogType.short;
LiveSite site = DouyuSite();
LiveSite site = DouyinSite();
var danmaku = site.getDanmaku();
danmaku.onMessage = (event) {
if (event.type == LiveMessageType.chat) {
Expand All @@ -18,16 +18,19 @@ void main() async {
danmaku.onClose = (event) {
print(event);
};

var search = await site.searchRooms("东方");

//var categores = await site.getCategores();
//print(categores.length);
var detail = await site.getRoomDetail(roomId: "687423");
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);
}
var detail = await site.getRoomDetail(roomId: search.items.first.roomId);
// 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);
Expand Down
35 changes: 30 additions & 5 deletions simple_live_core/lib/src/danmaku/douyin_danmaku.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:simple_live_core/src/common/http_client.dart' as http;

import 'package:simple_live_core/simple_live_core.dart';
import 'package:simple_live_core/src/common/web_socket_util.dart';

Expand Down Expand Up @@ -74,24 +76,27 @@ class DouyinDanmaku implements LiveDanmaku {
"browser_platform": "Win32",
"browser_name": "Mozilla",
"browser_version":
"5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.51",
DouyinSite.kDefaultUserAgent.replaceAll("Mozilla/", ""),
"browser_online": "true",
"tz_name": "Asia/Shanghai",
"identity": "audience",
"room_id": danmakuArgs.roomId,
"heartbeatDuration": "0",
"signature": "00000000"
//"signature": "00000000"
});
var url = uri.toString();

var sign = await getSignature(danmakuArgs.roomId, danmakuArgs.userId);

var url = "$uri&signature=$sign";
var backupUrl = url.replaceAll("webcast3-ws-web-lq", "webcast5-ws-web-lf");
print(url);
webScoketUtils = WebScoketUtils(
url: url,
backupUrl: backupUrl,
headers: {
"User-Agnet":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.51",
"User-Agnet": DouyinSite.kDefaultUserAgent,
"Cookie": danmakuArgs.cookie,
"Origin": "https://live.douyin.com"
},
heartBeatTime: heartbeatTime,
onMessage: (e) {
Expand Down Expand Up @@ -192,4 +197,24 @@ class DouyinDanmaku implements LiveDanmaku {
onClose = null;
webScoketUtils?.close();
}

/// 获取Websocket签名
/// - [roomId] 房间ID, 例如:7382735338101328680
/// - [uniqueId] 用户唯一ID, 例如:7273033021933946427
///
/// 服务端代码:https://github.com/lovelyyoshino/douyin_python,请自行部署后使用
Future<String> getSignature(String roomId, String uniqueId) async {
try {
var signResult = await http.HttpClient.instance.postJson(
"https://dy.nsapps.cn/signature",
queryParameters: {},
header: {"Content-Type": "application/json"},
data: {"roomId": roomId, "uniqueId": uniqueId},
);
return signResult["data"]["signature"];
} catch (e) {
CoreLog.error(e);
return "";
}
}
}
57 changes: 36 additions & 21 deletions simple_live_core/lib/src/douyin_site.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class DouyinSite implements LiveSite {
var items = <LiveRoomItem>[];
for (var item in result["data"]["data"]) {
var roomItem = LiveRoomItem(
roomId: item["room"]["id_str"].toString(),
roomId: item["web_rid"],
title: item["room"]["title"].toString(),
cover: item["room"]["cover"]["url_list"][0].toString(),
userName: item["room"]["owner"]["nickname"].toString(),
Expand Down Expand Up @@ -159,7 +159,7 @@ class DouyinSite implements LiveSite {
var items = <LiveRoomItem>[];
for (var item in result["data"]["data"]) {
var roomItem = LiveRoomItem(
roomId: item["room"]["id_str"].toString(),
roomId: item["web_rid"],
title: item["room"]["title"].toString(),
cover: item["room"]["cover"]["url_list"][0].toString(),
userName: item["room"]["owner"]["nickname"].toString(),
Expand Down Expand Up @@ -351,8 +351,12 @@ class DouyinSite implements LiveSite {
/// - [webRid] 直播间RID
// ignore: unused_element
Future<String> _getUserUniqueId(String webRid) async {
var webInfo = await _getRoomDataByHtml(webRid);
return webInfo["userStore"]["odin"]["user_unique_id"].toString();
try {
var webInfo = await _getRoomDataByHtml(webRid);
return webInfo["userStore"]["odin"]["user_unique_id"].toString();
} catch (e) {
return generateRandomNumber(12).toString();
}
}

/// 进入直播间前需要先获取cookie
Expand Down Expand Up @@ -558,10 +562,10 @@ class DouyinSite implements LiveSite {
"browser_language": "zh-CN",
"browser_platform": "Win32",
"browser_name": "Edge",
"browser_version": "120.0.0.0",
"browser_version": "125.0.0.0",
"browser_online": "true",
"engine_name": "Blink",
"engine_version": "120.0.0.0",
"engine_version": "125.0.0.0",
"os_name": "Windows",
"os_version": "10",
"cpu_core_num": "12",
Expand All @@ -570,10 +574,10 @@ class DouyinSite implements LiveSite {
"downlink": "10",
"effective_type": "4g",
"round_trip_time": "100",
"webid": "7273033021933946427",
"webid": "7382872326016435738",
});
var requlestUrl = await signUrl(uri.toString());

//var requlestUrl = await getAbogusUrl(uri.toString());
var requlestUrl = uri.toString();
var headResp = await HttpClient.instance
.head('https://live.douyin.com', header: headers);
var dyCookie = "";
Expand All @@ -591,14 +595,24 @@ class DouyinSite implements LiveSite {
requlestUrl,
queryParameters: {},
header: {
"Accept": "*/*",
"Authority": 'www.douyin.com',
"Referer": requlestUrl,
"Cookie": dyCookie,
"User-Agent": kDefaultUserAgent,
'accept': 'application/json, text/plain, */*',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
'cookie': dyCookie,
'priority': 'u=1, i',
'referer':
'https://www.douyin.com/search/${Uri.encodeComponent(keyword)}?type=live',
'sec-ch-ua':
'"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': kDefaultUserAgent,
},
);
if (result == 'blocked') {
if (result == "" || result == 'blocked') {
throw Exception("抖音直播搜索被限制,请稍后再试");
}
var items = <LiveRoomItem>[];
Expand Down Expand Up @@ -657,19 +671,20 @@ class DouyinSite implements LiveSite {
Random().nextInt(1000000000);
}

Future<String> signUrl(String url) async {
/// 读取A-Bogus签名后的URL
/// - [url] 原始URL
/// - 返回签名后的URL
///
/// 服务端代码:https://github.com/dengmin/a-bogus,请自行部署后使用
Future<String> getAbogusUrl(String url) async {
try {
// 发起一个签名请求
// 服务端代码:https://github.com/5ime/Tiktok_Signature
var signResult = await HttpClient.instance.postJson(
"https://tk.nsapps.cn/",
"https://dy.nsapps.cn/abogus",
queryParameters: {},
header: {"Content-Type": "application/json"},
data: {"url": url, "userAgent": kDefaultUserAgent},
);
var requlestUrl =
'${signResult["data"]["url"]}&msToken=${Uri.encodeComponent(signResult["data"]["mstoken"])}';
return requlestUrl;
return signResult["data"]["url"];
} catch (e) {
CoreLog.error(e);
return url;
Expand Down
8 changes: 4 additions & 4 deletions simple_live_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: simple_live_core
version: 1.0.3
description: "聚合直播核心库"
repository: https://github.com/xiaoyaocz/simple_live_client
repository: https://github.com/xiaoyaocz/dart_simple_live
publish_to: "none"
environment:
sdk: '>=2.19.1 <3.0.0'

dependencies:
dio: ^5.3.2
logger: ^2.0.2
web_socket_channel: ^2.4.0
dio: ^5.5.0+1
logger: ^2.4.0
web_socket_channel: ^3.0.1
html_unescape: ^2.0.0
protobuf: ^3.1.0
crypto: ^3.0.3
Expand Down
Loading

0 comments on commit 62279e7

Please sign in to comment.