Skip to main content

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

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_sponsorblock-0.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

python_sponsorblock-0.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file python_sponsorblock-0.1.tar.gz.

File metadata

  • Download URL: python_sponsorblock-0.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for python_sponsorblock-0.1.tar.gz
Algorithm Hash digest
SHA256 0a2a1f292bb3ca90e4ecc78b7f87740934a0e8bab7b7ff72830ef5ed667c62b7
MD5 7fe412909210c9808f810879614f0e11
BLAKE2b-256 cdc4ffb27cdacded3da163198ae600f2c1e9eb44cd2f30e3e8c1db7669f5b6a4

See more details on using hashes here.

File details

Details for the file python_sponsorblock-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_sponsorblock-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e35fc6e8a45923992c5d2453a1c5763fab4db9183a19a4cc0546cd8e735abdad
MD5 a560bfef82b8a1634c32a8a9a7a4a486
BLAKE2b-256 5a8d7babefaaa49994d9548fb6804ae85263ce9218aebaf466c4aa33b7603d7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page