improvements

This commit is contained in:
Francesco 2025-05-15 18:56:07 +02:00
parent 76b43ba1a0
commit 6996df091b
11 changed files with 39 additions and 89 deletions

View file

@ -118,16 +118,15 @@ class AniListMutation {
"variables": variables
]
guard let jsonData = try? JSONSerialization.data(withJSONObject: requestBody, options: []) else {
completion(.failure(NSError(domain: "", code: -1,
userInfo: [NSLocalizedDescriptionKey: "Failed to serialize GraphQL request"])))
completion(.failure(NSError(domain: "", code: -1, userInfo: [NSLocalizedDescriptionKey: "Failed to serialize GraphQL request"])))
return
}
var request = URLRequest(url: apiURL)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = jsonData
URLSession.shared.dataTask(with: request) { data, resp, error in
if let e = error {
return completion(.failure(e))
@ -135,9 +134,8 @@ class AniListMutation {
guard let data = data,
let json = try? JSONDecoder().decode(AniListMediaResponse.self, from: data),
let mal = json.data.Media?.idMal else {
return completion(.failure(NSError(domain: "", code: -1,
userInfo: [NSLocalizedDescriptionKey: "Failed to decode AniList response or idMal missing"])))
}
return completion(.failure(NSError(domain: "", code: -1, userInfo: [NSLocalizedDescriptionKey: "Failed to decode AniList response or idMal missing"])))
}
completion(.success(mal))
}.resume()
}

View file

