Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
New server URL
Browse files Browse the repository at this point in the history
  • Loading branch information
inickt committed Nov 10, 2021
1 parent 7068856 commit 3621573
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
6 changes: 4 additions & 2 deletions LazyMan-iOS/GameView/GamePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions LazyMan-iOS/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,10 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
24 changes: 19 additions & 5 deletions LazyManCore/Managers/FeedManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}
11 changes: 11 additions & 0 deletions LazyManCore/Managers/SettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion LazyManCore/Util/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3621573

Please sign in to comment.