-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+2.49 KB
(100%)
...eproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// nekosapi.swift | ||
// AnimeGen | ||
// | ||
// Created by cranci on 17/02/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension ViewController { | ||
|
||
func loadImageAndTagsFromNekosapi() { | ||
startLoadingIndicator() | ||
|
||
let rating = ["safe", "suggestive"] | ||
let randomrating = rating.randomElement() ?? "safe" | ||
|
||
let apiEndpoint = "https://api.nekosapi.com/v3/images/random?limit=1&rating=\(randomrating)" | ||
|
||
guard let url = URL(string: apiEndpoint) else { | ||
print("Invalid URL") | ||
stopLoadingIndicator() | ||
return | ||
} | ||
|
||
var request = URLRequest(url: url) | ||
request.httpMethod = "GET" | ||
|
||
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in | ||
DispatchQueue.main.async { | ||
if let error = error { | ||
print("Error: \(error)") | ||
self.stopLoadingIndicator() | ||
return | ||
} | ||
|
||
guard let httpResponse = response as? HTTPURLResponse else { | ||
print("Invalid HTTP response") | ||
self.stopLoadingIndicator() | ||
return | ||
} | ||
|
||
guard httpResponse.statusCode == 200 else { | ||
print("Invalid status code: \(httpResponse.statusCode)") | ||
self.stopLoadingIndicator() | ||
return | ||
} | ||
|
||
do { | ||
if let jsonData = data, | ||
let jsonResponse = try? JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any], | ||
let items = jsonResponse["items"] as? [[String: Any]], | ||
let firstItem = items.first, | ||
let imageUrlString = firstItem["image_url"] as? String, | ||
let imageUrl = URL(string: imageUrlString), | ||
let tagsArray = firstItem["tags"] as? [[String: Any]] { | ||
|
||
self.currentImageURL = imageUrlString | ||
|
||
let tags = tagsArray.compactMap { $0["name"] as? String } | ||
|
||
if let data = try? Data(contentsOf: imageUrl), let newImage = UIImage(data: data) { | ||
self.imageView.image = newImage | ||
self.animateImageChange(with: newImage) | ||
|
||
self.updateUIWithTags(tags) | ||
|
||
self.stopLoadingIndicator() | ||
} else { | ||
print("Failed to load image data.") | ||
self.stopLoadingIndicator() | ||
} | ||
} else { | ||
print("Failed to parse JSON response or missing necessary data.") | ||
self.stopLoadingIndicator() | ||
} | ||
} | ||
} | ||
} | ||
|
||
task.resume() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
# AnimeGen | ||
|
||
AnimeGen is an app made in Swift. This app is developed using the [pic.re api](https://doc.pic.re/), [waifu.im api](https://docs.waifu.im/), [nekos.best api](https://docs.nekos.best/), [waifu.pics api](https://waifu.pics/docs), [Hmtai api](https://hmtai.hatsunia.cfd/endpoints), Its purpose is to save, generate, and share images. | ||
|
||
--- | ||
AnimeGen is an app made in Swift. This app is developed using public APIs. The app purpose is to save, generate, and share images. | ||
|
||
## Compatibility | ||
Its Made to support any iOS/iPadOS device running iOS 13+ | ||
|
||
## Supported APIs | ||
|
||
- [pic.re api](https://doc.pic.re/) | ||
- [waifu.im api](https://docs.waifu.im/) | ||
- [nekos.best api](https://docs.nekos.best/) | ||
- [waifu.pics api](https://waifu.pics/docs) | ||
- [Hmtai api](https://hmtai.hatsunia.cfd/endpoints) | ||
- [Nekos api](https://nekosapi.com/docs) | ||
|
||
## Third Party Softwares | ||
|
||
- [SDWebImage](https://github.com/SDWebImage/SDWebImage) (.gif images saves for the gallery) | ||
- [NineAnimator](https://github.com/SuperMarcus/NineAnimator) (Launchscreen Idea/Base) | ||
- [Nekidev](https://github.com/Nekidev/anime-api) (Helped me finding the Htmai api) | ||
- [Nekidev](https://github.com/Nekidev/anime-api) (Helped me finding the Htmai api) |