Skip to content

Commit

Permalink
add all time filter and black format
Browse files Browse the repository at this point in the history
  • Loading branch information
offish authored Sep 21, 2021
1 parent 887780d commit 05fa216
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions twitchtube/clips.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ def download_clip(clip: str, basepath: str, oauth_token: str, client_id: str) ->


def get_clips(
blacklist: list,
category: str,
id_: str,
name: str,
path: str,
seconds: float,
ids: list,
client_id: str,
oauth_token: str,
period: int,
language: str,
limit: int,
blacklist: list,
category: str,
id_: str,
name: str,
path: str,
seconds: float,
ids: list,
client_id: str,
oauth_token: str,
period: int,
language: str,
limit: int,
) -> (dict, list, list):
"""
Gets the top clips for given game, returns JSON response
Expand All @@ -100,18 +100,20 @@ def get_clips(

# params = {"period": period, "limit": limit}
params = {
"ended_at": datetime.datetime.now(datetime.timezone.utc).isoformat(),
"started_at": (
datetime.datetime.now(datetime.timezone.utc)
- datetime.timedelta(hours=period)
).isoformat(),
"first": limit,
}

if category == "channel":
params["broadcaster_id"] = id_
else:
params["game_id"] = id_
if period:
params = {
**params,
"ended_at": datetime.datetime.now(datetime.timezone.utc).isoformat(),
"started_at": (
datetime.datetime.now(datetime.timezone.utc)
- datetime.timedelta(hours=period)
).isoformat(),
}

params["broadcaster_id" if category == "channel" else "game_id"] = id_

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

Expand Down Expand Up @@ -155,9 +157,9 @@ def get_clips(
break

if (
clip_id not in ids
and not is_blacklisted(clip, formatted_blacklist)
and (language == clip["language"] or not language)
clip_id not in ids
and not is_blacklisted(clip, formatted_blacklist)
and (language == clip["language"] or not language)
):
data[clip["id"]] = {
"url": clip["url"],
Expand All @@ -182,10 +184,7 @@ def download_clips(data: dict, path: str, oauth_token: str, client_id: str) -> l

for clip, value in data.items():
download_clip(value["url"], path, oauth_token, client_id)
names.append(data[clip]["display_name"])

name = data[clip]["display_name"]

names.append(name)

log.info(f"Downloaded {len(data)} clips from this batch.\n")
log.info(f"Downloaded {len(data)} clips from this batch\n")
return names

0 comments on commit 05fa216

Please sign in to comment.