Skip to content

Commit

Permalink
added hanime support ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
femalemonkeyman committed Mar 25, 2023
1 parent f5e8340 commit 27093c0
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 185 deletions.
1 change: 1 addition & 0 deletions lib/anime/anime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class AniPageState extends State<AniPage> with AutomaticKeepAliveClientMixin {
selectedGenres = [];
search = textController.text;
} else {
selectedGenres = [];
search = null;
}
await queryData();
Expand Down
180 changes: 98 additions & 82 deletions lib/anime/anime_videos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ class AniViewerState extends State<AniViewer> {
BetterPlayerController? phonePlayer;
int currentEpisode = 1;
List subtitles = [];
late Future<Map> getMediaInfo = mediaInfo(
widget.episode['id'],
);
Map getMedia = {};

bool isPhone = Platform.isAndroid || Platform.isIOS;

@override
void initState() {
super.initState();
Future.microtask(
() async {
getMedia = await mediaInfo(
widget.episode['id'],
) ??
widget.episode;
setState(() {});
},
);
}

Future desktopPlayer(String url) async {
Expand All @@ -45,15 +52,17 @@ class AniViewerState extends State<AniViewer> {
controller = await VideoController.create(
player!.handle,
);
Directory dir = await getTemporaryDirectory();
String path = "";
for (final i in subtitles) {
await Dio().download(i['url'], "${dir.path}/${i['lang']}subs.vtt");
if (i['lang'] == "English") {
path = "${dir.path}/${i['lang']}subs.vtt";
if (getMedia['subtitles'] != null) {
Directory dir = await getTemporaryDirectory();
String path = "";
for (final i in getMedia['subtitles']) {
await Dio().download(i['url'], "${dir.path}/${i['lang']}subs.vtt");
if (i['lang'] == "English") {
path = "${dir.path}/${i['lang']}subs.vtt";
}
}
await (player!.platform as libmpvPlayer).setProperty("sub-files", path);
}
await (player!.platform as libmpvPlayer).setProperty("sub-files", path);
await player!.open(
Playlist(
[
Expand All @@ -67,81 +76,88 @@ class AniViewerState extends State<AniViewer> {

@override
Widget build(context) {
return FutureBuilder<Map>(
future: getMediaInfo,
builder: (context, snap) {
if (snap.hasData && snap.connectionState == ConnectionState.done) {
subtitles = snap.data!['subtitles']!;
if (isPhone) {
BetterPlayerDataSource source = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
snap.data!['sources']!.first['url'],
headers: {"User-Agent": "Death"},
videoFormat: BetterPlayerVideoFormat.hls,
subtitles: List.generate(
subtitles.length - 1,
(index) {
return BetterPlayerSubtitlesSource(
selectedByDefault:
(subtitles[index]['lang'] == "English") ? true : false,
type: BetterPlayerSubtitlesSourceType.network,
name: subtitles[index]['lang'],
urls: [
subtitles[index]['url'],
],
);
},
),
);
phonePlayer = BetterPlayerController(
const BetterPlayerConfiguration(
useRootNavigator: true,
controlsConfiguration: BetterPlayerControlsConfiguration(
playerTheme: BetterPlayerTheme.material,
),
deviceOrientationsOnFullScreen: [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
if (getMedia.isNotEmpty) {
if (isPhone) {
BetterPlayerDataSource source = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
getMedia['sources']!.first['url'],
headers: {"User-Agent": "Death"},
videoFormat: BetterPlayerVideoFormat.hls,
subtitles: (subtitles.isNotEmpty)
? List.generate(
subtitles.length - 1,
(index) {
return BetterPlayerSubtitlesSource(
selectedByDefault: (subtitles[index]['lang'] == "English")
? true
: false,
type: BetterPlayerSubtitlesSourceType.network,
name: subtitles[index]['lang'],
urls: [
subtitles[index]['url'],
],
);
},
)
: null,
);
phonePlayer = BetterPlayerController(
const BetterPlayerConfiguration(
useRootNavigator: true,
controlsConfiguration: BetterPlayerControlsConfiguration(
playerTheme: BetterPlayerTheme.material,
),
deviceOrientationsOnFullScreen: [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
fullScreenByDefault: true,
autoPlay: true,
aspectRatio: 16 / 9,
allowedScreenSleep: false,
fit: BoxFit.contain,
),
betterPlayerDataSource: source,
);
return BetterPlayer(
controller: phonePlayer!,
);
} else {
return FutureBuilder(
future: desktopPlayer(
getMedia['sources'].last['url'],
),
builder: (context, innerSnap) {
if (innerSnap.connectionState == ConnectionState.done) {
return Stack(
children: [
Video(controller: controller),
VideoControls(
player: player!,
),
],
fullScreenByDefault: true,
autoPlay: true,
aspectRatio: 16 / 9,
allowedScreenSleep: false,
fit: BoxFit.contain,
),
betterPlayerDataSource: source,
);
return BetterPlayer(
controller: phonePlayer!,
);
} else {
return FutureBuilder(
future: desktopPlayer(
snap.data!['sources']!.last['url'],
),
builder: (context, innerSnap) {
if (innerSnap.connectionState == ConnectionState.done) {
return Stack(
children: [
Video(controller: controller),
VideoControls(
player: player!,
),
],
);
}
return const Center(
child: CircularProgressIndicator(),
);
},
);
}
return const Center(
child: CircularProgressIndicator(),
);
}
}
return const Center(
child: CircularProgressIndicator(),
},
);
},
);
}
} else {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () => Navigator.maybePop(context),
child: const Text("Escape?"),
),
const Center(
child: CircularProgressIndicator(),
),
],
);
}
}

@override
Expand Down
127 changes: 62 additions & 65 deletions lib/info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class InfoPageState extends State<InfoPage> {
Future.microtask(
() async {
content = (widget.data.type == "anime")
? await mediaList(widget.data.mediaId)
? await mediaList(widget.data.mediaId) ??
await haniList(widget.data.title) ??
[]
: await dexReader(widget.data.mediaId);
setState(() {});
},
Expand Down Expand Up @@ -136,75 +138,70 @@ class InfoPageState extends State<InfoPage> {
child: expands,
),
),
(content.isNotEmpty)
? SliverPadding(
padding: const EdgeInsets.all(15),
sliver: SliverGrid(
gridDelegate:
const SliverGridDelegateWithMaxCrossAxisExtent(
mainAxisSpacing: 5,
crossAxisSpacing: 6,
maxCrossAxisExtent: 400,
mainAxisExtent: 100,
//childAspectRatio: 4 / 1,
),
delegate: SliverChildBuilderDelegate(
childCount: content.length,
(context, index) {
return GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return Scaffold(
body: (widget.data.type == "anime")
? AniViewer(
episodes: content,
episode: content[index],
)
: MangaReader(
chapter: content[index],
chapters: content,
),
);
},
),
),
child: IntrinsicHeight(
child: Card(
elevation: 3,
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(
content[index]['title'],
overflow: TextOverflow.visible,
),
),
Flexible(
child: Text(
content[index]['number'],
),
if (content.isNotEmpty)
SliverPadding(
padding: const EdgeInsets.all(15),
sliver: SliverGrid(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
mainAxisSpacing: 5,
crossAxisSpacing: 6,
maxCrossAxisExtent: 400,
mainAxisExtent: 100,
//childAspectRatio: 4 / 1,
),
delegate: SliverChildBuilderDelegate(
childCount: content.length,
(context, index) {
return GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return Scaffold(
body: (widget.data.type == "anime")
? AniViewer(
episodes: content,
episode: content[index],
)
: MangaReader(
chapter: content[index],
chapters: content,
),
],
);
},
),
),
child: IntrinsicHeight(
child: Card(
elevation: 3,
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(
content[index]['title'],
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
Flexible(
child: Text(
content[index]['number'],
),
),
],
),
),
);
},
),
),
)
: const SliverToBoxAdapter(
child: Center(
child: CircularProgressIndicator(),
),
),
),
);
},
),
),
)
],
),
),
Expand Down
Loading

0 comments on commit 27093c0

Please sign in to comment.