From a18db6d6f2dd99d2853069896a0e2daa5a702f90 Mon Sep 17 00:00:00 2001 From: offish Date: Wed, 30 Dec 2020 12:09:06 +0100 Subject: [PATCH 1/5] Update __init__.py --- twitchtube/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitchtube/__init__.py b/twitchtube/__init__.py index 15c6031..d1d8b67 100644 --- a/twitchtube/__init__.py +++ b/twitchtube/__init__.py @@ -2,4 +2,4 @@ __title__ = 'twitchtube' __author__ = 'offish' __license__ = 'MIT' -__version__ = '1.3.1' +__version__ = '1.3.2' From e68cee2afd11758f4e5f9d660e366e46cde5929a Mon Sep 17 00:00:00 2001 From: offish Date: Wed, 30 Dec 2020 12:10:03 +0100 Subject: [PATCH 2/5] Create api.py --- twitchtube/api.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 twitchtube/api.py diff --git a/twitchtube/api.py b/twitchtube/api.py new file mode 100644 index 0000000..b0d5a01 --- /dev/null +++ b/twitchtube/api.py @@ -0,0 +1,44 @@ +import json + +from .config import OAUTH_TOKEN, CLIENT_ID + +import requests + + +local = locals() + + +def request(endpoint: str, headers: dict, params: dict) -> dict: + return requests.get( + 'https://api.twitch.tv/' + endpoint, + headers = headers, + params = params + ) + + +def data(slug: str) -> dict: + return request( + 'helix/clips', + { + 'Authorization': f'Bearer {OAUTH_TOKEN}', + 'Client-Id': CLIENT_ID + }, + {'id': slug} + ) + + +def top_clips(headers: dict, params: dict) -> dict: + return request( + 'kraken/clips/top', + headers, + params + ) + + +def get(name: str, **args) -> dict: + response = local[name](**args) + + try: + return response.json() + except SyntaxError: + return response From deb1dc70950aaa609d5c16fcd8eaeb786e749f06 Mon Sep 17 00:00:00 2001 From: offish Date: Wed, 30 Dec 2020 12:10:34 +0100 Subject: [PATCH 3/5] Update clips.py --- twitchtube/clips.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/twitchtube/clips.py b/twitchtube/clips.py index 1e38cae..9177e67 100644 --- a/twitchtube/clips.py +++ b/twitchtube/clips.py @@ -5,6 +5,7 @@ from .config import CLIENT_ID, OAUTH_TOKEN, PARAMS, HEADERS from .logging import Log +from .api import get import requests @@ -17,16 +18,7 @@ def get_data(slug: str) -> dict: Gets the data from a given slug, returns a JSON respone from the Helix API endpoint """ - response = requests.get( - 'https://api.twitch.tv/helix/clips', - headers={ - 'Authorization': 'Bearer ' + OAUTH_TOKEN, - 'Client-Id': CLIENT_ID - }, - params={ - 'id': slug - } - ).json() + response = get('data', slug=slug) try: return response['data'][0] @@ -55,7 +47,7 @@ def get_clip_data(slug: str) -> tuple: return mp4_url, title - raise TypeError(f'Twitch didn\'t send what we wanted as response (could not find \'data\' in response). Response from /helix/ API endpoint:\n{clip_info}') + raise TypeError(f'We didn\'t receieve what we wanted. /helix/clips endpoint gave:\n{clip_info}') def get_progress(count, block_size, total_size) -> None: @@ -103,11 +95,7 @@ def get_clips(game: str, path: str) -> dict: PARAMS['game'] = game - response = requests.get( - 'https://api.twitch.tv/kraken/clips/top', - headers = HEADERS, - params = PARAMS - ).json() + response = get('top_clips', headers=HEADERS, params=PARAMS) if 'clips' in response: From 41134cb417f49ae7545a1aa714722ef3bf433b55 Mon Sep 17 00:00:00 2001 From: offish Date: Wed, 30 Dec 2020 12:11:00 +0100 Subject: [PATCH 4/5] Update logging.py --- twitchtube/logging.py | 1 + 1 file changed, 1 insertion(+) diff --git a/twitchtube/logging.py b/twitchtube/logging.py index 1362908..e3c81fa 100644 --- a/twitchtube/logging.py +++ b/twitchtube/logging.py @@ -12,6 +12,7 @@ def log(color: int, sort: str, text: str) -> None: Used for colored printing, does not return anything. """ time = datetime.now().time().strftime('%H:%M:%S') + text.encode(encoding='UTF-8', errors='ignore') print(f'{f.GREEN}twitchtube {f.WHITE}| {time} - {color + sort}{f.WHITE}: {text}{f.WHITE}') From 964d76351e0e1805d82a06059a95878caa548383 Mon Sep 17 00:00:00 2001 From: offish Date: Wed, 30 Dec 2020 12:13:52 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 37fd8df..5a1cd74 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,13 @@ [![Donate Steam](https://img.shields.io/badge/donate-steam-green.svg)](https://steamcommunity.com/tradeoffer/new/?partner=293059984&token=0-l_idZR) [![Donate PayPal](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/0ffish) - Automatically make video compilations of the most viewed Twitch clips and upload them to YouTube using Python 3. +## Example +![Screenshot](https://user-images.githubusercontent.com/30203217/103347433-4e5a7400-4a97-11eb-833a-0f5d59b0cd7e.png) + +[Here](https://www.youtube.com/channel/UCd0wttXr03lIcTLv38U5d-w) is an example of how the videos look like on YouTube. Majority of these videos are made using +this repo. Only a couple of titles and thumbnails have been changed. ## Installation Download the repo as ZIP and unzip it somewhere accessible. @@ -111,10 +115,6 @@ To run the script run this command (must be in the correct folder). python main.py ``` -## Example -[Here](https://www.youtube.com/channel/UCd0wttXr03lIcTLv38U5d-w) is an example of how the videos look like on YouTube. Majority of these videos are made using -this repo. Only a couple of titles and thumbnails have been changed. - ## Note I've only tested this script using Python 3.7.3, but should work with later versions.