Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
femalemonkeyman committed Jul 30, 2024
1 parent 97fc260 commit f17dcc9
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 111 deletions.
6 changes: 3 additions & 3 deletions lib/media/providers/anime/anitaku.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:encrypt/encrypt.dart';
import 'package:html/parser.dart';
import 'package:tokuwari_models/info_models.dart';

const String gogo = 'https://anitaku.so';
const String gogo = 'https://anitaku.pe';

Provider gogoList(final AniData data) async {
try {
Expand Down Expand Up @@ -59,9 +59,9 @@ Anime gogoInfo(final String id) async {
);
final response = await Dio()
.get(
'https://playtaku.online/encrypt-ajax.php?id=$updatedParams&alias=$encrypt',
'https://s3taku.com/encrypt-ajax.php?id=$updatedParams&alias=$encrypt',
options: Options(
headers: {'referer': episode, 'host': 'playtaku.online', 'x-requested-with': 'XMLHttpRequest'},
headers: {'referer': episode, 'host': 's3taku.com', 'x-requested-with': 'XMLHttpRequest'},
),
)
.then((value) => jsonDecode(value.data)['data']);
Expand Down
25 changes: 13 additions & 12 deletions lib/viewers/Anime/media_anime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ extension DurationExtension on Duration {
/// Returns a [String] representation of [Duration].
String label({Duration? reference}) {
reference ??= this;
int days = inDays;
int hours = inHours - (days * 24);
int minutes = inMinutes - (inHours * 60);
int seconds = inSeconds - (inMinutes * 60);
if (reference > const Duration(days: 1)) {
final days = inDays.toString().padLeft(3, '0');
final hours = (inHours - (inDays * 24)).toString().padLeft(2, '0');
final minutes = (inMinutes - (inHours * 60)).toString().padLeft(2, '0');
final seconds = (inSeconds - (inMinutes * 60)).toString().padLeft(2, '0');
return '$days:$hours:$minutes:$seconds';
return '${days.toString().padLeft(3, '0')}:'
'${hours.toString().padLeft(2, '0')}:'
'${minutes.toString().padLeft(2, '0')}:'
'${seconds.toString().padLeft(2, '0')}';
} else if (reference > const Duration(hours: 1)) {
final hours = inHours.toString().padLeft(2, '0');
final minutes = (inMinutes - (inHours * 60)).toString().padLeft(2, '0');
final seconds = (inSeconds - (inMinutes * 60)).toString().padLeft(2, '0');
return '$hours:$minutes:$seconds';
return '${hours.toString().padLeft(2, '0')}:'
'${minutes.toString().padLeft(2, '0')}:'
'${seconds.toString().padLeft(2, '0')}';
} else {
final minutes = inMinutes.toString().padLeft(2, '0');
final seconds = (inSeconds - (inMinutes * 60)).toString().padLeft(2, '0');
return '$minutes:$seconds';
return '${minutes.toString().padLeft(2, '0')}:'
'${seconds.toString().padLeft(2, '0')}';
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions lib/viewers/Novel/media_novel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class NovelViewerState extends State<NovelViewer> with AutomaticKeepAliveClientM
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: controller.chapters[index],
child: RichText(
text: controller.chapters[index],
textScaler: TextScaler.linear(controller.fontScale),
),
),
),
);
Expand All @@ -50,7 +53,7 @@ class NovelViewerState extends State<NovelViewer> with AutomaticKeepAliveClientM
behavior: HitTestBehavior.translucent,
onTap: () => setState(() {
print('yes');
controller.setFontScale(20);
controller.setFontScale(16);
}),
),
const BackButton(),
Expand Down
101 changes: 38 additions & 63 deletions lib/viewers/Novel/novel_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import 'dart:io';

import 'package:epubx/epubx.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:csslib/parser.dart' as cs;
import 'package:csslib/visitor.dart' as csv;
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:path/path.dart' as p;
import 'package:xml/xml.dart';

class NovelController {
final EpubBook epub;
final List<Widget> chapters;
final List<InlineSpan> chapters;
double fontScale = Platform.isAndroid || Platform.isIOS ? 1 : 1.14285714;

NovelController._(this.epub, this.chapters);
Expand Down Expand Up @@ -83,8 +80,8 @@ class ChapterParser {
_ => const TextStyle(),
};

List<Widget> parseChapters() {
final List<Widget> chapters = [];
List<InlineSpan> parseChapters() {
final List<InlineSpan> chapters = [];
for (final chapter in epub.Chapters) {
final List<InlineSpan> children = [];
currentChapterFile = chapter.ContentFileName;
Expand All @@ -101,15 +98,16 @@ class ChapterParser {
if (htmlBody == null) {
throw Exception('Chapter parsing error: HTML body not found');
}
_parseElements(htmlBody, children, const TextStyle());
chapters.add(ChapterElement(text: TextSpan(children: children)));
_parseElements(htmlBody, children);
chapters.add(TextSpan(children: children));
}
return chapters;
}

void _parseElements(XmlElement node, List<InlineSpan> children, TextStyle style) {
void _parseElements(XmlElement node, List<InlineSpan> children) {
if (node.getAttribute('hidden') != null) return;
final name = node.localName.toLowerCase();
final textWidgets = _buildWidgets(node);
switch (node.localName.toLowerCase()) {
// Inline Elements
case 'image':
Expand All @@ -119,11 +117,13 @@ class ChapterParser {
.path;
children.add(
WidgetSpan(
child: ExtendedImage.memory(
epub.images[location]!.Content!,
fit: BoxFit.cover,
enableMemoryCache: false,
clearMemoryCacheWhenDispose: true,
child: Center(
child: ExtendedImage.memory(
epub.images[location]!.Content!,
fit: BoxFit.cover,
enableMemoryCache: false,
clearMemoryCacheWhenDispose: true,
),
),
),
);
Expand All @@ -140,76 +140,51 @@ class ChapterParser {
case 'body':
case 'section':
case 'p':
children.addAll(_buildWidgets(node, style));
children.add(const TextSpan(text: '\n', style: TextStyle(fontSize: 0)));
children.addAll(textWidgets);
case 'br':
print('no');
children.add(const TextSpan(text: '\n'));
// Inline
case 'em':
case 'i':
children.add(
TextSpan(
children: textWidgets,
style: const TextStyle(fontStyle: FontStyle.italic),
),
);
case 'b':
case 'span':
case 'strong':
children.add(
TextSpan(
children: textWidgets,
style: const TextStyle(fontWeight: FontWeight.bold),
),
);
case 'a':
children.addAll(_buildWidgets(node, style));
children.add(
TextSpan(
children: textWidgets,
style: const TextStyle(color: Colors.blue),
),
);
default:
children.addAll(textWidgets);
}
}

List<InlineSpan> _buildWidgets(XmlElement node, TextStyle style) {
List<InlineSpan> _buildWidgets(XmlElement node) {
final List<InlineSpan> children = [];
for (final child in node.children) {
if (child case XmlText(:final value)) {
if (value.trim().isEmpty) continue;
children.add(TextSpan(text: value));
} else if (child is XmlElement) {
_parseElements(child, children, style);
_parseElements(child, children);
} else {
print(child);
}
}
return children;
}
}

class ChapterElement extends MultiChildRenderObjectWidget {
final InlineSpan text;
final ElementRenderType renderType;
ChapterElement({
super.key,
required this.text,
this.renderType = ElementRenderType.block,
}) : super(children: WidgetSpan.extractFromInlineSpan(text, TextScaler.noScaling));

@override
ChapterElementRenderObject createRenderObject(BuildContext context) {
return ChapterElementRenderObject(text, textDirection: TextDirection.ltr);
}

@override
void updateRenderObject(BuildContext context, covariant ChapterElementRenderObject renderObject) {
// TODO: implement updateRenderObject
//renderObject.markNeedsPaint();
}
}

class TextNode extends TextSpan {
final ElementRenderType renderType;
const TextNode({super.text, super.style, this.renderType = ElementRenderType.block, super.children});
}

class ChapterElementRenderObject extends RenderParagraph {
ChapterElementRenderObject(
super.text, {
super.textDirection = TextDirection.ltr,
});
@override
void performLayout() {
// For non-block elements, perform default layout
super.performLayout();
}
}

enum ElementRenderType {
block,
inline,
}
56 changes: 25 additions & 31 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ description: Something I guess
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 0.5.1
version: 0.5.2

environment:
sdk: ">=3.2.0"
sdk: ">=3.4.0"

dependencies:
flutter:
sdk: flutter
sliver_tools:
path:
dio:
async:
graphql:
flex_color_scheme:
sliver_tools: ^0.2.12
path: ^1.9.0
dio: ^5.5.0+1
async: ^2.11.0
graphql: ^5.2.0-beta.8
flex_color_scheme: ^7.3.1
# For novels
epubx:
git:
url: https://github.com/femalemonkeyman/epubx
#path: /mnt/Storage/HomeStuff/Documents/epubx
html:
file_picker:
permission_handler:
html: ^0.15.4
file_picker: ^8.0.6
permission_handler: ^11.3.1
# Media kit
media_kit:
git:
Expand All @@ -43,20 +43,18 @@ dependencies:
url: https://github.com/media-kit/media-kit.git
ref: main
path: ./libs/universal/media_kit_libs_video
path_provider:
window_manager:
encrypt:
path_provider: ^2.1.3
window_manager: ^0.3.9
encrypt: ^5.0.3
isar: ^4.0.0-dev.14
isar_flutter_libs: ^4.0.0-dev.14
xml:
expandable_text:
string_similarity:
go_router:
extended_image:
collection:
expandable_page_view:
csslib:

xml: ^6.5.0
expandable_text: ^2.3.0
string_similarity: ^2.0.0
go_router: ^14.2.1
extended_image: ^8.2.1
expandable_page_view: ^1.0.17
csslib: ^1.0.0

#Model
tokuwari_models:
Expand All @@ -71,18 +69,14 @@ dependencies:
# url: https://github.com/femalemonkeyman/key

dependency_overrides:
graphql: ^5.2.0-beta.6
graphql: ^5.2.0-beta.8
screen_brightness: ">=1.0.1"

media_kit:
git:
url: https://github.com/media-kit/media-kit.git
ref: main
path: ./media_kit
media_kit_video:
git:
url: https://github.com/media-kit/media-kit.git
ref: main
path: ./media_kit_video
media_kit_native_event_loop:
git:
url: https://github.com/media-kit/media-kit.git
Expand All @@ -99,5 +93,5 @@ flutter:
# the material Icons class.
uses-material-design: true
dev_dependencies:
build_runner:
flutter_lints:
build_runner: ^2.4.11
flutter_lints: ^4.0.0

0 comments on commit f17dcc9

Please sign in to comment.