-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,173 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CACHE_CHANNEL_LIMIT=500 | ||
CACHE_TIMEOUT_7TV=300 | ||
CACHE_TIMEOUT_BTTV=300 | ||
CACHE_TIMEOUT_FFZ=300 | ||
CACHE_TIMEOUT_TWITCH=300 | ||
TWITCH_CLIENT_ID= | ||
TWITCH_SECRET= |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM python:3.7.13-alpine | ||
COPY ./ /app | ||
WORKDIR /app | ||
RUN ls -a | ||
RUN pip3 install -r requirements.txt | ||
CMD ["gunicorn", "--preload", "--bind", "0.0.0.0:8000", "app:app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# emotes-api | ||
Fetches Twitch emotes from various providers (Twitch, 7TV, BTTV, FFZ). | ||
|
||
[![Clang analysis](https://status.crippled.dev/api/badge/5/status)](https://emotes.crippled.dev) | ||
|
||
# Endpoints | ||
- `/v1/channel/<username>/<provider>` | ||
- `/v1/global/<provider>` | ||
|
||
Available providers: `twitch`, `7tv`, `bttv`, `ffz`, `all`. | ||
|
||
## Output | ||
```json | ||
[ | ||
{ | ||
"animated": false, | ||
"code": "FeelsDankMan", | ||
"provider": 1, | ||
"urls": [ | ||
{ | ||
"size": "1x", | ||
"url": "https://cdn.7tv.app/emote/63071bb9464de28875c52531/1x.webp" | ||
}, | ||
{ | ||
"size": "2x", | ||
"url": "https://cdn.7tv.app/emote/63071bb9464de28875c52531/2x.webp" | ||
}, | ||
{ | ||
"size": "3x", | ||
"url": "https://cdn.7tv.app/emote/63071bb9464de28875c52531/3x.webp" | ||
}, | ||
{ | ||
"size": "4x", | ||
"url": "https://cdn.7tv.app/emote/63071bb9464de28875c52531/4x.webp" | ||
} | ||
], | ||
"zero_width": false | ||
}, | ||
] | ||
``` | ||
|
||
### Providers | ||
| id | Provider | | ||
| --- | --- | | ||
| 0 | Twitch | | ||
| 1 | 7TV | | ||
| 2 | BTTV | | ||
| 3 | FFZ | | ||
|
||
# Setup | ||
1. Register an app on [dev.twitch.tv](https://dev.twitch.tv/console/apps/create) and enter the client ID and secret in [.env](.env.example). | ||
2. Install requirements. | ||
```python | ||
pip3 install -r requirements.txt | ||
``` | ||
3. Run the server. | ||
```python | ||
gunicorn --preload --bind 0.0.0.0:8000 app:app | ||
``` | ||
|
||
# Development | ||
- Unit tests | ||
```python | ||
python3 -m unittest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
{ | ||
"schemaVersion" :2 , | ||
"dockerfileLines" :[ | ||
"FROM python:3.7.13-alpine", | ||
"COPY ./ /app", | ||
"WORKDIR /app", | ||
"RUN ls -a", | ||
"RUN pip3 install -r requirements.txt", | ||
"CMD [ \"gunicorn\", \"--preload\", \"--bind\", \"0.0.0.0:8000\", \"app:app\" ]" | ||
] | ||
"schemaVersion": 2, | ||
"dockerfilePath": "./Dockerfile" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from dotenv import load_dotenv | ||
from twitchAPI.twitch import Twitch | ||
import asyncio | ||
import os | ||
import threading | ||
import providers.twitch | ||
import providers.seventv | ||
import providers.bttv | ||
import providers.ffz | ||
|
||
load_dotenv() | ||
TWITCH_CLIENT_ID = os.getenv('TWITCH_CLIENT_ID') | ||
TWITCH_SECRET = os.getenv('TWITCH_SECRET') | ||
|
||
class Channel: | ||
async def getUserId(self): | ||
twitch = await Twitch(TWITCH_CLIENT_ID, TWITCH_SECRET) | ||
async for user in twitch.get_users(logins=self.login): | ||
self.user_id = user.id | ||
print(f'[{self.login}] Found user: {self.user_id}') | ||
|
||
def __init__(self, login): | ||
self.twitch_emotes = [] | ||
self.twitch_emotes_updated = 0 | ||
self.twitch_lock = threading.Lock() | ||
self.seventv_emotes = [] | ||
self.seventv_emotes_updated = 0 | ||
self.seventv_lock = threading.Lock() | ||
self.bttv_emotes = [] | ||
self.bttv_emotes_updated = 0 | ||
self.bttv_lock = threading.Lock() | ||
self.ffz_emotes = [] | ||
self.ffz_emotes_updated = 0 | ||
self.ffz_lock = threading.Lock() | ||
self.login = login | ||
|
||
if login != '_global': | ||
asyncio.run(self.getUserId()) | ||
|
||
def getTwitchEmotes(self): | ||
return providers.twitch.getEmotes(self) | ||
|
||
def getSevenTVEmotes(self): | ||
return providers.seventv.getEmotes(self) | ||
|
||
def getBTTVEmotes(self): | ||
return providers.bttv.getEmotes(self) | ||
|
||
def getFFZEmotes(self): | ||
return providers.ffz.getEmotes(self) | ||
|
||
def getEmotes(self): | ||
twitch_emotes = self.getTwitchEmotes() | ||
seventv_emotes = self.getSevenTVEmotes() | ||
bttv_emotes = self.getBTTVEmotes() | ||
ffz_emotes = self.getFFZEmotes() | ||
return twitch_emotes + seventv_emotes + bttv_emotes + ffz_emotes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class EmoteUrl: | ||
def __init__(self, size, url): | ||
self.size = size | ||
self.url = url | ||
|
||
def toDict(self): | ||
return dict(size=self.size, url=self.url) | ||
|
||
class Emote: | ||
def __init__(self, code, provider, zero_width, animated): | ||
self.code = code | ||
self.provider = provider | ||
self.zero_width = zero_width | ||
self.animated = animated | ||
self.urls = [] | ||
|
||
def toDict(self): | ||
return dict( | ||
code=self.code, | ||
provider=self.provider, | ||
zero_width=self.zero_width, | ||
animated = self.animated, | ||
urls=[u.toDict() for u in self.urls] | ||
) | ||
|
||
def addUrl(self, size, url): | ||
self.urls.append(EmoteUrl(size, url)) |
Oops, something went wrong.