# Path: twitch/api/base.py
# class TwitchAPI(object):
#     """Twitch API client."""
# 
#     def __init__(self, client_id, oauth_token=None):
#         """Initialize the API."""
#         super(TwitchAPI, self).__init__()
#         self._client_id = client_id
#         self._oauth_token = oauth_token
#         self._initial_backoff, self._max_retries = backoff_config()
# 
#     def _get_request_headers(self):
#         """Prepare the headers for the requests."""
#         headers = {
#             "Accept": "application/vnd.twitchtv.v5+json",
#             "Client-ID": self._client_id,
#         }
# 
#         if self._oauth_token:
#             headers["Authorization"] = "OAuth {}".format(self._oauth_token)
# 
#         return headers
# 
#     def _request_get(self, path, params=None, json=True, url=BASE_URL):
#         """Perform a HTTP GET request."""
#         url = urljoin(url, path)
#         headers = self._get_request_headers()
# 
#         response = requests.get(url, params=params, headers=headers)
#         if response.status_code >= 500:
# 
#             backoff = self._initial_backoff
#             for _ in range(self._max_retries):
#                 time.sleep(backoff)
#                 backoff_response = requests.get(
#                     url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
#                 )
#                 if backoff_response.status_code < 500:
#                     response = backoff_response
#                     break
#                 backoff *= 2
# 
#         response.raise_for_status()
#         if json:
#             return response.json()
#         else:
#             return response
# 
#     def _request_post(self, path, data=None, params=None, url=BASE_URL):
#         """Perform a HTTP POST request.."""
#         url = urljoin(url, path)
# 
#         headers = self._get_request_headers()
# 
#         response = requests.post(
#             url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
#         )
#         response.raise_for_status()
#         if response.status_code == 200:
#             return response.json()
# 
#     def _request_put(self, path, data=None, params=None, url=BASE_URL):
#         """Perform a HTTP PUT request."""
#         url = urljoin(url, path)
# 
#         headers = self._get_request_headers()
#         response = requests.put(
#             url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
#         )
#         response.raise_for_status()
#         if response.status_code == 200:
#             return response.json()
# 
#     def _request_delete(self, path, params=None, url=BASE_URL):
#         """Perform a HTTP DELETE request."""
#         url = urljoin(url, path)
# 
#         headers = self._get_request_headers()
# 
#         response = requests.delete(
#             url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
#         )
#         response.raise_for_status()
#         if response.status_code == 200:
#             return response.json()
# 
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
# 
# BROADCAST_TYPES = [
#     BROADCAST_TYPE_ARCHIVE,
#     BROADCAST_TYPE_HIGHLIGHT,
#     BROADCAST_TYPE_UPLOAD,
#     BROADCAST_TYPE_ARCHIVE_UPLOAD,
#     BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
#     BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
#     BROADCAST_TYPE_ALL,
# ]
# 
# PERIOD_WEEK = "week"
# 
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
# 
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
# 
# Path: twitch/decorators.py
# def oauth_required(func):
#     def wrapper(*args, **kwargs):
#         if not args[0]._oauth_token:
#             raise TwitchAuthException("OAuth token required")
#         return func(*args, **kwargs)
# 
#     return wrapper
# 
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
#     pass
# 
# Path: twitch/resources.py
# class Video(TwitchObject):
#     pass


