Skip to content

Commit

Permalink
Merge pull request #47 from pppontusw/blackout-detection
Browse files Browse the repository at this point in the history
Detect geographic blackout
  • Loading branch information
pppontusw authored May 26, 2024
2 parents 6cf688e + 5c7b035 commit e2ec5df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 7 additions & 2 deletions nhltv_lib/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from nhltv_lib.constants import HEADERS, UA_NHLTV
from nhltv_lib.exceptions import (
AuthenticationFailed,
BlackoutRestriction,
)
from nhltv_lib.models import GameStatus
from nhltv_lib.stream import get_shorten_video
Expand Down Expand Up @@ -85,9 +86,14 @@ def _get_download_from_stream(stream: NHLStream) -> Download:
def _verify_nhltv_request_status_succeeded(nhltv_json: dict) -> None:
"""
Takes a response from the session key URL and raises
AuthenticationFailed if authentication failed
appropriate error if authentication failed
"""
if nhltv_json.get("status") != "success":
if nhltv_json.get("code") == 209:
tprint(
"Stream can not be authorized due to geographic restriction"
)
raise BlackoutRestriction(nhltv_json)
raise AuthenticationFailed(nhltv_json)


Expand All @@ -107,7 +113,6 @@ def _get_session_key(stream: NHLStream) -> str:
raise AuthenticationFailed(session_rsp.json())
session_json = session_rsp.json()


dump_json_if_debug_enabled(session_json)

return _extract_session_key(session_json)
Expand Down
9 changes: 4 additions & 5 deletions nhltv_lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ def download(stream: NHLStream, attempts: int = 0) -> None:
if attempts < 1:
login_and_save_cookie()
return download(stream, attempts + 1)
else:
game_tracking.update_game_status(
stream.game_id, GameStatus.auth_failure
)
raise
game_tracking.update_game_status(
stream.game_id, GameStatus.auth_failure
)
raise
except BlackoutRestriction:
game_tracking.set_blackout(stream.game_id)

Expand Down

0 comments on commit e2ec5df

Please sign in to comment.