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

Commit

Permalink
Add audio only feeds for NHL games (#72)
Browse files Browse the repository at this point in the history
* Add audio feeds for NHL

* Update audio feed names
  • Loading branch information
inickt authored Mar 13, 2020
1 parent 5ebfaf3 commit 8fdd952
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
8 changes: 4 additions & 4 deletions LazyManCore/Models/Feed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public struct Feed: Hashable {
}

// TODO: - This is bad now, refactor
public init(highlightName: String, league: League, url: URL?) {
public init(feedType: String, callLetters: String, feedName: String, league: League, url: URL?) {
self.playlistUrl = url
self.feedType = FeedType(feedType: highlightName)
self.feedType = FeedType(feedType: feedType)
self.league = league
self.feedName = highlightName
self.callLetters = ""
self.feedName = feedName
self.callLetters = callLetters
self.playbackID = 0
self.date = Date()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ private extension MLBScheduleResponse.EpgAlternateResponse {
let playbackUrl = URL(string: playbackUrlString) else {
return []
}
return [Feed(highlightName: title, league: .MLB, url: playbackUrl)]
return [Feed(feedType: "",
callLetters: "",
feedName: title,
league: .MLB,
url: playbackUrl)]
default:
return []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,33 @@ private extension NHLScheduleResponse.EpgResponse {
Feed(feedType: $0.mediaFeedType ?? "",
callLetters: $0.callLetters ?? "",
feedName: $0.feedName ?? "",
playbackID: Int($0.mediaPlaybackId) ?? -1,
playbackID: Int($0.mediaPlaybackId ?? "") ?? -1,
league: .NHL,
date: date)
}
case "Audio":
return items.compactMap {
guard let stringURL = $0.mediaPlaybackURL,
let url = URL(string: stringURL) else {
return nil
}
return Feed(feedType: $0.mediaFeedType ?? "",
callLetters: "\($0.callLetters ?? "") - Audio",
feedName: $0.feedName ?? "",
league: .NHL,
url: url)

}
case "Extended Highlights", "Recap":
guard let playbackUrlString = items.first?.playbacks?.first(where: { $0.name == "HTTP_CLOUD_TABLET_60" })?.url,
let playbackUrl = URL(string: playbackUrlString) else {
return []
guard let stringURL = items.first?.mediaPlaybackURL,
let url = URL(string: stringURL) else {
return []
}
return [Feed(highlightName: title, league: .NHL, url: playbackUrl)]
return [Feed(feedType: "",
callLetters: "",
feedName: title,
league: .NHL,
url: url)]
default:
return []
}
Expand Down
3 changes: 2 additions & 1 deletion LazyManCore/Models/Schedules/NHLScheduleResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ struct NHLScheduleResponse: Codable {
}

struct EpgItemResponse: Codable {
let mediaPlaybackId: String
let mediaPlaybackId: String?
let mediaFeedType: String?
let mediaPlaybackURL: String?
let callLetters: String?
let feedName: String?
let playbacks: [PlaybackResponse]?
Expand Down
4 changes: 3 additions & 1 deletion LazyManCore/Util/ScheduleLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class ScheduleWebLoader: ScheduleLoader {
let config = URLSessionConfiguration.default
config.requestCachePolicy = .reloadIgnoringLocalCacheData
config.urlCache = nil
config.httpAdditionalHeaders = config.httpAdditionalHeaders ?? [:]
config.httpAdditionalHeaders?["x-platform"] = "ios-phone"
self.session = URLSession(configuration: config)
}

Expand All @@ -58,7 +60,7 @@ public class ScheduleWebLoader: ScheduleLoader {
return .failure(.urlError("\(startDateString)\(endDateString) schedule"))
}

let (data, _, error) = URLSession.shared.synchronousDataTask(with: url)
let (data, _, error) = self.session.synchronousDataTask(with: url)

if let data = data {
return .success(data)
Expand Down

0 comments on commit 8fdd952

Please sign in to comment.