Codebase list mlbstreamer / 92eb0ad
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
2 changed file(s) with 30 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
138138 media_id = media["mediaId"] if "mediaId" in media else media["guid"]
139139
140140 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
141156
142157 if "playbacks" in media:
143158 playback = media["playbacks"][0]
9191 token=None,
9292 access_token=None,
9393 access_token_expiry=None,
94 no_cache=False
94 proxies=None,
95 no_cache=False,
9596 ):
9697
9798 self.session = requests.Session()
107108 ("client_api_key", client_api_key),
108109 ("token", token),
109110 ("access_token", access_token),
110 ("access_token_expiry", access_token_expiry)
111 ("access_token_expiry", access_token_expiry),
112 ("proxies", proxies)
111113 ])
112114 self.no_cache = no_cache
113115 self._cache_responses = False
172174 @property
173175 def password(self):
174176 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)
175188
176189 @classmethod
177190 def new(cls, **kwargs):