Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# 更新日志

## 1.2.5

- 修复《异度旅社》等正常专辑误报已下架。
- 修复长专辑超过 5000 集后无法选集和续播,播放队列上限提高至 15000 集。

## 1.2.4

- 完善莘应用更新源,支持 Android 各架构安装包。
Expand Down
20 changes: 11 additions & 9 deletions lib/api/xmly_catalogue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class XmlyCatalogue {
}
result += section + digit;
}
if (result < 1 || result > 5000)
if (result < 1)
throw const XmlyException(
'invalid_episode',
'集数范围为 1 到 5000',
'请输入正整数集数',
definitive: true,
);
return result;
Expand Down Expand Up @@ -183,10 +183,10 @@ class XmlyCatalogue {
pageSize: pageSize,
ascending: true,
);
if (result.total > 5000)
if (result.total > xmlyMaxQueueTracks)
throw const XmlyException(
'catalogue_limit',
'专辑超过 5000 首队列上限',
'一次最多加载 $xmlyMaxQueueTracks 集,请按页浏览',
definitive: true,
);
if (result.total < 0 ||
Expand Down Expand Up @@ -267,7 +267,7 @@ class XmlyCatalogue {
"lib/api/xmly_catalogue.dart::XmlyCatalogue.selectRange",
);

if (items.length > 5000 || expression.isEmpty || expression.length > 40000)
if (expression.isEmpty || expression.length > 40000)
throw const XmlyException('invalid_range', '选择范围无效', definitive: true);
final wanted = <int>{};
for (final part in expression.split(RegExp('[,,]'))) {
Expand All @@ -281,14 +281,16 @@ class XmlyCatalogue {
);
final start = int.tryParse(match[1]!) ?? 0,
end = int.tryParse(match[2] ?? match[1]!) ?? 0;
if (start < 1 || end < start || end > 5000)
if (start < 1 || end < start || end - start >= 5000)
throw const XmlyException(
'invalid_range',
'选择范围必须在 1 到 5000 之间',
'请填写有效的声音序号,每批最多选择 5000 集',
definitive: true,
);
for (var value = start; value <= end; value++) {
wanted.add(value);
for (var offset = 0; offset <= end - start; offset++) {
wanted.add(start + offset);
if (wanted.length > 5000)
throw const XmlyException('invalid_range', '每批最多选择 5000 集');
}
}
final selected = <int, Track>{};
Expand Down
18 changes: 10 additions & 8 deletions lib/api/xmly_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class XmlyClient {
static const collector = 'https://xdcs-collector.ximalaya.com';
static const welfare = 'https://m.ximalaya.com';
static const paidOrigin = 'https://mpaywsa.ximalaya.com';
static const _albumTracksPath = '/mobile/v1/album/track/v2';
static const _maxResponse = 2 * 1024 * 1024;
static const _qualities = ['m4a_128', 'm4a_64', 'mp3_64', 'mp3_32', 'm4a_24'];
static const _maxUrlCacheFile = 16 * 1024 * 1024;
Expand Down Expand Up @@ -248,13 +249,13 @@ class XmlyClient {
return method == 'GET' &&
(const [
'/mobile/v1/album/info',
_albumTracksPath,
'/mobile-album/album/plant/detail',
'/lite-mobile/like/v1/user-likes',
].contains(path) ||
_playpageEndpoint(method, origin, path) ||
_albumOverviewEndpoint(method, origin, path) ||
RegExp(r'^/mobile/track/[1-9][0-9]{0,18}$').hasMatch(path) ||
RegExp(r'^/mobile/v1/album/track/ts-[0-9]+$').hasMatch(path) ||
RegExp(
r'^/album-mobile/album/similar/querySimilarAlbumList/ts-[0-9]+$',
).hasMatch(path) ||
Expand Down Expand Up @@ -938,10 +939,13 @@ class XmlyClient {
static void _paging(int page, int pageSize, {int maxPageSize = 50}) {
AppLog.instance.trace("lib/api/xmly_client.dart::XmlyClient._paging");

if (page < 1 || page > 10000 || pageSize < 1 || pageSize > maxPageSize)
if (page < 1 ||
page > xmlyMaxPage ||
pageSize < 1 ||
pageSize > maxPageSize)
throw XmlyException(
'invalid_page',
'页码范围为 1..10000,每页 1..$maxPageSize',
'页码范围为 1..$xmlyMaxPage,每页 1..$maxPageSize',
definitive: true,
);
}
Expand Down Expand Up @@ -1206,15 +1210,13 @@ class XmlyClient {
'isAsc': '${ascending != defaultDescending}',
'device': 'android',
};
final path =
'/mobile/v1/album/track/ts-${DateTime.now().millisecondsSinceEpoch}';
Map<String, dynamic> response;
var authenticated = accountAvailable;
try {
response = await request(
'GET',
mobile,
path,
_albumTracksPath,
query: query,
account: authenticated,
);
Expand All @@ -1225,7 +1227,7 @@ class XmlyClient {
response = await request(
'GET',
mobile,
path,
_albumTracksPath,
query: query,
account: false,
);
Expand Down Expand Up @@ -1328,7 +1330,7 @@ class XmlyClient {
final response = await request(
'GET',
mobile,
'/mobile/v1/album/track/ts-${DateTime.now().millisecondsSinceEpoch}',
_albumTracksPath,
query: {...query, 'pageId': childPage, 'pageSize': childSize},
account: authenticated,
);
Expand Down
12 changes: 7 additions & 5 deletions lib/models/xmly_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'package:crypto/crypto.dart';
import "../services/app_log.dart";

const int xmlyAlbumPageSize = 200;
const int xmlyMaxPage = 10000;
// Whole-queue operations materialize every track. Paged playback does not.
const int xmlyMaxQueueTracks = 15000;

class XmlyException implements Exception {
final String code, message;
Expand Down Expand Up @@ -524,7 +527,7 @@ class PlaybackQueue {
needsRepair = false {
AppLog.instance.trace("lib/models/xmly_models.dart::PlaybackQueue.new");

if (tracks.length > 5000 ||
if (tracks.length > xmlyMaxQueueTracks ||
cursor < -1 ||
cursor >= tracks.length ||
(tracks.isNotEmpty && cursor < 0)) {
Expand All @@ -546,9 +549,8 @@ class PlaybackQueue {
(this.albumPageSize != 50 &&
this.albumPageSize != xmlyAlbumPageSize) ||
albumPage! < 1 ||
albumPage! > 5000 ~/ this.albumPageSize! ||
albumTotal! < 0 ||
albumTotal! > 5000))) {
albumPage! > xmlyMaxPage ||
albumTotal! < 0))) {
throw const FormatException('播放队列分页损坏');
}
final ids = <String>{};
Expand Down Expand Up @@ -605,7 +607,7 @@ class PlaybackQueue {
final tracks = value['tracks'], cursor = value['cursor'];
final album = value['sourceAlbumId'], source = value['source'];
if (tracks is! List ||
tracks.length > 5000 ||
tracks.length > xmlyMaxQueueTracks ||
cursor is! int ||
album is! String) {
throw const FormatException('播放队列损坏');
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/catalogue_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Future<AlbumPage> locateCatalogueTarget({
if (track.id != target.id ||
track.albumId != albumId ||
ordinal == null ||
ordinal > 5000)
ordinal > xmlyMaxPage * xmlyAlbumPageSize)
return null;
var result = await read((ordinal - 1) ~/ xmlyAlbumPageSize + 1);
if (ordinal > result.total) return null;
Expand Down
70 changes: 39 additions & 31 deletions lib/services/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -744,17 +744,14 @@ class PlayerService {
"lib/services/player_service.dart::PlayerService._albumPage",
);

if (page < 1 || page > 5000 ~/ xmlyAlbumPageSize) {
throw const XmlyException('catalogue_limit', '专辑播放队列最多 5000 集');
}
final result = await client.album(
album,
page: page,
pageSize: xmlyAlbumPageSize,
ascending: true,
);
if (result.total < 0 || result.total > 5000) {
throw const XmlyException('catalogue_limit', '专辑播放队列最多 5000 集');
if (result.total < 0) {
throw const XmlyException('invalid_album', '专辑分页无效,请刷新重试');
}
final tracks = result.tracks, offset = (page - 1) * xmlyAlbumPageSize;
final end = (offset + xmlyAlbumPageSize).clamp(0, result.total);
Expand Down Expand Up @@ -886,12 +883,6 @@ class PlayerService {
}
final album = xmlyIdentifier(albumId),
id = 'xmly:${xmlyIdentifier(trackId)}';
if (page != null && (page < 1 || page > 5000 ~/ xmlyAlbumPageSize)) {
throw XmlyException(
'invalid_page',
'播放页码范围为 1 到 ${5000 ~/ xmlyAlbumPageSize}',
);
}
final intent = ++generation, request = _newRequest();
final client = _clientForIdentity(accountIdentity);
int? ordinalFor(Track? hint) {
Expand Down Expand Up @@ -1199,7 +1190,7 @@ class PlayerService {
return;
}
final candidate = first.officialPosition ?? xmlyPositive(first.orderNo);
if (candidate == null || candidate > 5000) {
if (candidate == null) {
throw const XmlyException('invalid_album', '队列缺少专辑页码,请从专辑页重新选择声音');
}
final request = _newRequest(), intent = _advanceIntent;
Expand Down Expand Up @@ -1312,19 +1303,23 @@ class PlayerService {
})) {
throw const XmlyException('duplicate_page', '专辑分页重复,请刷新后重试');
}
if (_queue.length + added.length > 5000) {
throw const XmlyException('catalogue_limit', '专辑播放队列最多 5000 集');
}
// Keep any tail appended while loading, and keep its last-page metadata.
final next = [...added, ..._queue];
// If the queue is full, keep the anchor page instead of rejecting a
// valid earlier page. Its discarded successors can be paged in again.
final trimmed = _queue.length + added.length > xmlyMaxQueueTracks;
final next = [
...added,
...trimmed ? _queue.take(overlap.length) : _queue,
];
++generation;
await _saveQueue(
next,
added.length,
album,
page: albumPage,
total: albumTotal,
pageSize: albumPageSize ?? xmlyAlbumPageSize,
page: trimmed ? page : albumPage,
total: trimmed ? anchorPage.total : albumTotal,
pageSize: trimmed
? xmlyAlbumPageSize
: albumPageSize ?? xmlyAlbumPageSize,
);
_queue = next;
cursor = added.length;
Expand Down Expand Up @@ -1406,6 +1401,7 @@ class PlayerService {
final total = albumTotal, page = albumPage, size = albumPageSize;
if (_queue.isEmpty ||
total == null ||
total > xmlyMaxQueueTracks ||
page == null ||
size == null ||
page * size < total ||
Expand Down Expand Up @@ -1497,6 +1493,12 @@ class PlayerService {
"lib/services/player_service.dart::PlayerService._advanceOrder.closure#1.closure#1.closure#1",
);
final first = await _albumPage(client, album, 1);
if (first.total > xmlyMaxQueueTracks) {
throw const XmlyException(
'catalogue_limit',
'此模式一次最多加载 $xmlyMaxQueueTracks 集,请使用顺序播放',
);
}
final values = <Track>[...first.tracks];
final ids = {for (final track in values) track.id};
total = first.total;
Expand Down Expand Up @@ -3139,7 +3141,7 @@ class PlayerService {
final last = snapshot.last;
final officialPosition = last.officialPosition;
final candidate = officialPosition ?? xmlyPositive(last.orderNo);
if (candidate == null || candidate > 5000) {
if (candidate == null) {
throw const XmlyException('invalid_album', '队列缺少专辑页码,请从专辑页重新选择声音');
}
void validateBoundary(int position) {
Expand Down Expand Up @@ -3232,17 +3234,15 @@ class PlayerService {
}
loadedPage = result.page;
total = result.total;
if (snapshot.length + added.length > 5000) {
throw const XmlyException('catalogue_limit', '专辑播放队列最多 5000 集');
}
}

// A queue may start mid-album; its length is not a catalogue position.
// Without an official position, orderNo selects only a candidate page.
final samePage =
officialPosition == null ||
withinPage < xmlyAlbumPageSize ||
loadedPage == 5000 ~/ xmlyAlbumPageSize;
candidate >= total ||
loadedPage == xmlyMaxPage;
final page = samePage ? loadedPage : loadedPage + 1;
final result = await _admission(request, () {
AppLog.instance.trace(
Expand Down Expand Up @@ -3273,20 +3273,28 @@ class PlayerService {
);

if (!active()) return;
final next = added.isEmpty ? snapshot : [...snapshot, ...added];
final drop = (snapshot.length + added.length - xmlyMaxQueueTracks)
.clamp(0, snapshot.length);
if (drop > cursor) {
throw const XmlyException('queue_full', '队列已满,请播放到列表末尾后再加载');
}
final next = added.isEmpty
? snapshot
: [...snapshot.skip(drop), ...added];
if (added.isNotEmpty ||
savedPage != loadedPage ||
savedTotal != total ||
savedSize != xmlyAlbumPageSize) {
await _saveQueue(
next,
cursor,
cursor - drop,
album,
page: loadedPage,
total: total,
);
}
_queue = next;
cursor -= drop;
committed = true;
if (!speculative) error = null;
status = added.isEmpty ? '已听到最新一集' : '已更新 ${added.length} 集';
Expand Down Expand Up @@ -3682,8 +3690,8 @@ class PlayerService {
);
return item.id == track.id;
});
if (existing < 0 && next.length >= 5000) {
throw const XmlyException('queue_full', '队列最多 5000 集');
if (existing < 0 && next.length >= xmlyMaxQueueTracks) {
throw const XmlyException('queue_full', '队列最多 $xmlyMaxQueueTracks 集');
}
final target = existing < 0 ? track : next.removeAt(existing);
final index = next.indexWhere((item) {
Expand Down Expand Up @@ -3740,8 +3748,8 @@ class PlayerService {
return item.id == track.id;
}))
return;
if (_queue.length >= 5000)
throw const XmlyException('queue_full', '队列最多 5000 集');
if (_queue.length >= xmlyMaxQueueTracks)
throw const XmlyException('queue_full', '队列最多 $xmlyMaxQueueTracks 集');
final next = [..._queue, track], index = cursor < 0 ? 0 : cursor;
await _saveQueue(
next,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: xmly_flutter
description: XMPlus 下载与收听客户端
publish_to: none
version: 1.2.4+17
version: 1.2.5+18
environment:
sdk: '>=3.13.7 <4.0.0'
flutter: '>=3.47.9'
Expand Down
Loading