Skip to content

Commit

Permalink
Revert "test build cuz my pc is not building"
Browse files Browse the repository at this point in the history
This reverts commit e5e295d.
  • Loading branch information
cranci1 committed May 21, 2024
1 parent e5e295d commit 96e6e20
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 203 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion AnimeGen/APIs Requests/Hmtai/HmtaiSender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension ViewController {
let categories3: [String]
let endpointPrefix: String

if UserDefaults.standard.bool(forKey: "enableExplicitContent") {
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"]
endpointPrefix = "https://hmtai.hatsunia.cfd/nsfw/"
} else {
Expand Down
2 changes: 1 addition & 1 deletion AnimeGen/APIs Requests/kyoko.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension ViewController {
let categories: [String]
let endpointPrefix: String

if UserDefaults.standard.bool(forKey: "enableExplicitContent") {
if UserDefaults.standard.bool(forKey: "enableExplictiCont") {
categories = ["waifu", "neko", "trap", "blowjob"]
endpointPrefix = "https://waifu.rei.my.id/nsfw/"
} else {
Expand Down
2 changes: 1 addition & 1 deletion AnimeGen/APIs Requests/n-sfw.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension ViewController {
let categories: [String]
let endpointPrefix: String

if UserDefaults.standard.bool(forKey: "enableExplicitContent") {
if UserDefaults.standard.bool(forKey: "enableExplictiCont") {
categories = ["anal","ass", "blowjob", "breeding", "buttplug", "cages", "ecchi", "feet", "fo", "furry", "gif", "hentai", "legs", "masturbation", "milf", "muscle", "neko", "paizuri", "petgirls", "pierced", "selfie", "smothering", "socks", "trap", "vagina", "yaoi", "yuri"]
endpointPrefix = "https://api.n-sfw.com/nsfw/"
} else {
Expand Down
2 changes: 1 addition & 1 deletion AnimeGen/APIs Requests/nekosapi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension ViewController {

var ratings: [String] = ["safe"]

if UserDefaults.standard.bool(forKey: "enableExplicitContent") {
if UserDefaults.standard.bool(forKey: "enableExplictiCont") {
ratings.append("explicit")
}

Expand Down
2 changes: 1 addition & 1 deletion AnimeGen/APIs Requests/nekosbot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension ViewController {
let categories: [String]
let endpointPrefix: String

if UserDefaults.standard.bool(forKey: "enableExplicitContent") {
if UserDefaults.standard.bool(forKey: "enableExplictiCont") {
categories = ["hentai", "hkitsune", "hanal", "hthigh", "hboobs", "yaoi"]
endpointPrefix = "https://nekobot.xyz/api/image?type="
} else {
Expand Down
112 changes: 43 additions & 69 deletions AnimeGen/APIs Requests/pic-re.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,84 +7,61 @@

import UIKit

class ImageCache {
private var cache: NSCache<NSURL, UIImage> = NSCache()

func image(for url: NSURL) -> UIImage? {
return cache.object(forKey: url)
}

func insertImage(_ image: UIImage?, for url: NSURL) {
guard let image = image else { return }
cache.setObject(image, forKey: url)
}
}

extension ViewController {

private var imageCache: ImageCache {
return ImageCache()
}

func loadImageFromPicRe() {
startLoadingIndicator()

guard let url = URL(string: "https://pic.re/image") else {
print("Invalid URL")
stopLoadingIndicator()
return
}

let startTime = Date()
let startTime = DispatchTime.now()

DispatchQueue.global().async {
self.fetchImageData(from: url, startTime: startTime)
}
}

private func fetchImageData(from url: URL, startTime: Date) {
if let cachedImage = imageCache.image(for: url as NSURL) {
handleImageLoadingCompletion(with: cachedImage, tags: [], imageUrlString: url.absoluteString, startTime: startTime)
return
}

var request = URLRequest(url: url)
request.httpMethod = "GET"

URLSession.shared.dataTask(with: request) { [weak self] (data, response, error) in
guard let self = self else { return }

if let error = error {
self.handleError("Error: \(error)")
guard let url = URL(string: "https://pic.re/image") else {
print("Invalid URL")
self.stopLoadingIndicator()
return
}

guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200,
let imageTagsString = httpResponse.allHeaderFields["image_tags"] as? String,
let imageUrlString = httpResponse.allHeaderFields["image_source"] as? String,
let data = data, let newImage = UIImage(data: data) else {
self.handleError("Invalid HTTP response or data")
return
}

self.imageCache.insertImage(newImage, for: url as NSURL)

let tags = imageTagsString.components(separatedBy: ",")

DispatchQueue.main.async {
self.handleImageLoadingCompletion(with: newImage, tags: tags, imageUrlString: imageUrlString, startTime: startTime)
}
}.resume()
}

private func handleError(_ message: String) {
print(message)
DispatchQueue.main.async {
self.stopLoadingIndicator()

var request = URLRequest(url: url)
request.httpMethod = "GET"

URLSession.shared.dataTask(with: request) { [weak self] (data, response, error) in
guard let self = self else { return }

if let error = error {
print("Error: \(error)")
self.stopLoadingIndicator()
return
}

guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
print("Invalid HTTP response")
self.stopLoadingIndicator()
return
}

guard let data = data,
let imageTagsString = httpResponse.allHeaderFields["image_tags"] as? String,
let imageUrlString = httpResponse.allHeaderFields["image_source"] as? String,
let newImage = UIImage(data: data) else {
print("Invalid image data or missing response headers")
self.stopLoadingIndicator()
return
}

let tags = imageTagsString.components(separatedBy: ",")

DispatchQueue.main.async {
self.handleImageLoadingCompletion(with: newImage, tags: tags, imageUrlString: imageUrlString)

let endTime = DispatchTime.now()
let executionTime = endTime.uptimeNanoseconds - startTime.uptimeNanoseconds
print("Execution time: \(Double(executionTime) / 1_000_000_000) seconds")
}
}.resume()
}
}

private func handleImageLoadingCompletion(with newImage: UIImage, tags: [String], imageUrlString: String, startTime: Date) {
private func handleImageLoadingCompletion(with newImage: UIImage, tags: [String], imageUrlString: String) {
addImageToHistory(image: newImage, tags: tags)
currentImageURL = imageUrlString
updateUIWithTags(tags)
Expand All @@ -94,8 +71,5 @@ extension ViewController {
animateImageChange(with: newImage)
stopLoadingIndicator()
incrementCounter()

let executionTime = Date().timeIntervalSince(startTime)
print("Execution time: \(executionTime) seconds")
}
}
2 changes: 1 addition & 1 deletion AnimeGen/APIs Requests/purr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension ViewController {
let categories: [String]
let endpointPrefix: String

if UserDefaults.standard.bool(forKey: "enableExplicitContent") {
if UserDefaults.standard.bool(forKey: "enableExplictiCont") {
categories = ["anal/gif", "blowjob/gif", "cum/gif", "fuck/gif", "neko/gif", "pussylick/gif", "solo/gif", "solo_male/gif", "threesome_fff/gif", "threesome_ffm/gif", "threesome_mmf/gif", "yuri/gif", "neko/img"]
endpointPrefix = "https://purrbot.site/api/img/nsfw/"
} else {
Expand Down
2 changes: 1 addition & 1 deletion AnimeGen/APIs Requests/waifu-im.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension ViewController {
func loadImageFromWaifuIm() {
startLoadingIndicator()

let isNSFW = UserDefaults.standard.bool(forKey: "enableExplicitContent")
let isNSFW = UserDefaults.standard.bool(forKey: "enableExplictiCont")
let apiEndpoint = "https://api.waifu.im/search"

guard var components = URLComponents(string: apiEndpoint) else {
Expand Down
2 changes: 1 addition & 1 deletion AnimeGen/APIs Requests/waifu-it.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension ViewController {
let categories: [String]
let endpointPrefix: String = "https://waifu.it/api/v4/"

if UserDefaults.standard.bool(forKey: "enableExplicitContent") {
if UserDefaults.standard.bool(forKey: "enableExplictiCont") {
categories = ["angry", "baka", "bite", "blush", "bonk", "bored", "bully", "bye", "chase", "cheer", "cringe", "cry", "dab", "dance", "die", "disgust", "facepalm", "feed", "glomp", "happy", "hi", "highfive", "hold", "hug", "kick", "kill", "kiss", "laugh", "lick", "love", "lurk", "midfing", "nervous", "nom", "nope", "nuzzle", "panic", "pat", "peck", "poke", "pout", "punch", "run", "sad", "shoot", "shrug", "sip", "slap", "sleepy", "smile", "smug", "stab", "stare", "suicide", "tease", "think", "thumbsup", "tickle", "triggered", "wag", "wave", "wink", "yes"]
} else {
categories = ["angry", "baka", "bite", "blush", "bonk", "bored", "bye", "chase", "cheer", "cringe", "cry", "cuddle", "dab", "dance", "disgust", "facepalm", "feed", "glomp", "happy", "hi", "highfive", "hold", "hug", "kick", "kiss", "laugh", "lurk", "nervous", "nom", "nope", "nuzzle", "panic", "pat", "peck", "poke", "pout", "run", "sad", "shrug", "sip", "slap", "sleepy", "smile", "smug", "stare", "tease", "think", "thumbsup", "tickle", "wag", "wave", "wink", "yes"]
Expand Down
72 changes: 29 additions & 43 deletions AnimeGen/APIs Requests/waifu-pics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension ViewController {
let categories: [String]
let endpointPrefix: String

if UserDefaults.standard.bool(forKey: "enableExplicitContent") {
if UserDefaults.standard.bool(forKey: "enableExplictiCont") {
categories = ["waifu", "neko", "trap", "blowjob"]
endpointPrefix = "https://api.waifu.pics/nsfw/"
} else {
Expand All @@ -24,6 +24,7 @@ extension ViewController {
}

let randomCategory = categories.randomElement() ?? "waifu"

let apiEndpoint = "\(endpointPrefix)\(randomCategory)"

guard let url = URL(string: apiEndpoint) else {
Expand All @@ -32,42 +33,36 @@ extension ViewController {
return
}

let startTime = Date()

URLSession.shared.dataTask(with: url) { [weak self] (data, response, error) in
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
DispatchQueue.main.async {
guard let self = self else { return }

if let error = error {
self.handleError("Error: \(error)")
print("Error: \(error)")
self.stopLoadingIndicator()
return
}

guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200,
let data = data,
let jsonResponse = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let imageUrlString = jsonResponse["url"] as? String else {
self.handleError("Invalid HTTP response or data")
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
print("Invalid HTTP response")
self.stopLoadingIndicator()
return
}

self.loadImage(with: imageUrlString, tags: [randomCategory], startTime: startTime)
if let data = data, let jsonResponse = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let imageUrlString = jsonResponse["url"] as? String {
self.loadImage(with: imageUrlString, tags: [randomCategory])
} else {
print("Failed to parse JSON response or missing necessary data.")
self.stopLoadingIndicator()
}
}
}.resume()
}

task.resume()
}

private var imageCache: ImageCache {
return ImageCache()
}

private func loadImage(with imageUrlString: String, tags: [String], startTime: Date) {
private func loadImage(with imageUrlString: String, tags: [String]) {
guard let imageUrl = URL(string: imageUrlString) else {
handleError("Invalid image URL")
return
}

if let cachedImage = imageCache.image(for: imageUrl as NSURL) {
handleImageLoadingCompletion(with: cachedImage, tags: tags, imageUrlString: imageUrlString, startTime: startTime)
print("Invalid image URL")
stopLoadingIndicator()
return
}

Expand All @@ -76,34 +71,28 @@ extension ViewController {
DispatchQueue.main.async {
if imageUrlString.lowercased().hasSuffix(".gif") {
if let animatedImage = UIImage.animatedImage(with: UIImage.gifData(data: imageData) ?? [], duration: 1.0) {
self.imageCache.insertImage(animatedImage, for: imageUrl as NSURL)
self.handleImageLoadingCompletion(with: animatedImage, tags: tags, imageUrlString: imageUrlString, startTime: startTime)
self.handleImageLoadingCompletion(with: animatedImage, tags: tags, imageUrlString: imageUrlString)
} else {
self.handleError("Failed to create animated image from GIF data.")
print("Failed to create animated image from GIF data.")
self.stopLoadingIndicator()
}
} else {
if let newImage = UIImage(data: imageData) {
self.imageCache.insertImage(newImage, for: imageUrl as NSURL)
self.handleImageLoadingCompletion(with: newImage, tags: tags, imageUrlString: imageUrlString, startTime: startTime)
self.handleImageLoadingCompletion(with: newImage, tags: tags, imageUrlString: imageUrlString)
} else {
self.handleError("Failed to load image data.")
print("Failed to load image data.")
self.stopLoadingIndicator()
}
}
}
} else {
self.handleError("Failed to load image data.")
print("Failed to load image data.")
self.stopLoadingIndicator()
}
}
}

private func handleError(_ message: String) {
print(message)
DispatchQueue.main.async {
self.stopLoadingIndicator()
}
}

private func handleImageLoadingCompletion(with newImage: UIImage, tags: [String], imageUrlString: String, startTime: Date) {
private func handleImageLoadingCompletion(with newImage: UIImage, tags: [String], imageUrlString: String) {
addImageToHistory(image: newImage, tags: tags)
currentImageURL = imageUrlString
updateUIWithTags(tags)
Expand All @@ -113,8 +102,5 @@ extension ViewController {
animateImageChange(with: newImage)
stopLoadingIndicator()
incrementCounter()

let executionTime = Date().timeIntervalSince(startTime)
print("Execution time: \(executionTime) seconds")
}
}
12 changes: 3 additions & 9 deletions AnimeGen/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {




func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

UserDefaults.standard.register(defaults: ["enableAnimations": true])
Expand Down Expand Up @@ -37,14 +39,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

func applicationWillTerminate(_ application: UIApplication) {
let defaults = UserDefaults.standard

if defaults.bool(forKey: "disableExplicitContent") {
defaults.set(false, forKey: "enableExplicitContent")
}
}


}
Expand Down
Loading

0 comments on commit 96e6e20

Please sign in to comment.