Skip to content

Commit

Permalink
Finally feel satisfied enough to build these changes
Browse files Browse the repository at this point in the history
  • Loading branch information
femalemonkeyman committed Aug 14, 2023
1 parent cc92e6b commit 60aadec
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 131 deletions.
32 changes: 14 additions & 18 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,12 @@ class Navigation extends StatelessWidget {
GoRoute(
name: 'anime',
path: '/anime',
pageBuilder: (context, state) => MaterialPage(
child: AniPage(
key: (state.uri.queryParameters.isEmpty)
? null
: Key(state.uri.queryParameters['tag']!),
type: 'anime',
tag: state.uri.queryParameters['tag'],
),
builder: (context, state) => AniPage(
key: (state.uri.queryParameters.isEmpty)
? null
: Key(state.uri.queryParameters['tag']!),
type: 'anime',
tag: state.uri.queryParameters['tag'],
),
routes: [
GoRoute(
Expand Down Expand Up @@ -147,15 +145,13 @@ class Navigation extends StatelessWidget {
GoRoute(
name: 'manga',
path: '/manga',
builder: (context, state) {
return AniPage(
key: (state.uri.queryParameters.isEmpty)
? null
: Key(state.uri.queryParameters['tag']!),
type: 'manga',
tag: state.uri.queryParameters['tag'],
);
},
builder: (context, state) => AniPage(
key: (state.uri.queryParameters.isEmpty)
? null
: Key(state.uri.queryParameters['tag']!),
type: 'manga',
tag: state.uri.queryParameters['tag'],
),
routes: [
GoRoute(
parentNavigatorKey: _rootKey,
Expand Down Expand Up @@ -201,7 +197,7 @@ class Navigation extends StatelessWidget {
GoRoute(
name: 'later',
path: '/later',
builder: (context, state) => const LaterPage(),
builder: (context, state) => LaterPage(),
),
],
),
Expand Down
11 changes: 7 additions & 4 deletions lib/media/media.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class AniPageState extends State<AniPage> {
bool loading = false;
final List<String> selectedGenres = [];
late String? tag = widget.tag;
Map pageInfo = {};
final Map pageInfo = {};
final List<AniData> animeData = [];

@override
Expand Down Expand Up @@ -124,7 +124,11 @@ class AniPageState extends State<AniPage> {
},
),
);
pageInfo = query.data!['Page']['pageInfo'];
pageInfo
..clear()
..addAll(
query.data!['Page']['pageInfo'],
);
animeData.addAll(
List.generate(
query.data!['Page']['media'].length,
Expand Down Expand Up @@ -200,7 +204,7 @@ class AniPageState extends State<AniPage> {
},
).then(
(value) async {
pageInfo = {};
pageInfo.clear();
animeData.clear();
await queryData();
setState(
Expand Down Expand Up @@ -237,7 +241,6 @@ class AniPageState extends State<AniPage> {
},
),
child: CustomScrollView(
primary: true,
slivers: [
SliverToBoxAdapter(
child: Center(
Expand Down
89 changes: 68 additions & 21 deletions lib/media/media_anime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import 'package:window_manager/window_manager.dart';

const Source blank = Source(qualities: {}, subtitles: {});

void setSubtitles(final Source media, final Player player) {
if (media.subtitles.isNotEmpty) {
player.setSubtitleTrack(
SubtitleTrack.uri(
media.subtitles.entries
.firstWhere(
(element) => element.key.toLowerCase().contains('eng'),
)
.value,
),
);
}
}

class AniViewer extends StatefulWidget {
final List<MediaProv> episodes;
final int episode;
Expand Down Expand Up @@ -54,7 +68,11 @@ class AniViewerState extends State<AniViewer> {
httpHeaders: media.headers ?? {},
),
);
setState(() {});
setState(
() {
setSubtitles(media, player);
},
);
}
}

Expand Down Expand Up @@ -407,26 +425,55 @@ class TopBar extends StatelessWidget {
height: size.height / 2,
),
builder: (context) => ListView(
children: List.generate(
// player.state.tracks.video.length - 2,
media.qualities.length,
(index) {
return ListTile(
title: Text(media.qualities.keys.elementAt(index)),
onTap: () async {
final current = await player.stream.buffer.first;
print(current);
await player.open(
Media(
media.qualities.values.elementAt(index),
httpHeaders: media.headers,
),
);
await player.seek(current);
},
);
},
),
children: (media.qualities.length == 1)
? List.generate(
player.state.tracks.video.length - 2,
(index) {
return ListTile(
title: Text(
player.state.tracks.video[index + 2].h
.toString(),
),
onTap: () {
player.setVideoTrack(
player.state.tracks.video[index + 2],
);
context.pop();
},
);
},
)
: List.generate(
media.qualities.length,
(index) {
return ListTile(
title:
Text(media.qualities.keys.elementAt(index)),
onTap: () {
Future.microtask(
() async {
final current =
await player.stream.position.first;
player.open(
Media(
media.qualities.values
.elementAt(index),
httpHeaders: media.headers,
),
play: false,
);
await player.stream.buffer.first;
setSubtitles(media, player);
player
..seek(current)
..play();
},
);
context.pop();
},
);
},
),
),
),
),
Expand Down
76 changes: 42 additions & 34 deletions lib/media/providers/anime/animepahe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ Provider paheList(final AniData data) async {
'https://animepahe.ru/api?m=release&id=$syncId&sort=episode_asc';
final Map anime = (await Dio().get(link)).data;
if (anime['last_page'] > 1) {
final List<Future<Response<Map>>> requests = [];
for (int i = 2; i <= anime['last_page']; i++) {
requests.add(
Dio().get('$link&page=$i'), //.data['data']
);
}
for (Response i in await Future.wait(requests)) {
for (Response i in await Future.wait(
[
for (int i = 2; i <= anime['last_page']; i++)
Dio().get('$link&page=$i'),
],
)) {
anime['data'].addAll(i.data['data']);
}
}
Expand All @@ -48,7 +47,7 @@ Provider paheList(final AniData data) async {
}

Anime paheInfo(final String id) async {
final Document data = parse(
final List<Element> data = parse(
(await Dio().get(
'https://animepahe.ru/play/$id',
options: Options(
Expand All @@ -58,34 +57,43 @@ Anime paheInfo(final String id) async {
),
))
.data,
);
for (Element i in data.body!
)
.getElementsByTagName('button')
.where((element) => element.attributes.containsKey('data-src'))) {
if (i.attributes['data-src']?.contains('kwik') ?? false) {
Document arr = parse(
(await Dio().get(
i.attributes['data-src']!,
options: Options(
headers: {
'referer': 'https://animepahe.ru',
},
),
))
.data,
);
qualities.addAll(
{
'${i.attributes['data-fansub']}-${i.attributes['data-resolution']}':
JsUnpack(
'\r${arr.getElementsByTagName('script').where((element) => element.text.contains('eval')).first.text}',
).unpack().split('source=\'')[1].split('\'')[0]
},
);
}
}
.where(
(element) =>
element.attributes.containsKey('data-src') &&
(element.attributes['data-src']?.contains('kwik') ?? false),
)
.toList();
return Source(
qualities: qualities,
qualities: Map.fromIterables(
[
for (Element i in data)
'${i.attributes['data-fansub']}-${i.attributes['data-resolution']}'
].reversed,
[
for (Response i in await Future.wait(
[
for (Element i in data)
Dio().get(
i.attributes['data-src']!,
options: Options(
headers: {
'referer': 'https://animepahe.ru',
},
),
)
],
))
JsUnpack(
parse(i.data)
.getElementsByTagName('script')
.where((element) => element.text.contains('eval'))
.first
.text,
).unpack().split('source=\'')[1].split('\'')[0],
].reversed,
), //qualities,
subtitles: {},
headers: {'referer': 'https://kwik.cx'},
);
Expand Down
7 changes: 3 additions & 4 deletions lib/media/providers/anime/aniwatch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Provider zoroList(final AniData data) async {
}

Anime zoroInfo(final id) async {
print(id);
final Options options = Options(responseType: ResponseType.plain);
final Element server = parse(
jsonDecode(
Expand All @@ -61,7 +62,7 @@ Anime zoroInfo(final id) async {
))
.data,
);
Map<String, dynamic> sources = jsonDecode(
final Map<String, dynamic> sources = jsonDecode(
(await Dio().get(
'https://megacloud.tv/embed-2/ajax/e-1/getSources?id=${link['link'].split('e-1/')[1].split('?')[0]}',
options: options))
Expand All @@ -83,9 +84,7 @@ Anime zoroInfo(final id) async {
}
sources['sources'] = jsonDecode(decrypt(sources['sources'], key));
}
if (sources['tracks'].last['kind'] != 'captions') {
(sources['tracks'] as List).removeLast();
}
sources['tracks'].removeWhere((element) => element['kind'] != 'captions');
return Source(
qualities: {
'default': sources['sources'][0]['file'],
Expand Down
36 changes: 17 additions & 19 deletions lib/pages/later_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@ import 'package:flutter/material.dart';
import 'package:isar/isar.dart';
import 'package:path_provider/path_provider.dart';

class LaterPage extends StatefulWidget {
const LaterPage({super.key});
class LaterPage extends StatelessWidget {
final List<AniData> animeData = [];
final List<AniData> mangaData = [];

@override
State createState() => LaterPageState();
}

class LaterPageState extends State<LaterPage> {
List<AniData> animeData = [];
List<AniData> mangaData = [];
LaterPage({super.key});
Future<Directory> get dir async {
return await getApplicationDocumentsDirectory();
}

final Isar isar = Isar.getInstance('later')!;
late final dataChange = isar.aniDatas.watchLazy(fireImmediately: true);

@override
void initState() {
super.initState();
}
late final Stream dataChange = isar.aniDatas.watchLazy(fireImmediately: true);

void updateData() {
animeData = isar.aniDatas.filter().typeEqualTo("anime").findAllSync();
mangaData = isar.aniDatas.filter().typeEqualTo("manga").findAllSync();
animeData
..clear()
..addAll(
isar.aniDatas.filter().typeEqualTo("anime").findAllSync(),
);
mangaData
..clear()
..addAll(
isar.aniDatas.filter().typeEqualTo("manga").findAllSync(),
);
}

@override
Expand All @@ -53,7 +51,7 @@ class LaterPageState extends State<LaterPage> {
Spacer(),
Text(
'Anime',
textScaleFactor: 1.2,
textScaler: TextScaler.linear(1.2),
),
Spacer(),
Expanded(
Expand All @@ -79,7 +77,7 @@ class LaterPageState extends State<LaterPage> {
Spacer(),
Text(
'Manga',
textScaleFactor: 1.2,
textScaler: TextScaler.linear(1.2),
),
Spacer(),
Expanded(
Expand Down
Loading

0 comments on commit 60aadec

Please sign in to comment.