Take 2 of configurable proxy support.
* If the currently active profile, or a team-specific profile
override (described in 111545e) contains a "proxies" setting, use that setting
for retrieving the stream information from MLB.tv.
Tony Cebzanov
5 years ago
138 | 138 |
media_id = media["mediaId"] if "mediaId" in media else media["guid"]
|
139 | 139 |
|
140 | 140 |
media_state = media["mediaState"]
|
|
141 |
|
|
142 |
# Get any team-specific profile overrides, and apply settings for them
|
|
143 |
profiles = tuple([ list(d.values())[0]
|
|
144 |
for d in config.settings.profile_map.get("team", {})
|
|
145 |
if list(d.keys())[0] in [
|
|
146 |
away_team_abbrev, home_team_abbrev
|
|
147 |
] ])
|
|
148 |
|
|
149 |
if len(profiles):
|
|
150 |
# override proxies for team, if defined
|
|
151 |
if len(config.settings.profiles[profiles].proxies):
|
|
152 |
old_proxies = state.session.proxies
|
|
153 |
state.session.proxies = config.settings.profiles[profiles].proxies
|
|
154 |
state.session.refresh_access_token(clear_token=True)
|
|
155 |
state.session.proxies = old_proxies
|
141 | 156 |
|
142 | 157 |
if "playbacks" in media:
|
143 | 158 |
playback = media["playbacks"][0]
|
91 | 91 |
token=None,
|
92 | 92 |
access_token=None,
|
93 | 93 |
access_token_expiry=None,
|
94 | |
no_cache=False
|
|
94 |
proxies=None,
|
|
95 |
no_cache=False,
|
95 | 96 |
):
|
96 | 97 |
|
97 | 98 |
self.session = requests.Session()
|
|
107 | 108 |
("client_api_key", client_api_key),
|
108 | 109 |
("token", token),
|
109 | 110 |
("access_token", access_token),
|
110 | |
("access_token_expiry", access_token_expiry)
|
|
111 |
("access_token_expiry", access_token_expiry),
|
|
112 |
("proxies", proxies)
|
111 | 113 |
])
|
112 | 114 |
self.no_cache = no_cache
|
113 | 115 |
self._cache_responses = False
|
|
172 | 174 |
@property
|
173 | 175 |
def password(self):
|
174 | 176 |
return self._state.password
|
|
177 |
|
|
178 |
@property
|
|
179 |
def proxies(self):
|
|
180 |
return self._state.proxies
|
|
181 |
|
|
182 |
@proxies.setter
|
|
183 |
def proxies(self, value):
|
|
184 |
# Override proxy environment variables if proxies are defined on session
|
|
185 |
self.session.trust_env = (len(value) == 0)
|
|
186 |
self._state.proxies = value
|
|
187 |
self.session.proxies.update(value)
|
175 | 188 |
|
176 | 189 |
@classmethod
|
177 | 190 |
def new(cls, **kwargs):
|