diff --git a/LazyMan-iOS/GameView/GamePresenter.swift b/LazyMan-iOS/GameView/GamePresenter.swift index c3f2816..627f1c6 100644 --- a/LazyMan-iOS/GameView/GamePresenter.swift +++ b/LazyMan-iOS/GameView/GamePresenter.swift @@ -106,9 +106,11 @@ class GamePresenter: NSObject, GamePresenterType, CastDelegate { func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool { if let url = loadingRequest.request.url { + var components = URLComponents(url: url, resolvingAgainstBaseURL: true) + components?.scheme = "http" + components?.host = settingsManager.serverHostname ?? defaultServerAddress for host in allHosts { - if url.absoluteString.contains(host), - let redirect = URL(string: url.absoluteString.replacingOccurrences(of: host, with: serverAddress)) { + if url.absoluteString.contains(host), let redirect = components?.url { try? loadingRequest.dataRequest?.respond(with: Data(contentsOf: redirect)) loadingRequest.finishLoading() return true diff --git a/LazyMan-iOS/Resources/Info.plist b/LazyMan-iOS/Resources/Info.plist index 8564f2d..99cd151 100644 --- a/LazyMan-iOS/Resources/Info.plist +++ b/LazyMan-iOS/Resources/Info.plist @@ -67,5 +67,10 @@ UIViewControllerBasedStatusBarAppearance + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + diff --git a/LazyManCore/Managers/FeedManager.swift b/LazyManCore/Managers/FeedManager.swift index 6a6845b..2bcd0fe 100644 --- a/LazyManCore/Managers/FeedManager.swift +++ b/LazyManCore/Managers/FeedManager.swift @@ -39,6 +39,13 @@ public class FeedManager: FeedManagerType { // MARK: - Private Properties private var cachedPlaylists = [Feed: [CDN: [Playlist]]]() + private var settingsManager: SettingsManagerType + + // MARK: - Init + + public init(settingsManager: SettingsManagerType = SettingsManager.shared) { + self.settingsManager = settingsManager + } // MARK: - FeedManagerType @@ -126,12 +133,19 @@ public class FeedManager: FeedManagerType { */ private func getMasterURL(league: League, cdn: CDN, playbackID: Int, date: Date) -> URL? { let dateString = DateUtils.convertToYYYYMMDD(from: date, timeZone: TimeZone(identifier: "America/Los_Angeles")!) - let masterURLSource = "https://freegamez.ga/getM3U8.php?league=\(league.rawValue)&date=\(dateString)&id=\(playbackID)&cdn=\(cdn.rawValue)" - - if let contents = try? String(contentsOf: URL(string: masterURLSource)!) { - return URL(string: contents) - } else { + var components = URLComponents() + components.scheme = "http" + components.host = settingsManager.serverHostname ?? defaultServerAddress + components.path = "/getM3U8.php" + components.queryItems = [ + .init(name: "league", value: league.rawValue), + .init(name: "date", value: dateString), + .init(name: "id", value: String(playbackID)), + .init(name: "cdn", value: cdn.rawValue) + ] + guard let url = components.url, let contents = try? String(contentsOf: url) else { return nil } + return URL(string: contents) } } diff --git a/LazyManCore/Managers/SettingsManager.swift b/LazyManCore/Managers/SettingsManager.swift index 7686350..e4d7882 100644 --- a/LazyManCore/Managers/SettingsManager.swift +++ b/LazyManCore/Managers/SettingsManager.swift @@ -16,6 +16,7 @@ public protocol SettingsManagerType { var showScores: Bool { get set } var favoriteNHLTeams: [Team] { get set } var favoriteMLBTeams: [Team] { get set } + var serverHostname: String? { get set } var notifications: Bool { get set } var versionUpdates: Bool { get set } var betaUpdates: Bool { get set } @@ -124,6 +125,16 @@ public class SettingsManager: SettingsManagerType { } } + private let serverHostnameKey = "serverHostname" + public var serverHostname: String? { + get { + return UserDefaults.standard.string(forKey: serverHostnameKey) + } + set { + UserDefaults.standard.set(newValue, forKey: serverHostnameKey) + } + } + private let notificationsKey = "notifications" public var notifications: Bool { get { diff --git a/LazyManCore/Util/Constants.swift b/LazyManCore/Util/Constants.swift index b81201a..afacd13 100644 --- a/LazyManCore/Util/Constants.swift +++ b/LazyManCore/Util/Constants.swift @@ -14,7 +14,7 @@ public let mlbHosts = ["mlb-ws-mf.media.mlb.com", "playback.svcs.mlb.com"] public let allHosts = nhlHosts + mlbHosts // Server address -public let serverAddress = "freegamez.ga" +public let defaultServerAddress = "freesports.ddns.net" // Notification for pausing when back to game list on iPhone public let pauseNotification = NSNotification.Name(rawValue: "pause")