Skip to content

Commit

Permalink
hmtai api fix kinda
Browse files Browse the repository at this point in the history
  • Loading branch information
cranci1 committed Feb 27, 2024
1 parent 6c935e2 commit bf445a6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
Binary file not shown.
55 changes: 27 additions & 28 deletions AnimeGen/APIs/Hmtai.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import UIKit

extension ViewController {

func loadImagesFromHmtai() {
startLoadingIndicator()

let categories3: [String]
let endpointPrefix: String

if UserDefaults.standard.bool(forKey: "enableExplictiCont") {
categories3 = ["ass","anal","bdsm","classic","cum","creampie","manga","femdom","hentai","incest","masturbation","public","ero","orgy","elves","yuri","pantsu","pussy","glasses","cuckold","blowjob","boobjob","handjob","footjob","boobs","thighs","ahegao","uniform","gangbang","tentacles","gif","nsfwNeko","nsfwMobileWallpaper","zettaiRyouiki"]
categories3 = ["ass", "anal", "bdsm", "classic", "cum", "creampie", "manga", "femdom", "hentai", "incest", "masturbation", "public", "ero", "orgy", "elves", "yuri", "pantsu", "pussy", "glasses", "cuckold", "blowjob", "boobjob", "handjob", "footjob", "boobs", "thighs", "ahegao", "uniform", "gangbang", "tentacles", "gif", "nsfwNeko", "nsfwMobileWallpaper", "zettaiRyouiki"]
endpointPrefix = "https://hmtai.hatsunia.cfd/nsfw/"
} else {
categories3 = ["wave", "wink", "tea", "bonk", "punch", "poke", "bully", "pat", "kiss", "kick", "blush", "feed", "smug", "hug", "cuddle", "cry", "cringe", "slap", "five", "glomp", "happy", "hold", "nom", "smile", "throw", "lick", "bite", "dance", "boop", "sleep", "like", "kill", "tickle", "nosebleed", "threaten", "depression", "wolf_arts", "jahy_arts", "neko_arts", "coffee_arts", "wallpaper", "mobileWallpaper"]
Expand All @@ -36,7 +36,7 @@ extension ViewController {
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
DispatchQueue.main.async {
if let error = error {
print("Error: \(error)")
print("Error loading image data: \(error.localizedDescription)")
self.stopLoadingIndicator()
return
}
Expand All @@ -47,38 +47,37 @@ extension ViewController {
return
}

if let data = data, let jsonResponse = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let imageUrlString = jsonResponse["url"] as? String, let imageUrl = URL(string: imageUrlString) {
if let jsonResponse = try? JSONSerialization.jsonObject(with: data ?? Data(), options: []) as? [String: Any],
let imageUrlString = jsonResponse["url"] as? String,
let imageUrl = URL(string: imageUrlString) {
print("Image URL: \(imageUrlString)")

if let imageData = try? Data(contentsOf: imageUrl) {
if imageUrlString.lowercased().hasSuffix(".gif") {
if let animatedImage = UIImage.animatedImage(with: UIImage.gifData(data: imageData) ?? [], duration: 2.0) {
self.imageView.image = animatedImage
self.animateImageChange(with: animatedImage)
} else {
print("Failed to create animated image from GIF data.")
let imageDataTask = URLSession.shared.dataTask(with: imageUrl) { (imageData, _, imageError) in
DispatchQueue.main.async {
if let imageError = imageError {
print("Error loading image data: \(imageError.localizedDescription)")
self.stopLoadingIndicator()
return
}
} else {
if let newImage = UIImage(data: imageData) {

if let imageData = imageData, let newImage = UIImage(data: imageData) {
self.imageView.image = newImage
self.animateImageChange(with: newImage)

let category3 = randomCategory3
self.tagsLabel.isHidden = false
self.currentImageURL = imageUrlString
self.updateUIWithTags([category3])

self.stopLoadingIndicator()
} else {
print("Failed to load image data.")
print("Invalid image content or link issue.")
self.loadImagesFromHmtai()
}
}

let category3 = randomCategory3

self.tagsLabel.isHidden = false

self.currentImageURL = imageUrlString

self.updateUIWithTags([category3])

self.stopLoadingIndicator()
} else {
print("Failed to load image data.")
self.stopLoadingIndicator()
}

imageDataTask.resume()
} else {
print("Failed to parse JSON response or missing necessary data.")
self.stopLoadingIndicator()
Expand All @@ -88,5 +87,5 @@ extension ViewController {

task.resume()
}

}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ AnimeGen supports any iOS/iPadOS device running iOS 13+
| Waifu.im | SFW/NSFW | :white_check_mark: |
| Nekos.best | SFW | :white_check_mark: |
| Waifu.pics | SFW/NSFW | :white_check_mark: |
| Hmtai | SFW/NSFW | |
| Hmtai | SFW/NSFW | :warning: |
| Nekos api | SFW/NSFW | :white_check_mark: |
| Nekos.mod | SFW/NSFW | :white_check_mark: |

</table>

> [!Note]
> The working status is going to be update only if reported the api being down (not working)
> [!Important]
> The Hmtai api uses "cdn.discordapp.com/attachments" links, they are currently marked as "This content is no longer available.", so most of the images wont work.
## APIs Credits

Expand Down

0 comments on commit bf445a6

Please sign in to comment.