@ -8,7 +8,6 @@
import Foundation
import UIKit
// MARK: - Analytics Response Model
struct AnalyticsResponse: Codable {
let status: String
let message: String
@ -16,26 +15,21 @@ struct AnalyticsResponse: Codable {
let timestamp: String?
}
// MARK: - Analytics Manager
class AnalyticsManager {
static let shared = AnalyticsManager()
private let analyticsURL = URL(string: "http://151.106.3.14:47474/analytics")!
private let moduleManager = ModuleManager()
private init() {}
// MARK: - Send Analytics Data
func sendEvent(event: String, additionalData: [String: Any] = [:]) {
let defaults = UserDefaults.standard
// Ensure the key is set with a default value if missing
if defaults.object(forKey: "analyticsEnabled") == nil {
defaults.setValue(false, forKey: "analyticsEnabled")
}
let analyticsEnabled = UserDefaults.standard.bool(forKey: "analyticsEnabled")
guard analyticsEnabled else {
@ -48,10 +42,8 @@ class AnalyticsManager {
return
}
// Prepare analytics data
var safeAdditionalData = additionalData
// Check and convert NSError if present
if let errorValue = additionalData["error"] as? NSError {
safeAdditionalData["error"] = errorValue.localizedDescription
}
@ -68,7 +60,6 @@ class AnalyticsManager {
sendRequest(with: analyticsData)
}
// MARK: - Private Request Method
private func sendRequest(with data: [String: Any]) {
var request = URLRequest(url: analyticsURL)
request.httpMethod = "POST"
@ -105,18 +96,14 @@ class AnalyticsManager {
}.resume()
}
// MARK: - Get App Version
private func getAppVersion() -> String {
return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "unknown_version"
}
// MARK: - Get Device Model
private func getDeviceModel() -> String {
return UIDevice.modelName
}
// MARK: - Get Selected Module
private func getSelectedModule() -> ScrapingModule? {
guard let selectedModuleId = UserDefaults.standard.string(forKey: "selectedModuleId") else { return nil }
return moduleManager.modules.first { $0.id.uuidString == selectedModuleId }

View file

@ -222,10 +222,3 @@ struct ActiveDownload: Identifiable {
var progress: Double
let task: URLSessionTask
}
extension URL {
static func isValidHLSURL(string: String) -> Bool {
guard let url = URL(string: string), url.pathExtension == "m3u8" else { return false }
return true
}
}

View file

@ -18,7 +18,7 @@ public extension UIDevice {
return identifier + String(UnicodeScalar(UInt8(value)))
}
func mapToDevice(identifier: String) -> String { // swiftlint:disable:this cyclomatic_complexity
func mapToDevice(identifier: String) -> String {
#if os(iOS)
switch identifier {
case "iPod5,1":

View file

@ -17,4 +17,9 @@ extension URL {
}
return params
}
static func isValidHLSURL(string: String) -> Bool {
guard let url = URL(string: string), url.pathExtension == "m3u8" else { return false }
return true
}
}

View file

@ -7,26 +7,21 @@
import Foundation
class FetchDelegate: NSObject, URLSessionTaskDelegate
{
class FetchDelegate: NSObject, URLSessionTaskDelegate {
private let allowRedirects: Bool
init(allowRedirects: Bool) {
self.allowRedirects = allowRedirects
}
func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
if(allowRedirects)
{
if(allowRedirects) {
completionHandler(request)
}
else
{
} else {
completionHandler(nil)
}
}
}
extension URLSession {
static let userAgents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",

View file

@ -301,9 +301,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
}
#if os(iOS) && !targetEnvironment(macCatalyst)
if #available(iOS 16.0, *) {
playerViewController.allowsVideoFrameAnalysis = false
}
#endif
if let url = subtitlesURL, !url.isEmpty {

View file

@ -102,9 +102,9 @@ struct LibraryView: View {
ForEach(libraryManager.bookmarks) { item in
if let module = moduleManager.modules.first(where: { $0.id.uuidString == item.moduleId }) {
Button(action: {
selectedBookmark = item
isDetailActive = true
}) {
selectedBookmark = item
isDetailActive = true
}) {
VStack(alignment: .leading) {
ZStack {
KFImage(URL(string: item.imageUrl))
@ -148,21 +148,21 @@ struct LibraryView: View {
}
.padding(.horizontal, 20)
NavigationLink(
destination: Group {
if let bookmark = selectedBookmark,
let module = moduleManager.modules.first(where: { $0.id.uuidString == bookmark.moduleId }) {
MediaInfoView(title: bookmark.title,
imageUrl: bookmark.imageUrl,
href: bookmark.href,
module: module)
} else {
Text("No Data Available")
}
},
isActive: $isDetailActive
) {
EmptyView()
}
destination: Group {
if let bookmark = selectedBookmark,
let module = moduleManager.modules.first(where: { $0.id.uuidString == bookmark.moduleId }) {
MediaInfoView(title: bookmark.title,
imageUrl: bookmark.imageUrl,
href: bookmark.href,
module: module)
} else {
Text("No Data Available")
}
},
isActive: $isDetailActive
) {
EmptyView()
}
.onAppear {
updateOrientation()
}
@ -360,7 +360,6 @@ struct ContinueWatchingCell: View {
if totalTime > 0 {
let ratio = lastPlayedTime / totalTime
// Clamp ratio between 0 and 1:
currentProgress = max(0, min(ratio, 1))
} else {
currentProgress = max(0, min(item.progress, 1))

View file

@ -647,7 +647,6 @@ struct MediaInfoView: View {
} else {
jsController.fetchStreamUrl(episodeUrl: href, softsub: module.metadata.softsub == true, module: module, completion: completion)
}
} catch {
self.handleStreamFailure(error: error)
DispatchQueue.main.async {
@ -718,7 +717,7 @@ struct MediaInfoView: View {
headers = streams[index]["headers"] as? [String:String] ?? [:]
index += 1
}
alert.addAction(UIAlertAction(title: title, style: .default) { _ in
self.playStream(url: streamUrl, fullURL: fullURL, subtitles: subtitles,headers: headers)

View file

@ -316,13 +316,11 @@ struct SearchBar: View {
.background(Color(.systemGray6))
.cornerRadius(8)
.onChange(of: text){newValue in
debounceTimer?.invalidate()
// Start a new timer to wait before performing the action
debounceTimer?.invalidate()
debounceTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false) { _ in
// Perform the action after the delay (debouncing)
onSearchButtonClicked()
}
}
onSearchButtonClicked()
}
}
.overlay(
HStack {
Image(systemName: "magnifyingglass")

View file

@ -74,27 +74,6 @@ struct SettingsViewPlayer: View {
}
}
Section(header: Text("Progress bar Marker Color")) {
ColorPicker("Segments Color", selection: Binding(
get: {
if let data = UserDefaults.standard.data(forKey: "segmentsColorData"),
let uiColor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? UIColor {
return Color(uiColor)
}
return .yellow
},
set: { newColor in
let uiColor = UIColor(newColor)
if let data = try? NSKeyedArchiver.archivedData(
withRootObject: uiColor,
requiringSecureCoding: false
) {
UserDefaults.standard.set(data, forKey: "segmentsColorData")
}
}
))
}
Section(header: Text("Skip Settings"), footer : Text("Double tapping the screen on it's sides will skip with the short tap setting.")) {
HStack {
Text("Tap Skip:")