Skip to content

Commit

Permalink
Fully updated to work with Derpibooru API V2
Browse files Browse the repository at this point in the history
  • Loading branch information
Atulin committed Nov 5, 2020
1 parent 7441358 commit ad114c8
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 19 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Derpibooru client made with Flutter

## Changelog

* **05.11.2020**
* Updated to work with the new Derpibooru API

* **17.12.2019**
* Updated to use AndroidX
* Updated Flutter to 1.12.13
Expand Down
2 changes: 1 addition & 1 deletion lib/API/v1/ImageList.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:chryssibooru/API/v1/API.dart';
import 'package:chryssibooru/API/v2/API.dart';
import 'package:chryssibooru/Connect.dart';
import 'package:flutter/foundation.dart';

Expand Down
35 changes: 32 additions & 3 deletions lib/API/v2/API.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Derpi {
String viewUrl;
String sourceUrl;
DateTime updatedAt;
List<String> tags;
List<Tag> tags;
int downvotes;
int commentCount;
Representations representations;
Expand Down Expand Up @@ -131,7 +131,7 @@ class Derpi {
viewUrl: json["view_url"],
sourceUrl: json["source_url"] == null ? null : json["source_url"],
updatedAt: DateTime.parse(json["updated_at"]),
tags: List<String>.from(json["tags"].map((x) => x)),
tags: Tag.parse(List<String>.from(json["tags"])),
downvotes: json["downvotes"],
commentCount: json["comment_count"],
representations: Representations.fromJson(json["representations"]),
Expand Down Expand Up @@ -233,7 +233,7 @@ class Intensities {
};
}

enum MimeType { IMAGE_PNG, IMAGE_JPEG }
enum MimeType { IMAGE_PNG, IMAGE_JPEG, VIDEO_WEBM, VIDEO_MP4 }

final mimeTypeValues = EnumValues({
"image/jpeg": MimeType.IMAGE_JPEG,
Expand Down Expand Up @@ -301,3 +301,32 @@ class EnumValues<T> {
return reverseMap;
}
}

enum TagType { ARTIST, SPOILER, OC }

final tagTypeValues = new EnumValues({
"artist": TagType.ARTIST,
"spoiler": TagType.SPOILER,
"oc": TagType.OC
});

class Tag {
TagType type;
String label;

Tag(String tag) {
var splitTag = tag.split(':');
if (splitTag.length >= 2) {
this.type = tagTypeValues.map[splitTag[0]];
this.label = tag;
} else {
this.label = tag;
}
}

static List<Tag> parse(List<String> tags) {
List<Tag> outTags = new List<Tag>();
outTags = tags.map((x) => new Tag(x)).toList();
return outTags;
}
}
2 changes: 1 addition & 1 deletion lib/API/v2/ImageList.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:chryssibooru/API/v1/API.dart';
import 'package:chryssibooru/API/v2/API.dart';
import 'package:chryssibooru/Connect.dart';
import 'package:flutter/foundation.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/Connect.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'dart:convert';

import 'package:chryssibooru/API/v1/API.dart';
import 'package:chryssibooru/API/v2/API.dart';
import 'package:http/http.dart' as http;

Future<List<Derpi>> fetchDerpi(String url) async {
final response = await http.get(url);

if (response.statusCode == 200) {
Iterable i = json.decode(response.body)['search'];
Iterable i = json.decode(response.body)['images'];
if (i.length > 0) {
List<Derpi> derpis = i.map((dynamic) => Derpi.fromJson(dynamic)).toList();
return derpis;
Expand Down
4 changes: 2 additions & 2 deletions lib/DerpisRepo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:chryssibooru/API/v1/API.dart';
import 'package:chryssibooru/API/v1/ImageList.dart';
import 'package:chryssibooru/API/v2/API.dart';
import 'package:chryssibooru/API/v2/ImageList.dart';
import 'package:flutter/material.dart';

class DerpisRepo extends ChangeNotifier {
Expand Down
2 changes: 1 addition & 1 deletion lib/Elements/FavouritesModal.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:chryssibooru/API/v1/API.dart';
import 'package:chryssibooru/API/v2/API.dart';
import 'package:chryssibooru/DerpisRepo.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down
3 changes: 1 addition & 2 deletions lib/Elements/HistoryModal.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:chryssibooru/API/v1/API.dart';
import 'package:chryssibooru/API/v2/API.dart';
import 'package:chryssibooru/DerpisRepo.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

class HistoryModal extends StatefulWidget {
HistoryModal({@required this.repo});
Expand Down
4 changes: 2 additions & 2 deletions lib/Views/HomePage.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:chryssibooru/API/v1/API.dart';
import 'package:chryssibooru/API/v2/API.dart';
import 'package:chryssibooru/DerpisRepo.dart';
import 'package:chryssibooru/Elements/FavouritesModal.dart';
import 'package:chryssibooru/Elements/FilterSheet.dart';
Expand Down Expand Up @@ -196,7 +196,7 @@ class HomePageState extends State<HomePage> {
child: ClipRRect(
borderRadius:new BorderRadius.all(Radius.circular(10.0)),
child: (){
String url = "https:" + repo.derpis[index].representations.thumb;
String url = repo.derpis[index].representations.thumb;
if(repo.derpis[index].mimeType == MimeType.VIDEO_WEBM){
List<String> parts = url.split('.');
parts[parts.length-1] = 'gif';
Expand Down
8 changes: 4 additions & 4 deletions lib/Views/ImageViewer.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/services.dart';
import 'package:flutter_advanced_networkimage/provider.dart';
import 'package:flutter_advanced_networkimage/transition.dart';
import 'package:chryssibooru/API/v1/API.dart';
import 'package:chryssibooru/API/v2/API.dart';
import 'package:chryssibooru/DerpisRepo.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/zoomable.dart';
Expand Down Expand Up @@ -62,7 +62,7 @@ class ImageViewerState extends State<ImageViewer> {
repo = Provider.of<DerpisRepo>(context);

_videoController?.dispose();
_videoController = VideoPlayerController.network('https:'+repo.derpis[_id].representations.medium)
_videoController = VideoPlayerController.network(repo.derpis[_id].representations.medium)
..addListener(() {
setState(() {
if (_videoController.value.duration != null)
Expand Down Expand Up @@ -97,7 +97,7 @@ class ImageViewerState extends State<ImageViewer> {
if (_pageController.page.round() != _currentPage) {
if (repo.derpis[_pageController.page.round()].mimeType == MimeType.VIDEO_WEBM) {
_videoController?.dispose();
_videoController = VideoPlayerController.network('https:'+repo.derpis[_pageController.page.round()].representations.medium)
_videoController = VideoPlayerController.network(repo.derpis[_pageController.page.round()].representations.medium)
..addListener(() {
setState(() {
_videoProgressPercent = (_videoController.value.position.inMilliseconds / _videoController.value.duration.inMilliseconds).clamp(0.0, 1.0);
Expand Down Expand Up @@ -154,7 +154,7 @@ class ImageViewerState extends State<ImageViewer> {
child: Container(
child: TransitionToImage(
image: AdvancedNetworkImage(
"https:" + getImageOfQuality(_quality, repo, index),
getImageOfQuality(_quality, repo, index),
useDiskCache: true,
cacheRule: CacheRule(maxAge: const Duration(days: 7))
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Derpibooru client made with Flutter
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.5.2 #+1
version: 1.6.0 #+1

environment:
sdk: ">=2.2.2 <3.0.0"
Expand Down

0 comments on commit ad114c8

Please sign in to comment.