Skip to content

Commit

Permalink
Merge pull request #2 from JustCoderdev/Development
Browse files Browse the repository at this point in the history
1.0.2 - 2022.07.12 | Less crashes
  • Loading branch information
JustCoderdev authored Jul 12, 2022
2 parents 7afb6aa + 63585f7 commit c6e35a3
Show file tree
Hide file tree
Showing 15 changed files with 513 additions and 512 deletions.
17 changes: 14 additions & 3 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Here there is going to be the changelog of the new versions of the plugin

All of the basic features on the plugin

## [1.0.1] - 2022.07.09 | Minor fixes
## [1.0.1] - 2022.07.11 | Minor fixes

### Added

Expand All @@ -28,8 +28,18 @@ All of the basic features on the plugin
- Logging event exposing `CLIENT-SECRET` and `CLIENT-ID` of Twitch API now removed
- On the showcase page, the refresh button was colored red every time it was updated instead of green

<!-- ## [Unreleased] -->
## [1.0.2] - 2022.07.12 | Less crashes

### Added

- When entering the list in `Channel Names` it now automatically removes spaces to avoid errors or missing data

### Fixed

- Data in title of previous version now is the correct one
- API requests should now no longer crash the plugin

<!-- ## [Unreleased] -->
<!--
### Added
### Changed
Expand All @@ -43,4 +53,5 @@ All of the basic features on the plugin
<!-- [unreleased]: https://github.com/JustCoderdev/TwitchActivity -->

[1.0.0]: https://github.com/JustCoderdev/TwitchActivity/tree/d5b02548cd3f141b0994c05cfed2e136c222fb90
[1.0.1]: https://github.com/JustCoderdev/TwitchActivity/tree/
[1.0.1]: https://github.com/JustCoderdev/TwitchActivity/tree/d4de7b5ebb64ea9d45755294f22e8d6bb2cf3b4a
[1.0.2]: https://github.com/JustCoderdev/TwitchActivity/tree/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This documentation is partially generated with [Python TouchPortal SDK](https://

1. Import the plugin from the release section on [github](https://github.com/JustCoderdev/TwitchActivity/releases)
2. Go to the plugin settings and change `Channel names` to the names of your followed channels and if you need adjust the refresh time (enter the time in minutes)
> NOTE: `Channel names` **must** be formatted like it is by default (MonikaCinnyRoll,xSgtPepperx) without spaces and separated by a `,` (capital letters have no influence over the functioning of the plugin but you can change it for esthetic) and contain up to 100 channels (the last one are going to be ignored)
> NOTE: `Channel names` **must** be formatted like it is by default (MonikaCinnyRoll,xSgtPepperx)without spaces (otherwise it will automatically remove them) and separated by a `,` (capital letters have no influence over the functioning of the plugin but you can change it for esthetic) and contain up to 100 channels (the last one are going to be ignored)
3. Import a simple button from `helpers/touchportal`
4. Go to the button GUI and change `Open stream` action field to your channel name
5. Press the `On Event` tab and change the value in `Update Button text...` from `${value:com.github.justcoderdev.twitchactivity.state.xSgtPepperx.viewers}` to `${value:com.github.justcoderdev.twitchactivity.state.YOURCHANNELNAME.viewers}` and `Change the icon...` from `xSgtPepperx icon` to `YOURCHANNELNAME icon`
Expand Down
2 changes: 1 addition & 1 deletion TwitchActivity/entry.tp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": 6,
"version": 2,
"version": 3,
"name": "Twitch Activity",
"id": "com.github.justcoderdev.twitchactivity",
"configuration": {
Expand Down
Binary file modified TwitchActivity/index.exe
Binary file not shown.
26 changes: 8 additions & 18 deletions build/scripts/WebHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def getStreams(self, users: list): #! Check if token is gone #* Channels & Vi

try:
res = get(f'https://api.twitch.tv/helix/streams?{query[1:]}', headers={'Authorization': f'Bearer {self._TOKEN}', 'Client-Id': self._CLIENT_ID}).json()
err = {'error': 'Bad Request', 'status': 400, 'message': 'Malformed query params.'}
return None if res == err else res
return None if res.get('data') == None else res
except ConnectionError:
isOnline = False

Expand All @@ -142,8 +141,7 @@ def getUsers(self, users: list): #! Check if token is gone

try:
res = get(f'https://api.twitch.tv/helix/users?{query[1:]}', headers={'Authorization': f'Bearer {self._TOKEN}', 'Client-Id': self._CLIENT_ID}).json()
err = {'error': 'Bad Request', 'status': 400, 'message': 'Invalid login names, emails or IDs in request'}
return None if res == err else res
return None if res.get('data') == None else res
except ConnectionError:
isOnline = False

Expand All @@ -159,12 +157,10 @@ def getChannelUserData(usersData: list, channel: str) -> dict:
'defIcon': None,
}

for i in range(len(usersData)):
userData = usersData[i]

for userData in usersData:
if userData['login'] == channel.lower():
output['display_name'] = userData['display_name']
output['defIcon'] = getDefImage(getImgBytesFromUrl(userData['profile_image_url']))
output['defIcon'] = getDefImage(userData['profile_image_url'])
return output

return output
Expand All @@ -176,9 +172,7 @@ def getChannelStreamData(streamsData: list, channel: str) -> dict:
'cViewers': '',
}

for i in range(len(streamsData)):
streamData = streamsData[i]

for streamData in streamsData:
if streamData['user_login'] == channel.lower():
output['cState'] = 'Offline' if streamData['type'] == '' else 'Online'
output['cViewers'] = str(streamData['viewer_count'])
Expand All @@ -187,21 +181,17 @@ def getChannelStreamData(streamsData: list, channel: str) -> dict:
return output


def getImgBytesFromUrl(imgURL: str) -> bytes | None:
global isOnline, newStates
def getDefImage(imgURL: str) -> str | None:
global isOnline

if not isOnline: return None

try:
return get(imgURL).content
imgBytes = get(imgURL).content
except ConnectionError:
isOnline = False
return None


def getDefImage(imgBytes: bytes) -> str | None:
if imgBytes == None: return None

#!#
imgDef = Image.open(BytesIO(imgBytes))
#!#
Expand Down
2 changes: 1 addition & 1 deletion build/scripts/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def updateSettings(data):

# Update settings
REFRESH['time'] = int(data[1]['Refresh Time (m)'])
CHANNELS = data[0]['Channel names'].split(',')[:100]
CHANNELS = data[0]['Channel names'].replace(' ', '').split(',')[:100]
DYNAMIC = True if data[2]['Dynamic image (bool)'] == '1' else False

# Create new states
Expand Down
Loading

0 comments on commit c6e35a3

Please sign in to comment.