Skip to content

Scripting with Streamrip v2

nani8ot edited this page Dec 8, 2024 · 3 revisions

All downloads in streamrip go through the same pipeline. Items start with some basic info, such as its type, source, and ID. Then, they are resolved, and then downloads. The behavior of streamrip can be configured by modifying the Config object.

Getting started

We can get started with the client submodule, which handles API calls to each of the services. This tutorial will use Qobuz, but the code can be swapped out for any of the sources.

from streamrip.client import QobuzClient
from streamrip.config import Config

config = Config.defaults()
config.session.qobuz.email_or_userid = "YOUR_EMAIL"
config.session.qobuz.password_or_token = "YOUR_PASSWORD"
c = QobuzClient(config)

So far, we haven't made any requests yet. In order to do so, we need to login to the service. Note that all of the async code shown needs to be wrapped in an async function in a script. I'm going to omit this for brevity.

await c.login()
print(c.logged_in) # True

Now, we can request any type of media we want

my_album = await c.get_metadata("123456", "album")
print(my_album) # should print a giant dictionary with metadata

However, we usually don't interact with the client directly because theres a lot of intricacy related to parsing that we abstract away. Instead, we use the Pending and Media types to handle all the requests and downloads seamlessly.

# same thing as before
from streamrip.media import Album, PendingAlbum
from streamrip.db import Dummy, Database
db = Database(downloads=Dummy(), failed=Dummy())
p = PendingAlbum("123456", c, config, db)

This doesn't send any requests yet. To get the metadata, we "resolve" the Pending item into a Media, in this case Album.

resolved_album = await p.resolve()
print(resolved_album.meta) # print metadata

This is a source agnostic form that contains all the information related to the album. We can download it by running

await resolved_album.rip()