|
|
@ -11,9 +11,9 @@ class Twitch(object):
|
|
|
|
self.api_url = api_url
|
|
|
|
self.api_url = api_url
|
|
|
|
self.client_id = client_id
|
|
|
|
self.client_id = client_id
|
|
|
|
|
|
|
|
|
|
|
|
def _get_videos(self, user_id):
|
|
|
|
def _get_videos(self, channel_id):
|
|
|
|
def request(offset, limit):
|
|
|
|
def request(offset, limit):
|
|
|
|
url = '{0}/channels/{1}/videos'.format(self.api_url, user_id)
|
|
|
|
url = '{0}/channels/{1}/videos'.format(self.api_url, channel_id)
|
|
|
|
params = dict(client_id=self.client_id, offset=offset, limit=limit)
|
|
|
|
params = dict(client_id=self.client_id, offset=offset, limit=limit)
|
|
|
|
r = requests.get(url, params=params)
|
|
|
|
r = requests.get(url, params=params)
|
|
|
|
r.raise_for_status()
|
|
|
|
r.raise_for_status()
|
|
|
@ -49,9 +49,9 @@ class Twitch(object):
|
|
|
|
break
|
|
|
|
break
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def _get_stream_info(self, user_id):
|
|
|
|
def _get_stream_info(self, channel_id):
|
|
|
|
def request():
|
|
|
|
def request():
|
|
|
|
url = '{0}/streams/{1}'.format(self.api_url, user_id)
|
|
|
|
url = '{0}/streams/{1}'.format(self.api_url, channel_id)
|
|
|
|
params = dict(client_id=self.client_id)
|
|
|
|
params = dict(client_id=self.client_id)
|
|
|
|
r = requests.get(url, params=params)
|
|
|
|
r = requests.get(url, params=params)
|
|
|
|
r.raise_for_status()
|
|
|
|
r.raise_for_status()
|
|
|
@ -64,9 +64,9 @@ class Twitch(object):
|
|
|
|
game=data['stream']['game'],
|
|
|
|
game=data['stream']['game'],
|
|
|
|
viewers=int(data['stream']['viewers']))
|
|
|
|
viewers=int(data['stream']['viewers']))
|
|
|
|
|
|
|
|
|
|
|
|
def get_messages(self, user_id, since):
|
|
|
|
def get_messages(self, channel_id, since):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
videos = self._get_videos(user_id)
|
|
|
|
videos = self._get_videos(channel_id)
|
|
|
|
result = []
|
|
|
|
result = []
|
|
|
|
for video in [v for v in videos if v['date'] >= since]:
|
|
|
|
for video in [v for v in videos if v['date'] >= since]:
|
|
|
|
comments = self._get_comments(video['id'])
|
|
|
|
comments = self._get_comments(video['id'])
|
|
|
@ -76,8 +76,8 @@ class Twitch(object):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def get_stream_info(self, user_id):
|
|
|
|
def get_stream_info(self, channel_id):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
return self._get_stream_info(user_id)
|
|
|
|
return self._get_stream_info(channel_id)
|
|
|
|
except requests.exceptions.HTTPError as e:
|
|
|
|
except requests.exceptions.HTTPError as e:
|
|
|
|
raise TwitchError('Failed to get stream info: {0}'.format(e))
|
|
|
|
raise TwitchError('Failed to get stream info: {0}'.format(e))
|
|
|
|