Skip to main content

Python Sponsorblock

status-badge

python-sponsorblock logo

This is a wrapper for the sponsorblock api, enabling you to get the timestamps of sponsor segments from Youtube videos.

Installation

# using this gitea repository (recommended)
pip install --index-url https://gitea.elara.ws/api/packages/music-kraken/pypi/simple/ python-sponsorblock
# using pip
pip install python-sponsorblock

Why does this exist?

I decided against using the already existing sponsorblock.py for one main reason. It sometimes throws exceptions that do not belong to the project itself. An example for this are request exceptions. This is fine, but it shows a diverging philosophy from what I want to achieve with this project. I want to have an wrapper that just gets all data it can in a structured way. I don't want a library that does the requests for you, I want a library that gives you the data. I want to stress, this is not an attack on the sponsorblock.py project, it is just a different approach. My other "issue" with the sponsorblock.py project is, that it is way to complex. Thus fixing it would require more time than implementing the functionality I need from scratch.

I decided to catch all necessary exceptions, that cant be handled and either throw an exception inheriting from one base exception or return empty data.

Usage

Every relevant function can be found in the Sponsorblock class.

from python_sponsorblock import SponsorBlock
import requests

# all arguments are optional and are set to the default values in this example
sb = SponsorBlock(
    session=requests.Session(),    # a requests session object
    silent=False,    # throw exceptions or return empty data
    base_url="https://sponsor.ajay.app",    # the url of the sponsorblock api, make sure there is no trailing slash
)

print(sb.get_segments("https://yt.artemislena.eu/watch?v=w5GmDRW975g"))

You can import all of the exceptions that can be thrown like this:

from python_sponsorblock import exceptions

Get the Data

Because I don't need much functionality, I havent implemented a lot of api requests. The following list contains every function, that I plan to implement:

  • Get Segments

If you need more functionality, just raise an issue or create a pull request. Here is an overview for all api endpoints I could write wrappers for.

Every function that requires a video id as input, can also take a full url as input. The function will extract the video id from the url.

Get Segments

This function gets all segments of a video.

from python_sponsorblock import SponsorBlock, constants
from python_sponsorblock.constants import Segment

sb = SponsorBlock()
segments: List[Segment] = sb.get_segments("https://yt.artemislena.eu/watch?v=w5GmDRW975g")

Data Objects

All Data Classes, Enums and simmilar objects can be found in the constants module.

from python_sponsorblock import constants

Segment

This is most arguably the most important object in this library. It represents a segment of a video that is a sponsor segment.

from python_sponsorblock.exceptions import Segment, Category, ActionType

Segment(
    UUID="uuid",
    segment=(0.0, 10.0),
    category=Category.SPONSOR,
    videoDuration=100.0,
    actionType=ActionType.SKIP,
    locked=0,
    votes=10,
    description="This is a sponsor segment"
)

Enums (Types)

The enums are just representations of the types that are used in the sponsorblock api. This is the official documentation of the sponsor block types.

Metadata

Release files for python-sponsorblock 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-sponsorblock 0.1
File Size Uploaded Provenance Actions
python_sponsorblock-0.1.tar.gz 6.5 kB Without provenance Details for python_sponsorblock-0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-sponsorblock 0.1
File Interpreter ABI Platform Actions
python_sponsorblock-0.1-py3-none-any.whl Python 3 none any Details for python_sponsorblock-0.1-py3-none-any.whl

Total release size: 12.9 kB

Release files / python_sponsorblock-0.1.tar.gz

Download URL python_sponsorblock-0.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0a2a1f292bb3ca90e4ecc78b7f87740934a0e8bab7b7ff72830ef5ed667c62b7
BLAKE2b-256 checksum
How to use checksums
cdc4ffb27cdacded3da163198ae600f2c1e9eb44cd2f30e3e8c1db7669f5b6a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / python_sponsorblock-0.1-py3-none-any.whl

Download URL python_sponsorblock-0.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e35fc6e8a45923992c5d2453a1c5763fab4db9183a19a4cc0546cd8e735abdad
BLAKE2b-256 checksum
How to use checksums
5a8d7babefaaa49994d9548fb6804ae85263ce9218aebaf466c4aa33b7603d7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Security for python-sponsorblock 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page