From 95bbe2066b768d912a384f0475355f2008350b07 Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 2 May 2021 20:51:51 +0200 Subject: [PATCH 1/8] Update README.md --- README.md | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 64bd2c4..3233908 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,28 @@ Automatically make video compilations of the most viewed Twitch clips, and uploa ## Usage Example of making a video through terminal ```python -python main.py "g Just Chatting, c xQcOW, c Trainwreckstv" --duration 10.5 --resolution 1080 1920 --title "Top Just Chatting, xQc and Trainwrecks Twitch Clips Today" --tags "xqc, trainwrecks, twitch clips, xqc twitch, trainwrecks twitch" +python main.py --data "g Just Chatting, c xQcOW, c Trainwreckstv" --client_id "1hq8ektpki36w5kn37mluioungyqjo" --oauth_token "9f5einm9qtp0bj4m9l1ykevpwdn98o" --duration 10.5 --resolution 1080 1920 --title "Top Just Chatting, xQc and Trainwrecks Twitch Clips Today" --tags "xqc, trainwrecks, twitch clips, xqc twitch, trainwrecks twitch" ``` -`g` indicates game, `c` indicates channel. You can also use `channel` and or `game`. +`g` indicates game, `c` indicates channel. You can also use `channel` and `game`. -The only parameter required is `data`. **Every other parameter that is not specified, will default to an assigned value in [`config.py`](twitchtube/config.py).** +**Every parameter that is not specified, will default to an assigned value in [`config.py`](twitchtube/config.py).** -Example of minium required input: +Example of running with only default values: +```text +python main.py +``` + +[`config.py`](twitchtube/config.py): ```python -python main.py "channel maskenissen" +DATA = ["channel maskenissen"] + +CLIENT_ID = "1hq8ektpki36w5kn37mluioungyqjo" # Twitch Client ID +OAUTH_TOKEN = "9f5einm9qtp0bj4m9l1ykevpwdn98o" # Twitch OAuth Token +PERIOD = "day" # day, week, month or all +LANGUAGE = "en" # en, es, th etc. +LIMIT = 100 # 1-100 +... ``` You can also run the bot from a Python file like [`example.py`](example.py) @@ -33,13 +45,13 @@ from twitchtube.video import make_video while True: make_video( - ["channel xQcOW", "game Just Chatting"], + data=["channel xQcOW", "game Just Chatting"], client_id="1hq8ektpki36w5kn37mluioungyqjo", # example client id (fake) oauth_token="9f5einm9qtp0bj4m9l1ykevpwdn98o", # example token (fake) - video_length=10.5, - resolution=(1080, 1920), + video_length=10.5, # minutes as float + resolution=(1080, 1920), # height x width frames=60, - period="day", + period="day", # most viewed clips today ) sleep(24 * 60 * 60) # make a video daily ``` @@ -108,7 +120,7 @@ These are all the parameters `make_video` takes ```python def make_video( # required - data: list, + data: list = DATA, # other path: str = get_path(), check_version: bool = CHECK_VERSION, From 9b894f51277834fa909ffe7a8d4eeef496eb4606 Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 2 May 2021 20:52:05 +0200 Subject: [PATCH 2/8] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 726eda8..4181ea7 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ def str_to_bool(value): raise argparse.ArgumentTypeError("Boolean value expected.") -parser.add_argument("data", type=str, help="") +parser.add_argument("--data", type=str, help="") parser.add_argument("--path", type=str, help="") parser.add_argument("--check_version", type=str_to_bool, help="") parser.add_argument("--client_id", type=str, help="") From aa507f16a3312ec18e7c6edf0282999fb4b48860 Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 2 May 2021 20:52:19 +0200 Subject: [PATCH 3/8] Update example.py --- example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.py b/example.py index 4f5749c..115c483 100644 --- a/example.py +++ b/example.py @@ -2,7 +2,7 @@ make_video( - ["c xQcOW", "game Just Chatting"], + data=["c xQcOW", "game Just Chatting"], client_id="1hq8ektpki36w5kn37mluioungyqjo", # example client id (fake) oauth_token="9f5einm9qtp0bj4m9l1ykevpwdn98o", # example token (fake) video_length=10.5, From ca35d2aa700351250aeaa56108b67c67a17485ec Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 2 May 2021 20:53:18 +0200 Subject: [PATCH 4/8] Update video.py #46 #47 --- twitchtube/video.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/twitchtube/video.py b/twitchtube/video.py index 4c771fc..273b79a 100644 --- a/twitchtube/video.py +++ b/twitchtube/video.py @@ -13,12 +13,13 @@ from moviepy.editor import VideoFileClip, concatenate_videoclips from opplast import Upload, __version__ as opplast_version + log = Log() # add language as param def make_video( # required - data: list, + data: list = DATA, # other path: str = get_path(), check_version: bool = CHECK_VERSION, @@ -87,6 +88,7 @@ def make_video( except Exception as e: print(e) + titles = [] clips = [] names = [] ids = [] @@ -117,7 +119,7 @@ def make_video( ) # so we dont add the same clip twice - new_clips, new_ids = get_clips( + new_clips, new_ids, new_titles = get_clips( category, name, path, @@ -130,8 +132,13 @@ def make_video( limit, ) - ids += new_ids - clips.append(new_clips) + if new_clips: + ids += new_ids + titles += new_titles + clips.append(new_clips) + + if not clips: + raise NoClipsFound("Did not find any clips") Path(path).mkdir(parents=True, exist_ok=True) @@ -143,6 +150,9 @@ def make_video( # remove duplicate names names = list(dict.fromkeys(names)) + if not title: + title = titles[0] + config = create_video_config( path, file_name, title, description, thumbnail, tags, names ) @@ -196,6 +206,8 @@ def make_video( except Exception as e: log.clip(f"Could not delete {file} because {e}") + log.info("Done!") + def get_clip_paths(path: str) -> list: """ From 5959c2c73c2bda212037bb9caae04396a0bc0f45 Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 2 May 2021 20:53:59 +0200 Subject: [PATCH 5/8] Update exceptions.py --- twitchtube/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitchtube/exceptions.py b/twitchtube/exceptions.py index 2cb47cd..0c28f80 100644 --- a/twitchtube/exceptions.py +++ b/twitchtube/exceptions.py @@ -6,5 +6,5 @@ class VideoPathAlreadyExists(Exception): pass -class WrongKrakenResponse(Exception): +class NoClipsFound(Exception): pass From 02170d4c28d5e7bac0020dd18d675a76bcff2cbd Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 2 May 2021 20:54:39 +0200 Subject: [PATCH 6/8] Update config.py --- twitchtube/config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/twitchtube/config.py b/twitchtube/config.py index e615877..947dc30 100644 --- a/twitchtube/config.py +++ b/twitchtube/config.py @@ -11,6 +11,8 @@ True # see if youre running the latest version of twitchtube and opplast ) +DATA = ["c xQcOW", "c Trainwreckstv", "g Just Chatting"] + # twitch CLIENT_ID = "" # Twitch Client ID OAUTH_TOKEN = "" # Twitch OAuth Token @@ -55,7 +57,7 @@ # youtube -TITLE = "" # youtube title +TITLE = "" # youtube title, leave empty for the first clip's title DESCRIPTION = ( "Streamers in this video:\n" # youtube description, streamers will be added ) From e0483ac723bd1d6054435d99bcab297a4638c52f Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 2 May 2021 20:55:12 +0200 Subject: [PATCH 7/8] Update clips.py --- twitchtube/clips.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/twitchtube/clips.py b/twitchtube/clips.py index b5c3de2..e1831fe 100644 --- a/twitchtube/clips.py +++ b/twitchtube/clips.py @@ -3,7 +3,6 @@ import urllib.request import re -from .exceptions import WrongKrakenResponse from .logging import Log from .api import get @@ -93,13 +92,14 @@ def get_clips( period: str, language: str, limit: int, -) -> (dict, list): +) -> (dict, list, list): """ Gets the top clips for given game, returns JSON response from the Kraken API endpoint. """ data = {} new_ids = [] + new_titles = [] headers = {"Accept": "application/vnd.twitchtv.v5+json", "Client-ID": client_id} @@ -128,28 +128,33 @@ def get_clips( ) else: - raise WrongKrakenResponse(f"Could not find 'clips' in response. {response}") + log.warn( + f'Did not find "clips" in response {response} for {category} {name}, period: {period} language: {language}' + ) - for clip in response["clips"]: - duration = clip["duration"] + if "clips" in response: + for clip in response["clips"]: + duration = clip["duration"] - if seconds <= 0.0: - break + if seconds <= 0.0: + break - tracking_id = clip["tracking_id"] + tracking_id = clip["tracking_id"] - if not tracking_id in ids: - data[clip["tracking_id"]] = { - "url": "https://clips.twitch.tv/" + clip["slug"], - "title": clip["title"], - "display_name": clip["broadcaster"]["display_name"], - "duration": duration, - } - new_ids.append(tracking_id) + if not tracking_id in ids: + data[clip["tracking_id"]] = { + "url": "https://clips.twitch.tv/" + clip["slug"], + "title": clip["title"], + "display_name": clip["broadcaster"]["display_name"], + "duration": duration, + } + new_ids.append(tracking_id) + new_titles.append(clip["title"]) + seconds -= duration - seconds -= duration + return (data, new_ids, new_titles) - return (data, new_ids) + return ({}, [], []) def download_clips(data: dict, path: str, oauth_token: str, client_id: str) -> list: From ee9ac3c45d2c8ec92de0aa9b49f6a844b026c69c Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 2 May 2021 20:55:35 +0200 Subject: [PATCH 8/8] 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 f066db3..81140c1 100644 --- a/twitchtube/__init__.py +++ b/twitchtube/__init__.py @@ -1,4 +1,4 @@ __title__ = "twitchtube" __author__ = "offish" __license__ = "MIT" -__version__ = "1.6.1" +__version__ = "1.6.2"