Skip to content

Commit

Permalink
v1.6.3
Browse files Browse the repository at this point in the history
v1.6.3
  • Loading branch information
offish authored May 27, 2021
2 parents ec27620 + 5e6f031 commit b912c39
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 68 deletions.
101 changes: 50 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,56 @@ while True:
sleep(24 * 60 * 60) # make a video daily
```

These are all the parameters `make_video` takes
```python
def make_video(
data: list = DATA,
blacklist: list = BLACKLIST,
# other
path: str = get_path(),
check_version: bool = CHECK_VERSION,
# twitch
client_id: str = CLIENT_ID,
oauth_token: str = OAUTH_TOKEN,
period: str = PERIOD,
language: str = LANGUAGE,
limit: int = LIMIT,
# selenium
profile_path: str = ROOT_PROFILE_PATH,
sleep: int = SLEEP,
headless: bool = HEADLESS,
debug: bool = DEBUG,
# video options
render_video: bool = RENDER_VIDEO,
file_name: str = FILE_NAME,
resolution: tuple = RESOLUTION,
frames: int = FRAMES,
video_length: float = VIDEO_LENGTH,
resize_clips: bool = RESIZE_CLIPS,
enable_intro: bool = ENABLE_INTRO,
resize_intro: bool = RESIZE_INTRO,
intro_path: str = INTRO_FILE_PATH,
enable_transition: bool = ENABLE_TRANSITION,
resize_transition: bool = RESIZE_TRANSITION,
transition_path: str = TRANSITION_FILE_PATH,
enable_outro: bool = ENABLE_OUTRO,
resize_outro: bool = RESIZE_OUTRO,
outro_path: str = OUTRO_FILE_PATH,
# other options
save_file: bool = SAVE_TO_FILE,
save_file_name: str = SAVE_FILE_NAME,
upload_video: bool = UPLOAD_TO_YOUTUBE,
delete_clips: bool = DELETE_CLIPS,
# youtube
title: str = TITLE,
description: str = DESCRIPTION,
thumbnail: str = THUMBNAIL,
tags: list = TAGS,
) -> None:
...
```
Information about every parameter can be found in [`config.py`](twitchtube/config.py).

## Installation
Download the repo as ZIP and unzip it somewhere accessible, or use git.

Expand Down Expand Up @@ -117,57 +167,6 @@ Copy the "Root Directory" path of that profile and paste it into the `ROOT_PROFI

You can now save your `config`.

### Parameters
These are all the parameters `make_video` takes
```python
def make_video(
# required
data: list = DATA,
# other
path: str = get_path(),
check_version: bool = CHECK_VERSION,
# twitch
client_id: str = CLIENT_ID,
oauth_token: str = OAUTH_TOKEN,
period: str = PERIOD,
language: str = LANGUAGE,
limit: int = LIMIT,
# selenium
profile_path: str = ROOT_PROFILE_PATH,
sleep: int = SLEEP,
headless: bool = HEADLESS,
debug: bool = DEBUG,
# video options
render_video: bool = RENDER_VIDEO,
file_name: str = FILE_NAME,
resolution: tuple = RESOLUTION,
frames: int = FRAMES,
video_length: float = VIDEO_LENGTH,
resize_clips: bool = RESIZE_CLIPS,
enable_intro: bool = ENABLE_INTRO,
resize_intro: bool = RESIZE_INTRO,
intro_path: str = INTRO_FILE_PATH,
enable_transition: bool = ENABLE_TRANSITION,
resize_transition: bool = RESIZE_TRANSITION,
transition_path: str = TRANSITION_FILE_PATH,
enable_outro: bool = ENABLE_OUTRO,
resize_outro: bool = RESIZE_OUTRO,
outro_path: str = OUTRO_FILE_PATH,
# other options
save_file: bool = SAVE_TO_FILE,
save_file_name: str = SAVE_FILE_NAME,
upload_video: bool = UPLOAD_TO_YOUTUBE,
delete_clips: bool = DELETE_CLIPS,
# youtube
title: str = TITLE,
description: str = DESCRIPTION,
thumbnail: str = THUMBNAIL,
tags: list = TAGS,
) -> None:
...
```
Information about every parameter can be found in [`config.py`](twitchtube/config.py).

## Troubleshooting
### Uploading
If you're having issues uploading try to update [opplast](https://github.com/offish/opplast).
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def str_to_bool(value):


parser.add_argument("--data", type=str, help="")
parser.add_argument("--blacklist", 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="")
Expand Down Expand Up @@ -62,7 +63,7 @@ def str_to_bool(value):
try:
if not arg == None:

if key == "tags" or key == "data":
if key == "tags" or key == "data" or key == "blacklist":
arg = arg.split(", ")

if key == "resolution":
Expand Down
2 changes: 1 addition & 1 deletion twitchtube/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__title__ = "twitchtube"
__author__ = "offish"
__license__ = "MIT"
__version__ = "1.6.2"
__version__ = "1.6.3"
12 changes: 9 additions & 3 deletions twitchtube/clips.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re

from .logging import Log
from .utils import format_blacklist, is_blacklisted
from .api import get


Expand Down Expand Up @@ -82,6 +83,7 @@ def download_clip(clip: str, basepath: str, oauth_token: str, client_id: str) ->


def get_clips(
blacklist: list,
category: str,
name: str,
path: str,
Expand Down Expand Up @@ -109,12 +111,15 @@ def get_clips(
if language:
params["language"] = language

log.info(f"Getting clips for {category} {name}")

response = get("top_clips", headers=headers, params=params)

if not response.get("clips"):
if response.get("error") == "Internal Server Error":
# the error is twitch's fault, we try again
get_clips(
blacklist,
category,
name,
path,
Expand All @@ -132,16 +137,17 @@ def get_clips(
f'Did not find "clips" in response {response} for {category} {name}, period: {period} language: {language}'
)

formatted_blacklist = format_blacklist(blacklist)

if "clips" in response:
for clip in response["clips"]:
tracking_id = clip["tracking_id"]
duration = clip["duration"]

if seconds <= 0.0:
break

tracking_id = clip["tracking_id"]

if not tracking_id in ids:
if not tracking_id in ids and not is_blacklisted(clip, formatted_blacklist):
data[clip["tracking_id"]] = {
"url": "https://clips.twitch.tv/" + clip["slug"],
"title": clip["title"],
Expand Down
4 changes: 4 additions & 0 deletions twitchtube/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
)

DATA = ["c xQcOW", "c Trainwreckstv", "g Just Chatting"]
BLACKLIST = [
"c ludwig",
"g Pools, Hot Tubs, and Beaches",
] # channels/games you dont want to be included in the video

# twitch
CLIENT_ID = "" # Twitch Client ID
Expand Down
58 changes: 58 additions & 0 deletions twitchtube/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from string import ascii_lowercase, digits
from random import choice

from .exceptions import InvalidCategory
from .config import CLIP_PATH

from requests import get
Expand Down Expand Up @@ -53,3 +54,60 @@ def create_video_config(
"thumbnail": thumbnail,
"tags": tags,
}


def get_category(category: str) -> str:
if category == "g" or category == "game":
return "game"

if category == "c" or category == "channel":
return "channel"

raise InvalidCategory(
category + ' is not supported. Use "g", "game", "c" or "channel"'
)


def get_category_and_name(entry: str) -> (str, str):
_category, name = entry.split(" ", 1)
category = get_category(_category)

return (category, name)


def remove_blacklisted(data: list, blacklist: list) -> (bool, list):
did_remove = False

for d in data:
d_category, d_name = get_category_and_name(d)

for b in blacklist:
b_category, b_name = get_category_and_name(b)

if b_category == d_category and b_name == d_name:
data.remove(d)
did_remove = True

return (did_remove, data)


def format_blacklist(blacklist: list) -> list:
formatted = []

for b in blacklist:
category, name = get_category_and_name(b)
formatted.append(category + " " + name)

return formatted


def is_blacklisted(clip: dict, blacklist: list) -> bool:
if "broadcaster" in clip and clip["broadcaster"].get("name"):
if "channel " + clip["broadcaster"]["name"] in blacklist:
return True

if clip.get("game"):
if "game " + clip["game"] in blacklist:
return True

return False
22 changes: 10 additions & 12 deletions twitchtube/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .exceptions import *
from .logging import Log
from .config import *
from .utils import get_path, create_video_config, get_current_version
from .utils import *
from .clips import get_clips, download_clips

from moviepy.editor import VideoFileClip, concatenate_videoclips
Expand All @@ -20,6 +20,7 @@
def make_video(
# required
data: list = DATA,
blacklist: list = BLACKLIST,
# other
path: str = get_path(),
check_version: bool = CHECK_VERSION,
Expand Down Expand Up @@ -104,22 +105,19 @@ def make_video(
if os.path.exists(f"{path}/{file_name}.mp4"):
raise VideoPathAlreadyExists("specify another path")

# first we get all the clips for every entry in data
for entry in data:
category, name = entry.split(" ", 1)
if category == "g":
category = "game"
did_remove, data = remove_blacklisted(data, blacklist)

if category == "c":
category = "channel"
if did_remove:
log.info("Data included blacklisted content and was removed")

if not (category == "game" or category == "channel"):
raise InvalidCategory(
category + ' is not supported. Use "g", "game", "c" or "channel"'
)
# first we get all the clips for every entry in data
# some bug here with loop or something
for entry in data:
category, name = get_category_and_name(entry)

# so we dont add the same clip twice
new_clips, new_ids, new_titles = get_clips(
blacklist,
category,
name,
path,
Expand Down

0 comments on commit b912c39

Please sign in to comment.