Compare commits

...

4 Commits

Author SHA1 Message Date
dd3714f8c8 feat: fetches per default every category
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-05-13 13:53:36 +02:00
760e12889c Merge pull request 'ci: add pipeline' (#1) from ci/add-pipeline into main
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #1
2024-04-26 09:48:07 +00:00
7d14fef3f5 docs: add ci badge
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful
2024-04-25 19:56:55 -07:00
65b1d17253 docs: fix command in README 2024-04-25 19:56:08 -07:00
2 changed files with 18 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
# Python Sponsorblock # Python Sponsorblock
[![status-badge](https://ci.elara.ws/api/badges/61/status.svg)](https://ci.elara.ws/repos/61)
<img src="https://gitea.elara.ws/music-kraken/python-sponsorblock/raw/branch/main/assets/logo.svg" width=300 alt="python-sponsorblock logo"/> <img src="https://gitea.elara.ws/music-kraken/python-sponsorblock/raw/branch/main/assets/logo.svg" width=300 alt="python-sponsorblock logo"/>
This is a wrapper for the sponsorblock api, enabling you to get the timestamps of sponsor segments from Youtube videos. This is a wrapper for the sponsorblock api, enabling you to get the timestamps of sponsor segments from Youtube videos.
@@ -8,7 +10,7 @@ This is a wrapper for the sponsorblock api, enabling you to get the timestamps o
```bash ```bash
# using this gitea repository (recommended) # using this gitea repository (recommended)
pip install --index-url https://gitea.elara.ws/api/packages/music-kraken/pypi/simple/ music-kraken pip install --index-url https://gitea.elara.ws/api/packages/music-kraken/pypi/simple/ python-sponsorblock
``` ```
```bash ```bash

View File

@@ -7,7 +7,7 @@ import json
from functools import wraps from functools import wraps
from .exceptions import SponsorBlockError, SponsorBlockIdNotFoundError, ReturnDefault from .exceptions import SponsorBlockError, SponsorBlockIdNotFoundError, ReturnDefault
from .constants import Segment from .constants import Segment, Category
def error_handling(default: Any) -> Callable: def error_handling(default: Any) -> Callable:
@@ -99,14 +99,25 @@ class SponsorBlock:
return data return data
@error_handling(default=[]) @error_handling(default=[])
def get_segments(self, video: str) -> List[Segment]: def get_segments(self, video: str, categories: List[Category] = None) -> List[Segment]:
"""
Retrieves the skip segments for a given video.
Args:
video (str): The video identifier.
categories (List[Category], optional): A list of categories to filter the skip segments. Defaults to all categories.
Returns:
List[Segment]: A list of skip segments for the given video.
"""
video_id = self._get_video_id(video) video_id = self._get_video_id(video)
categories = categories or [c for c in Category]
# build query parameters # build query parameters
query = { query = {
"videoID": video_id "videoID": video_id,
"categories": json.dumps([c.value for c in categories])
} }
print(query)
r = self._request(method="GET", endpoint="/api/skipSegments?" + urlencode(query)) r = self._request(method="GET", endpoint="/api/skipSegments?" + urlencode(query))
return [constants.Segment(**d) for d in r] return [constants.Segment(**d) for d in r]