Skip to content

Commit

Permalink
Started Implementing mangas
Browse files Browse the repository at this point in the history
  • Loading branch information
K3vinb5 committed May 3, 2024
1 parent a7ac4d0 commit ecd3189
Show file tree
Hide file tree
Showing 18 changed files with 643 additions and 280 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
with:
files: build/windows/x64/runner/Release/Unyo-${{github.ref_name}}-windows.zip
- name: Build Msix
run: flutter pub run msix:create -y
run: flutter pub run msix:create --dontInstallCert
- name: Windows Msix Release
uses: softprops/action-gh-release@v1
env:
Expand Down
2 changes: 1 addition & 1 deletion debian/gui/unyo.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Exec=unyo
Icon=logo
Terminal=false
Type=Application
Categories=Multimedia;
Categories=AudioVideo;Video;
11 changes: 4 additions & 7 deletions lib/api/anilist_api.dart → lib/api/anilist_api_anime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:url_launcher/url_launcher.dart';
const String anilistEndpoint = "https://graphql.anilist.co";
const String anilistEndPointGetToken =
"https://anilist.co/api/v2/oauth/authorize?client_id=17550&response_type=token";
late String token;

Future<List<AnimeModel>> getAnimeModelListTrending(int page, int n, int attempt) async {
Map<String, dynamic> query = {
Expand Down Expand Up @@ -413,7 +412,7 @@ Future<List<String>> getUserNameAndId(String access_token) async {
];
}

Future<UserAnimeModel> getUserAnimeInfo(int mediaId, int attempt) async {
Future<UserMediaModel> getUserAnimeInfo(int mediaId, int attempt) async {
var url = Uri.parse(anilistEndpoint);
Map<String, dynamic> query = {
"query": "query{ Media(id: $mediaId){ mediaListEntry { score progress repeat priority status startedAt{day month year} completedAt{day month year} } } }",
Expand All @@ -433,7 +432,7 @@ Future<UserAnimeModel> getUserAnimeInfo(int mediaId, int attempt) async {
}
Map<String, dynamic> jsonResponse = json.decode(response.body);
if (jsonResponse["data"]["Media"]["mediaListEntry"] == null){
return UserAnimeModel(
return UserMediaModel(
score: 0,
progress: 0,
repeat: 0,
Expand All @@ -445,7 +444,7 @@ Future<UserAnimeModel> getUserAnimeInfo(int mediaId, int attempt) async {
}
Map<String, dynamic> mediaListEntry =
jsonResponse["data"]["Media"]["mediaListEntry"];
return UserAnimeModel(
return UserMediaModel(
score: mediaListEntry["score"],
progress: mediaListEntry["progress"],
repeat: mediaListEntry["repeat"],
Expand Down Expand Up @@ -534,6 +533,4 @@ Future<int> getAnimeCurrentEpisode(int mediaId) async{
return jsonResponse["data"]["AiringSchedule"]["episode"];
}

/*Future<Map<String,List<AnimeModel>>> getUserAnimeLists(){
//TODO
}*/
//MANGA SPECIFIC QUERIES
111 changes: 111 additions & 0 deletions lib/api/anilist_api_manga.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import 'dart:convert';
import 'dart:math';
import 'package:unyo/models/models.dart';
import 'package:unyo/screens/home_screen.dart';
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';

const String anilistEndpoint = "https://graphql.anilist.co";
const String anilistEndPointGetToken =
"https://anilist.co/api/v2/oauth/authorize?client_id=17550&response_type=token";

Future<List<AnimeModel>> getMangaModelListTrending(int page, int n, int attempt) async {
Map<String, dynamic> query = {
"query":
"query(\$page:Int = 1 \$id:Int \$type:MediaType \$isAdult:Boolean = false \$search:String \$format:[MediaFormat]\$status:MediaStatus \$countryOfOrigin:CountryCode \$source:MediaSource \$season:MediaSeason \$seasonYear:Int \$year:String \$onList:Boolean \$yearLesser:FuzzyDateInt \$yearGreater:FuzzyDateInt \$episodeLesser:Int \$episodeGreater:Int \$durationLesser:Int \$durationGreater:Int \$chapterLesser:Int \$chapterGreater:Int \$volumeLesser:Int \$volumeGreater:Int \$licensedBy:[Int]\$isLicensed:Boolean \$genres:[String]\$excludedGenres:[String]\$tags:[String]\$excludedTags:[String]\$minimumTagRank:Int \$sort:[MediaSort]=[POPULARITY_DESC,SCORE_DESC]){Page(page:\$page,perPage:$n){pageInfo{total perPage currentPage lastPage hasNextPage}media(id:\$id type:\$type season:\$season format_in:\$format status:\$status countryOfOrigin:\$countryOfOrigin source:\$source search:\$search onList:\$onList seasonYear:\$seasonYear startDate_like:\$year startDate_lesser:\$yearLesser startDate_greater:\$yearGreater episodes_lesser:\$episodeLesser episodes_greater:\$episodeGreater duration_lesser:\$durationLesser duration_greater:\$durationGreater chapters_lesser:\$chapterLesser chapters_greater:\$chapterGreater volumes_lesser:\$volumeLesser volumes_greater:\$volumeGreater licensedById_in:\$licensedBy isLicensed:\$isLicensed genre_in:\$genres genre_not_in:\$excludedGenres tag_in:\$tags tag_not_in:\$excludedTags minimumTagRank:\$minimumTagRank sort:\$sort isAdult:\$isAdult){id title{userPreferred}coverImage{extraLarge large color}startDate{year month day}endDate{year month day}bannerImage season seasonYear description type format status(version:2)episodes duration chapters volumes genres isAdult averageScore popularity nextAiringEpisode{airingAt timeUntilAiring episode}mediaListEntry{id status}studios(isMain:true){edges{isMain node{id name}}}}}}",
"variables": {
"page": page,
"type": "ANIME",
"sort": ["TRENDING_DESC", "POPULARITY_DESC"]
}
};
var url = Uri.parse(anilistEndpoint);
var response = await http.post(
url,
headers: {"Content-Type": "application/json"},
body: json.encode(query),
);
if (response.statusCode == 500) {
if(attempt < 5){
List<AnimeModel> returnList = await getAnimeModelListRecentlyReleased(page, n, attempt++);
return returnList;
}
return [];
} else {
List<dynamic> media = jsonDecode(response.body)["data"]["Page"]["media"];
List<AnimeModel> list = [];
for (int i = 0; i < n; i++) {
Map<String, dynamic> json = media[i];
list.add(AnimeModel(
id: json["id"],
title: json["title"]["userPreferred"],
coverImage: json["coverImage"]["large"],
bannerImage: json["bannerImage"],
startDate:
"${json["startDate"]["day"]}/${json["startDate"]["month"]}/${json["startDate"]["year"]}",
endDate:
"${json["endDate"]["day"]}/${json["endDate"]["month"]}/${json["endDate"]["year"]}",
type: json["type"],
description: json["description"],
status: json["status"],
averageScore: json["averageScore"],
episodes: json["episodes"],
duration: json["duration"],
format: json["format"],
));
}
return list;
}
}

Future<List<AnimeModel>> getAnimeModelListRecentlyReleased(
int page, int n, int attempt) async {
Map<String, dynamic> query = {
"query":
"query{ Page(page: $page, perPage: $n) { airingSchedules (sort: TIME_DESC, notYetAired: false) {episode media { id title { userPreferred } coverImage { large } bannerImage format startDate { year month day } endDate { year month day } type description status averageScore episodes duration}}}}"
};

var url = Uri.parse(anilistEndpoint);
var response = await http.post(
url,
headers: {"Content-Type": "application/json"},
body: json.encode(query),
);
if (response.statusCode == 500) {
if(attempt < 5){
List<AnimeModel> returnList = await getAnimeModelListRecentlyReleased(page, n, attempt++);
return returnList;
}
return [];
} else {
List<dynamic> media = jsonDecode(response.body)["data"]["Page"]["airingSchedules"];
List<AnimeModel> list = [];
for (int i = 0; i < media.length; i++) {
var currentMedia = media[i]["media"];
list.add(AnimeModel(
id: currentMedia["id"],
title: currentMedia["title"]["userPreferred"],
coverImage: currentMedia["coverImage"]["large"],
bannerImage: currentMedia["bannerImage"],
startDate: "${currentMedia["startDate"]["day"]}/${currentMedia["startDate"]["month"]}/${currentMedia["startDate"]["year"]}",
endDate: "${currentMedia["endDate"]["day"]}/${currentMedia["endDate"]["month"]}/${currentMedia["endDate"]["year"]}",
type: currentMedia["type"],
status: currentMedia["status"],
averageScore: currentMedia["averageScore"],
episodes: currentMedia["episodes"],
currentEpisode: media[i]["episode"],
duration: currentMedia["duration"],
description: currentMedia["description"],
format: currentMedia["format"],
));
}
for(int i = 0; i < list.length; i++){
for(int j = i + 1; j < list.length - 1; j++){
if(list[i].id == list[j].id){
list.removeAt(j);
}
}
}
return list;
}
}
38 changes: 38 additions & 0 deletions lib/models/manga_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class MangaModel {
MangaModel(
{required this.id,
required this.title,
required this.coverImage,
required this.bannerImage,
required this.startDate,
required this.endDate,
required this.type,
required this.status,
required this.averageScore,
required this.chapters,
required this.duration,
required this.description,
required this.format,
this.currentEpisode,
});

int id;
String? title;
String? coverImage;
String? bannerImage;
String? startDate;
String? endDate;
String? type;
String? status;
String? description;
String? format;
int? averageScore;
int? chapters;
int? currentEpisode;
int? duration;

@override
String toString() {
return "$id $coverImage";
}
}
4 changes: 2 additions & 2 deletions lib/models/user_anime_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class UserAnimeModel{
UserAnimeModel({
class UserMediaModel{
UserMediaModel({
required this.score,
required this.progress,
required this.repeat,
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/anime_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:unyo/api/anilist_api.dart';
import 'package:unyo/api/anilist_api_anime.dart';
import 'package:unyo/models/models.dart';
import 'package:unyo/screens/video_screen.dart';
import 'package:unyo/widgets/widgets.dart';
Expand All @@ -26,7 +26,7 @@ class AnimeDetailsScreen extends StatefulWidget {

class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
late VideoScreen videoScreen;
UserAnimeModel? userAnimeModel;
UserMediaModel? userAnimeModel;
List<String> searches = [];
List<String> searchesId = [];
late int currentSearch;
Expand Down Expand Up @@ -74,7 +74,7 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
}

void setUserAnimeModel() async {
UserAnimeModel newUserAnimeModel =
UserMediaModel newUserAnimeModel =
await getUserAnimeInfo(widget.currentAnime.id, 0);
setState(() {
userAnimeModel = newUserAnimeModel;
Expand Down
Loading

0 comments on commit ecd3189

Please sign in to comment.