Animelon's way of learning from video, from the person's own Jellyfin server: connected per device (Settings, or a studyset's Add material › Watch from Jellyfin) with a name and password or a Quick Connect code, over HTTPS only (plain HTTP only to a server on the same machine); the token stays in the system's keyring. Shows, films and videos tied to a studyset follow the person in their settings as the server's and the item's ids alone (settings schema 9), named by the server when shown. The Watch screen plays the video (video_player on Android, media_kit's libmpv on Linux and Windows) with the line in the studyset's front language cut into the dictionary's words with furigana, and the back language's line beneath; a word tapped pauses the video and becomes a card with the line and its translation as its first hint, tagged with the show. The video's words are listed, most frequent first. The sound is the track in the studyset's language, whichever the file marks default, and the menu switches it; the subtitles read are a whole track, never a forced one (which only covers what the sound doesn't say), and captions for the hard of hearing only without plain ones. The line and its translation take the video's width in a box of a fixed height, so the video keeps its size; in the dark theme the video's colours glow around it, as YouTube's ambient mode, and the words' panel takes the colour of the episode's picture under the pointer. A line is cut into words with one request: DictionaryEndpoint.withKeys looks up every stretch of it that may be a word, as it stands and as every word it may be a conjugation of, in the new dictionary_key table (one row per key, indexed; migration dictionary-keys adds the table and its index, nothing else), which the loader fills beside the entries. The instance gets the text of each line looked up and keeps none of it, as the Watch screen says. Linux builds need libmpv-dev, and the app links libmpv: the snap stages Ubuntu's libmpv2, makes the update-alternatives links for BLAS and LAPACK that ffmpeg's speech recognition needs (staging never runs install scripts), and removes what the GNOME runtime and core24 already hold, as older copies of cairo, pango and librsvg hid the runtime's from its GTK. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
133 lines
5.2 KiB
Dart
133 lines
5.2 KiB
Dart
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:halkyon_learn_flutter/src/core/video/media_players.dart';
|
|
import 'package:halkyon_learn_flutter/src/core/video/subtitles.dart';
|
|
import 'package:halkyon_learn_flutter/src/feature/jellyfin/data/jellyfin_gateway.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:integration_test/integration_test.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
|
|
// The video player for real (ExoPlayer on Android, libmpv on Linux and
|
|
// Windows), streaming from a Jellyfin server, which `flutter test` can't:
|
|
// on a device or the desktop,
|
|
//
|
|
// flutter test integration_test/jellyfin_player_test.dart -d <device> \
|
|
// --dart-define=JELLYFIN_URL=https://jellyfin.example.org \
|
|
// --dart-define=JELLYFIN_USER=<name> \
|
|
// --dart-define=JELLYFIN_PASSWORD=<password>
|
|
//
|
|
// with a server holding at least one episode, film or video with text
|
|
// subtitles, reached over HTTPS as the app reaches it (Android refuses plain
|
|
// HTTP to it). A Linux build needs libmpv-dev.
|
|
const _url = String.fromEnvironment('JELLYFIN_URL');
|
|
const _user = String.fromEnvironment('JELLYFIN_USER');
|
|
const _password = String.fromEnvironment('JELLYFIN_PASSWORD');
|
|
|
|
void main() {
|
|
// Frames as the app draws them, as the picture is checked.
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized().framePolicy =
|
|
LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
|
|
|
|
testWidgets('streams a video with subtitles from the server and plays it', (
|
|
tester,
|
|
) async {
|
|
final client = http.Client();
|
|
addTearDown(client.close);
|
|
final gateway = HttpJellyfinGateway(
|
|
client,
|
|
device: (id: 'device-check', name: 'Device check', version: '0'),
|
|
);
|
|
final found = await tester.runAsync(() async {
|
|
final server = await gateway.server(Uri.parse(_url));
|
|
final account = await gateway.signIn(server, _user, _password);
|
|
final videos = await gateway.search(account, '');
|
|
final libraries = await gateway.libraries(account);
|
|
// Down the first library to its first video.
|
|
var items = [...videos, ...libraries];
|
|
for (var depth = 0; depth < 4; depth++) {
|
|
final video = items.where((item) => item.kind.isVideo).firstOrNull;
|
|
if (video != null) {
|
|
final playback = await gateway.playback(account, video.id);
|
|
final track = playback.subtitles
|
|
.where((track) => track.isText)
|
|
.firstOrNull;
|
|
final cues = track == null
|
|
? const <SubtitleCue>[]
|
|
: parseSubtitles(
|
|
await gateway.subtitles(account, playback, track),
|
|
);
|
|
return (account: account, playback: playback, cues: cues);
|
|
}
|
|
items = items.isEmpty
|
|
? items
|
|
: await gateway.children(account, items.first.id);
|
|
}
|
|
return null;
|
|
});
|
|
expect(found, isNotNull, reason: 'No video found on $_url');
|
|
final (:account, :playback, :cues) = found!;
|
|
expect(cues, isNotEmpty, reason: 'The video has no text subtitles');
|
|
|
|
final players = PlatformMediaPlayers();
|
|
expect(players.available, isTrue);
|
|
// From the middle, where a picture is unlikely to be one colour.
|
|
final video = (await tester.runAsync(
|
|
() => players.open(
|
|
gateway.streamOf(account, playback),
|
|
headers: gateway.headersOf(account),
|
|
start: (playback.runTime ?? Duration.zero) ~/ 2,
|
|
),
|
|
))!;
|
|
addTearDown(() => tester.runAsync(video.dispose));
|
|
final picture = GlobalKey();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: Center(
|
|
child: RepaintBoundary(
|
|
key: picture,
|
|
child: SizedBox(width: 640, height: 360, child: video.view()),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.runAsync(() async {
|
|
await video.play();
|
|
await Future<void>.delayed(const Duration(seconds: 4));
|
|
});
|
|
await tester.pump();
|
|
|
|
final state = video.state.value;
|
|
expect(state.error, isNull);
|
|
expect(state.duration, greaterThan(Duration.zero));
|
|
expect(state.position, greaterThan(const Duration(seconds: 1)));
|
|
// The picture is drawn, not only the sound played: a frame isn't one
|
|
// flat colour.
|
|
final boundary =
|
|
picture.currentContext!.findRenderObject()! as RenderRepaintBoundary;
|
|
final frame = (await tester.runAsync(() async {
|
|
final image = await boundary.toImage();
|
|
return (await image.toByteData())!;
|
|
}))!;
|
|
final lightness = [
|
|
for (var i = 0; i < frame.lengthInBytes; i += 4)
|
|
frame.getUint8(i) + frame.getUint8(i + 1) + frame.getUint8(i + 2),
|
|
];
|
|
final mean = lightness.reduce((a, b) => a + b) / lightness.length;
|
|
final spread =
|
|
lightness.map((value) => (value - mean).abs()).reduce((a, b) => a + b) /
|
|
lightness.length;
|
|
expect(spread, greaterThan(4), reason: 'The picture is one flat colour');
|
|
|
|
await tester.runAsync(() => video.seekTo(cues.first.start));
|
|
await tester.runAsync(
|
|
() => Future<void>.delayed(const Duration(milliseconds: 500)),
|
|
);
|
|
expect(
|
|
cueAt(cues, video.state.value.position + const Duration(milliseconds: 1)),
|
|
isNotNull,
|
|
);
|
|
});
|
|
}
|