from twitch.api.base import TwitchAPI
from twitch.constants import (
    BROADCAST_TYPE_HIGHLIGHT,
    BROADCAST_TYPES,
    PERIOD_WEEK,
    PERIODS,
    VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video


class Videos(TwitchAPI):
    def get_by_id(self, video_id):
        response = self._request_get("videos/{}".format(video_id))
        return Video.construct_from(response)

    def get_top(
        self,
        limit=10,
        offset=0,
        game=None,
        period=PERIOD_WEEK,
        broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
    ):
        if limit > 100:
            raise TwitchAttributeException(
                "Maximum number of objects returned in one request is 100"
            )
        if period not in PERIODS:
            raise TwitchAttributeException(
                "Period is not valid. Valid values are {}".format(PERIODS)
            )


# Path: twitch/api/base.py
# class TwitchAPI(object):
#     """Twitch API client."""
# 
#     def __init__(self, client_id, oauth_token=None):
#         """Initialize the API."""
#         super(TwitchAPI, self).__init__()
#         self._client_id = client_id
#         self._oauth_token = oauth_token
#         self._initial_backoff, self._max_retries = backoff_config()
# 
#     def _get_request_headers(self):
#         """Prepare the headers for the requests."""
#         headers = {
#             "Accept": "application/vnd.twitchtv.v5+json",
#             "Client-ID": self._client_id,
#         }
# 
#         if self._oauth_token:
#             headers["Authorization"] = "OAuth {}".format(self._oauth_token)
# 
#         return headers
# 
#     def _request_get(self, path, params=None, json=True, url=BASE_URL):
#         """Perform a HTTP GET request."""
#         url = urljoin(url, path)
#         headers = self._get_request_headers()
# 
#         response = requests.get(url, params=params, headers=headers)
#         if response.status_code >= 500:
# 
#             backoff = self._initial_backoff
#             for _ in range(self._max_retries):
#                 time.sleep(backoff)
#                 backoff_response = requests.get(
#                     url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
#                 )
#                 if backoff_response.status_code < 500:
#                     response = backoff_response
#                     break
#                 backoff *= 2
# 
#         response.raise_for_status()
#         if json:
#             return response.json()
#         else:
#             return response
# 
#     def _request_post(self, path, data=None, params=None, url=BASE_URL):
#         """Perform a HTTP POST request.."""
#         url = urljoin(url, path)
# 
#         headers = self._get_request_headers()
# 
#         response = requests.post(
#             url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
#         )
#         response.raise_for_status()
#         if response.status_code == 200:
#             return response.json()
# 
#     def _request_put(self, path, data=None, params=None, url=BASE_URL):
#         """Perform a HTTP PUT request."""
#         url = urljoin(url, path)
# 
#         headers = self._get_request_headers()
#         response = requests.put(
#             url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
#         )
#         response.raise_for_status()
#         if response.status_code == 200:
#             return response.json()
# 
#     def _request_delete(self, path, params=None, url=BASE_URL):
#         """Perform a HTTP DELETE request."""
#         url = urljoin(url, path)
# 
#         headers = self._get_request_headers()
# 
#         response = requests.delete(
#             url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
#         )
#         response.raise_for_status()
#         if response.status_code == 200:
#             return response.json()
# 
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
# 
# BROADCAST_TYPES = [
#     BROADCAST_TYPE_ARCHIVE,
#     BROADCAST_TYPE_HIGHLIGHT,
#     BROADCAST_TYPE_UPLOAD,
#     BROADCAST_TYPE_ARCHIVE_UPLOAD,
#     BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
#     BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
#     BROADCAST_TYPE_ALL,
# ]
# 
# PERIOD_WEEK = "week"
# 
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
# 
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
# 
# Path: twitch/decorators.py
# def oauth_required(func):
#     def wrapper(*args, **kwargs):
#         if not args[0]._oauth_token:
#             raise TwitchAuthException("OAuth token required")
#         return func(*args, **kwargs)
# 
#     return wrapper
# 
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
#     pass
# 
# Path: twitch/resources.py
# class Video(TwitchObject):
#     pass


# Path: twitch/api/videos.py
from twitch.api.base import TwitchAPI
from twitch.constants import (
    BROADCAST_TYPE_HIGHLIGHT,
    BROADCAST_TYPES,
    PERIOD_WEEK,
    PERIODS,
    VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video



class Videos(TwitchAPI):
    def get_by_id(self, video_id):
        response = self._request_get("videos/{}".format(video_id))
        return Video.construct_from(response)

    def get_top(
        self,
        limit=10,
        offset=0,
        game=None,
        period=PERIOD_WEEK,
        broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
    ):
        if limit > 100:
            raise TwitchAttributeException(
                "Maximum number of objects returned in one request is 100"
            )
        if period not in PERIODS:
            raise TwitchAttributeException(
                "Period is not valid. Valid values are {}".format(PERIODS)
            )


        if broadcast_type not in BROADCAST_TYPES: