|
2 | 2 | import logging
|
3 | 3 |
|
4 | 4 | import requests
|
| 5 | +from requests.api import request |
5 | 6 |
|
6 | 7 | import scctool.settings
|
7 | 8 | import scctool.settings.translation
|
|
17 | 18 | def updateTitle(newTitle):
|
18 | 19 | """Update the twitch title to the title specified in the config file."""
|
19 | 20 | global previousTitle
|
| 21 | + twitchChannel = scctool.settings.config.parser.get( |
| 22 | + "Twitch", "Channel").strip() |
20 | 23 |
|
21 | 24 | try:
|
22 |
| - twitchChannel = scctool.settings.config.parser.get( |
23 |
| - "Twitch", "Channel").strip() |
24 | 25 | userID = getUserID(twitchChannel)
|
25 | 26 |
|
26 | 27 | clientID = scctool.settings.safe.get('twitch-client-id')
|
27 | 28 | oauth = scctool.settings.config.parser.get("Twitch", "oauth")
|
28 | 29 |
|
29 | 30 | headers = {'Accept': 'application/vnd.twitchtv.v5+json',
|
30 |
| - 'Authorization': f'OAuth {oauth}', |
31 |
| - 'Client-ID': clientID} |
| 31 | + 'Authorization': f'Bearer {oauth}', |
| 32 | + 'Client-Id': clientID} |
32 | 33 |
|
33 |
| - params = {'channel[status]': newTitle} |
| 34 | + data = {'title': newTitle} |
| 35 | + |
| 36 | + params = {'broadcaster_id': userID} |
34 | 37 |
|
35 | 38 | if scctool.settings.config.parser.getboolean("Twitch", "set_game"):
|
36 |
| - params['channel[game]'] = 'StarCraft II' |
| 39 | + data['game_id'] = '490422' |
37 | 40 |
|
38 |
| - requests.put(f'https://api.twitch.tv/kraken/channels/{userID}', |
39 |
| - headers=headers, params=params).raise_for_status() |
| 41 | + requests.patch( |
| 42 | + url=f'https://api.twitch.tv/helix/channels', headers=headers, params=params, json=data).raise_for_status() |
40 | 43 | msg = _('Updated Twitch title of {} to: "{}"').format(
|
41 | 44 | twitchChannel, newTitle)
|
42 | 45 | success = True
|
@@ -72,12 +75,16 @@ def getUserID(login):
|
72 | 75 | client_id = scctool.settings.safe.get('twitch-client-id')
|
73 | 76 | url = 'https://api.twitch.tv/helix/users'
|
74 | 77 | oauth = scctool.settings.config.parser.get("Twitch", "oauth")
|
75 |
| - headers = {'Client-ID': client_id, 'Authorization': f'Bearer {oauth}'} |
| 78 | + headers = {'Client-Id': client_id, 'Authorization': f'Bearer {oauth}'} |
76 | 79 | params = {'login': login}
|
77 | 80 |
|
78 | 81 | r = requests.get(url, headers=headers, params=params)
|
79 | 82 | r.raise_for_status()
|
80 |
| - return r.json().get('data')[0]['id'] |
| 83 | + try: |
| 84 | + return r.json().get('data')[0]['id'] |
| 85 | + except IndexError: |
| 86 | + raise ValueError( |
| 87 | + f'Twitch channel "{login}" not found - please check your settings.') |
81 | 88 |
|
82 | 89 |
|
83 | 90 | # def addCommunity(channelID):
|
|
0 commit comments