diff --git a/manga/src/all/mangadex/mangadex-v0.0.45.dart b/manga/src/all/mangadex/mangadex-v0.0.45.dart index 0e686ef8..172054d1 100644 --- a/manga/src/all/mangadex/mangadex-v0.0.45.dart +++ b/manga/src/all/mangadex/mangadex-v0.0.45.dart @@ -8,7 +8,7 @@ class MangaDex extends MProvider { Future getPopular(MSource source, int page) async { page = (20 * (page - 1)); final url = - "https://api.mangadex.org/manga?limit=20&offset=$page&availableTranslatedLanguage[]=en&includes[]=cover_art${getMDXContentRating()}&order[followedCount]=desc"; + "https://api.mangadex.org/manga?limit=20&offset=$page&availableTranslatedLanguage[]=${source.lang}&includes[]=cover_art${getMDXContentRating()}&order[followedCount]=desc"; final datas = {"url": url}; final res = await http('GET', json.encode(datas)); return mangaRes(res, source); @@ -37,8 +37,107 @@ class MangaDex extends MProvider { @override Future search( MSource source, String query, int page, FilterList filterList) async { - final url = - "https://api.mangadex.org/manga?includes[]=cover_art&offset=0&limit=20&title=$query${getMDXContentRating()}&order[followedCount]=desc&availableTranslatedLanguage[]=${source.lang}"; + page = (20 * (page - 1)); + final filters = filterList.filters; + String url = ""; + + url = + "https://api.mangadex.org/manga?includes[]=cover_art&offset=$page&limit=20&title=$query"; + for (var filter in filters) { + if (filter.type == "HasAvailableChaptersFilter") { + if (filter.state) { + url += "${ll(url)}hasAvailableChapters=true"; + url += "${ll(url)}availableTranslatedLanguage[]=${source.lang}"; + } + } else if (filter.type == "OriginalLanguageList") { + final langs = (filter.state as List).where((e) => e.state).toList(); + if (langs.isNotEmpty) { + for (var ln in langs) { + url += "${ll(url)}${ln.value}"; + } + } + } else if (filter.type == "ContentRatingList") { + final langs = (filter.state as List).where((e) => e.state).toList(); + if (langs.isNotEmpty) { + for (var ln in langs) { + url += "${ll(url)}${ln.value}"; + } + } + } else if (filter.type == "DemographicList") { + final langs = (filter.state as List).where((e) => e.state).toList(); + if (langs.isNotEmpty) { + for (var ln in langs) { + url += "${ll(url)}${ln.value}"; + } + } + } else if (filter.type == "StatusList") { + final langs = (filter.state as List).where((e) => e.state).toList(); + if (langs.isNotEmpty) { + for (var ln in langs) { + url += "${ll(url)}${ln.value}"; + } + } + } else if (filter.type == "SortFilter") { + final value = filter.state.ascending ? "asc" : "desc"; + url += + "${ll(url)}order[${filter.values[filter.state.index].value}]=$value"; + } else if (filter.type == "TagsFilter") { + for (var tag in filter.state) { + url += "${ll(url)}${tag.values[tag.state].value}"; + } + } else if (filter.type == "FormatFilter") { + final included = (filter.state as List) + .where((e) => e.state == 1 ? true : false) + .toList(); + final excluded = (filter.state as List) + .where((e) => e.state == 2 ? true : false) + .toList(); + if (included.isNotEmpty) { + for (var val in included) { + url += "${ll(url)}includedTags[]=${val.value}"; + } + } + if (excluded.isNotEmpty) { + for (var val in excluded) { + url += "${ll(url)}excludedTags[]=${val.value}"; + } + } + } else if (filter.type == "GenreFilter") { + final included = (filter.state as List) + .where((e) => e.state == 1 ? true : false) + .toList(); + final excluded = (filter.state as List) + .where((e) => e.state == 2 ? true : false) + .toList(); + if (included.isNotEmpty) { + for (var val in included) { + url += "${ll(url)}includedTags[]=${val.value}"; + } + } + if (excluded.isNotEmpty) { + for (var val in excluded) { + url += "${ll(url)}excludedTags[]=${val.value}"; + } + } + } else if (filter.type == "ThemeFilter") { + final included = (filter.state as List) + .where((e) => e.state == 1 ? true : false) + .toList(); + final excluded = (filter.state as List) + .where((e) => e.state == 2 ? true : false) + .toList(); + if (included.isNotEmpty) { + for (var val in included) { + url += "${ll(url)}includedTags[]=${val.value}"; + } + } + if (excluded.isNotEmpty) { + for (var val in excluded) { + url += "${ll(url)}excludedTags[]=${val.value}"; + } + } + } + } final res = await http('GET', json.encode({"url": url})); return mangaRes(res, source); @@ -267,6 +366,155 @@ class MangaDex extends MProvider { } return coverFileName; } + + List getFilterList() { + return [ + CheckBoxFilter( + "Has available chapters", "", "HasAvailableChaptersFilter"), + GroupFilter("OriginalLanguageList", "Original language", [ + CheckBoxFilter("Japanese (Manga)", "originalLanguage[]=ja"), + CheckBoxFilter("Chinese (Manhua)", + "originalLanguage[]=zh&originalLanguage[]=zh-hk"), + CheckBoxFilter("Korean (Manhwa)", "originalLanguage[]=ko"), + ]), + GroupFilter("ContentRatingList", "Content rating", [ + CheckBoxFilter("Safe", "contentRating[]=safe", state: true), + CheckBoxFilter("Suggestive", "contentRating[]=suggestive", state: true), + CheckBoxFilter("Erotica", "contentRating[]=erotica"), + CheckBoxFilter("Pornographic", "contentRating[]=pornographic"), + ]), + GroupFilter("DemographicList", "Publication demographic", [ + CheckBoxFilter("None", "publicationDemographic[]=none"), + CheckBoxFilter("Shounen", "publicationDemographic[]=shounen"), + CheckBoxFilter("Shoujo", "publicationDemographic[]=shoujo"), + CheckBoxFilter("Seinen", "publicationDemographic[]=seinen"), + CheckBoxFilter("Josei", "publicationDemographic[]=josei"), + ]), + GroupFilter("StatusList", "Status", [ + CheckBoxFilter("Ongoing", "status[]=ongoing"), + CheckBoxFilter("Completed", "status[]=completed"), + CheckBoxFilter("Hiatus", "status[]=hiatus"), + CheckBoxFilter("Cancelled", "status[]=cancelled"), + ]), + SortFilter("SortFilter", "Sort", SortState(5, false), [ + SelectFilterOption("Alphabetic", "title"), + SelectFilterOption("Chapter uploded at", "latestUploadedChapter"), + SelectFilterOption("Number of follows", "followedCount"), + SelectFilterOption("Content created at", "createdAt"), + SelectFilterOption("Content info updated at", "updatedAt"), + SelectFilterOption("Relevance", "relevance"), + SelectFilterOption("Year", "year"), + SelectFilterOption("Rating", "rating"), + ]), + GroupFilter("TagsFilter", "Tags mode", [ + SelectFilter("TagInclusionMode", "Included tags mode", 0, [ + SelectFilterOption("AND", "includedTagsMode=AND"), + SelectFilterOption("OR", "includedTagsMode=OR"), + ]), + SelectFilter("TagExclusionMode", "Excluded tags mode", 1, [ + SelectFilterOption("AND", "excludedTagsMode=AND"), + SelectFilterOption("OR", "excludedTagsMode=OR"), + ]), + ]), + GroupFilter("ContentsFilter", "Content", [ + TriStateFilter("Gore", "b29d6a3d-1569-4e7a-8caf-7557bc92cd5d"), + TriStateFilter( + "Sexual Violence", "97893a4c-12af-4dac-b6be-0dffb353568e"), + ]), + GroupFilter("FormatFilter", "Format", [ + TriStateFilter("4-Koma", "b11fda93-8f1d-4bef-b2ed-8803d3733170"), + TriStateFilter("Adaptation", "f4122d1c-3b44-44d0-9936-ff7502c39ad3"), + TriStateFilter("Anthology", "51d83883-4103-437c-b4b1-731cb73d786c"), + TriStateFilter("Award Winning", "0a39b5a1-b235-4886-a747-1d05d216532d"), + TriStateFilter("Doujinshi", "b13b2a48-c720-44a9-9c77-39c9979373fb"), + TriStateFilter("Fan Colored", "7b2ce280-79ef-4c09-9b58-12b7c23a9b78"), + TriStateFilter("Full Color", "f5ba408b-0e7a-484d-8d49-4e9125ac96de"), + TriStateFilter("Long Strip", "3e2b8dae-350e-4ab8-a8ce-016e844b9f0d"), + TriStateFilter( + "Official Colored", "320831a8-4026-470b-94f6-8353740e6f04"), + TriStateFilter("Oneshot", "0234a31e-a729-4e28-9d6a-3f87c4966b9e"), + TriStateFilter("User Created", "891cf039-b895-47f0-9229-bef4c96eccd4"), + TriStateFilter("Web Comic", "e197df38-d0e7-43b5-9b09-2842d0c326dd"), + ]), + GroupFilter("GenreFilter", "Genre", [ + TriStateFilter("Action", "391b0423-d847-456f-aff0-8b0cfc03066b"), + TriStateFilter("Adventure", "87cc87cd-a395-47af-b27a-93258283bbc6"), + TriStateFilter("Boys' Love", "5920b825-4181-4a17-beeb-9918b0ff7a30"), + TriStateFilter("Comedy", "4d32cc48-9f00-4cca-9b5a-a839f0764984"), + TriStateFilter("Crime", "5ca48985-9a9d-4bd8-be29-80dc0303db72"), + TriStateFilter("Drama", "b9af3a63-f058-46de-a9a0-e0c13906197a"), + TriStateFilter("Fantasy", "cdc58593-87dd-415e-bbc0-2ec27bf404cc"), + TriStateFilter("Girls' Love", "a3c67850-4684-404e-9b7f-c69850ee5da6"), + TriStateFilter("Historical", "33771934-028e-4cb3-8744-691e866a923e"), + TriStateFilter("Horror", "cdad7e68-1419-41dd-bdce-27753074a640"), + TriStateFilter("Isekai", "ace04997-f6bd-436e-b261-779182193d3d"), + TriStateFilter("Magical Girls", "81c836c9-914a-4eca-981a-560dad663e73"), + TriStateFilter("Mecha", "50880a9d-5440-4732-9afb-8f457127e836"), + TriStateFilter("Medical", "c8cbe35b-1b2b-4a3f-9c37-db84c4514856"), + TriStateFilter("Mystery", "ee968100-4191-4968-93d3-f82d72be7e46"), + TriStateFilter("Philosophical", "b1e97889-25b4-4258-b28b-cd7f4d28ea9b"), + TriStateFilter("Psychological", "3b60b75c-a2d7-4860-ab56-05f391bb889c"), + TriStateFilter("Romance", "423e2eae-a7a2-4a8b-ac03-a8351462d71d"), + TriStateFilter("Sci-Fi", "256c8bd9-4904-4360-bf4f-508a76d67183"), + TriStateFilter("Slice of Life", "e5301a23-ebd9-49dd-a0cb-2add944c7fe9"), + TriStateFilter("Sports", "69964a64-2f90-4d33-beeb-f3ed2875eb4c"), + TriStateFilter("Superhero", "7064a261-a137-4d3a-8848-2d385de3a99c"), + TriStateFilter("Thriller", "07251805-a27e-4d59-b488-f0bfbec15168"), + TriStateFilter("Tragedy", "f8f62932-27da-4fe4-8ee1-6779a8c5edba"), + TriStateFilter("Wuxia", "acc803a4-c95a-4c22-86fc-eb6b582d82a2"), + ]), + GroupFilter("ThemeFilter", "Theme", [ + TriStateFilter("Aliens", "e64f6742-c834-471d-8d72-dd51fc02b835"), + TriStateFilter("Animals", "3de8c75d-8ee3-48ff-98ee-e20a65c86451"), + TriStateFilter("Cooking", "ea2bc92d-1c26-4930-9b7c-d5c0dc1b6869"), + TriStateFilter("Crossdressing", "9ab53f92-3eed-4e9b-903a-917c86035ee3"), + TriStateFilter("Delinquents", "da2d50ca-3018-4cc0-ac7a-6b7d472a29ea"), + TriStateFilter("Demons", "39730448-9a5f-48a2-85b0-a70db87b1233"), + TriStateFilter("Genderswap", "2bd2e8d0-f146-434a-9b51-fc9ff2c5fe6a"), + TriStateFilter("Ghosts", "3bb26d85-09d5-4d2e-880c-c34b974339e9"), + TriStateFilter("Gyaru", "fad12b5e-68ba-460e-b933-9ae8318f5b65"), + TriStateFilter("Harem", "aafb99c1-7f60-43fa-b75f-fc9502ce29c7"), + TriStateFilter("Incest", "5bd0e105-4481-44ca-b6e7-7544da56b1a3"), + TriStateFilter("Loli", "2d1f5d56-a1e5-4d0d-a961-2193588b08ec"), + TriStateFilter("Mafia", "85daba54-a71c-4554-8a28-9901a8b0afad"), + TriStateFilter("Magic", "a1f53773-c69a-4ce5-8cab-fffcd90b1565"), + TriStateFilter("Martial Arts", "799c202e-7daa-44eb-9cf7-8a3c0441531e"), + TriStateFilter("Military", "ac72833b-c4e9-4878-b9db-6c8a4a99444a"), + TriStateFilter("Monster Girls", "dd1f77c5-dea9-4e2b-97ae-224af09caf99"), + TriStateFilter("Monsters", "36fd93ea-e8b8-445e-b836-358f02b3d33d"), + TriStateFilter("Music", "f42fbf9e-188a-447b-9fdc-f19dc1e4d685"), + TriStateFilter("Ninja", "489dd859-9b61-4c37-af75-5b18e88daafc"), + TriStateFilter( + "Office Workers", "92d6d951-ca5e-429c-ac78-451071cbf064"), + TriStateFilter("Police", "df33b754-73a3-4c54-80e6-1a74a8058539"), + TriStateFilter( + "Post-Apocalyptic", "9467335a-1b83-4497-9231-765337a00b96"), + TriStateFilter("Reincarnation", "0bc90acb-ccc1-44ca-a34a-b9f3a73259d0"), + TriStateFilter("Reverse Harem", "65761a2a-415e-47f3-bef2-a9dababba7a6"), + TriStateFilter("Samurai", "81183756-1453-4c81-aa9e-f6e1b63be016"), + TriStateFilter("School Life", "caaa44eb-cd40-4177-b930-79d3ef2afe87"), + TriStateFilter("Shota", "ddefd648-5140-4e5f-ba18-4eca4071d19b"), + TriStateFilter("Supernatural", "eabc5b4c-6aff-42f3-b657-3e90cbd00b75"), + TriStateFilter("Survival", "5fff9cde-849c-4d78-aab0-0d52b2ee1d25"), + TriStateFilter("Time Travel", "292e862b-2d17-4062-90a2-0356caa4ae27"), + TriStateFilter( + "Traditional Games", "31932a7e-5b8e-49a6-9f12-2afa39dc544c"), + TriStateFilter("Vampires", "d7d1730f-6eb0-4ba6-9437-602cac38664c"), + TriStateFilter("Video Games", "9438db5a-7e2a-4ac0-b39e-e0d95a34b8a8"), + TriStateFilter("Villainess", "d14322ac-4d6f-4e9b-afd9-629d5f4d8a41"), + TriStateFilter( + "Virtual Reality", "8c86611e-fab7-4986-9dec-d1a2f44acdd5"), + TriStateFilter("Zombies", "631ef465-9aba-4afb-b0fc-ea10efe274a8"), + ]), + ]; + } + + String ll(String url) { + if (url.contains("?")) { + return "&"; + } + return "?"; + } } MangaDex main() {