2.0.0 • Published 10 days ago

babbling v2.0.0

Weekly downloads
91
License
ISC
Repository
github
Last release
10 days ago

Babbling npm

Cast Streaming service videos to Chromecast

What?

Babbling, as in babbling brook, refers to the streaming services it helps bridge to your Chromecast. It's also a bit of a play on the Tower of Babel, because it "speaks" to many different services.

No, but seriously, what?

Babbling aims to provide a simple, promise-based API (and also a CLI app!) for programmatically casting media from various streaming services to a Chromecast device.

Currently, Babbling supports casting videos from:

Typescript/Javascript

Each app works a bit differently and has different capabilities, so you interact with them slightly differently—though we do strive for some consistency. For example, Youtube supports specifying the name of the device you're connecting with, so we support that option:

const device = new ChromecastDevice("Living Room TV");
const yt = await device.openApp(YoutubeApp, {
    deviceName: "Home",
});
await yt.play("video-id");

Please see the specific app implementations for details about each's specific API.

An easier option

Most people won't be interested in the specific app implementations. If you're such a person, Babbling offers a simpler interface:

const player = (await PlayerBuilder.autoInflate())
    .addDevice(new ChromecastDevice("Living Room TV"))
    .build();
await player.playUrl("https://www.youtube.com/watch?v=byva0hOj8CU&list=PL1tiwbzkOjQxD0jjAE7PsWoaCrs0EkBH2");

As of writing, all the apps currently supported also support the Player interface, allowing you to just copy the URL of the thing you want to watch and paste it in, whether it's for a Series, a Playlist, or a specific Episode. In addition to URL-based playback, most apps allow you to search for what you want—see the full Player API section below.

This does gloss over something slightly, which is authenticating each app. While Youtube can work fine without auth, if you have Youtube RED and don't want to see ads—or if you want to watch personal playlists, or keep track of watch progress in videos—you'll want to be authenticated.

Authentication

You're welcome to do this by hand—just see each specific app for their options—but Babbling comes with batteries included to make this simpler for you. If you install Babbling globally (npm i -g babbling) you'll get a command-line tool that can automatically pull all the cookies and other auth info needed for each app from the Chrome browser. Just close Chrome (the database in which HBO Go stores its data is very insistent on only one app accessing it at a time) and run babbling auto-auth. That will enable the autoInflate() function mentioned above, and also allow you to use babbling cast <url>!

Amazon Video

Authentication for Amazon Video is a bit of a special case, requiring you to login with your email and password. We do not store your password, but we need to login in a specific way to be able to communicate with the Amazon Video Chromecast app.

This can be performed easily with the Babbling command-line tool:

babbling auth:prime <your@amazon-login>

You will be prompted for your password, and, if everything goes well, you well then be able to use babbling cast <url>, etc., for Amazon videos!

Youtube

The auto-auth tool will work for a time with Youtube, but Google's cookies have a fairly short shelf-life. If you want to authenticate Babbling to be able to cast Youtube videos for a longer period of time without having to constantly re-run auto-auth, we've got a tool for that, too:

babbling auth:youtube

This will open a Chrome browser for authenticating. The mechanism here is based on that used for YakYak, and has the same caveats:

babbling may show up as iOS Device and Google may alert you that "some iOS Device is trying to use your account". This is normal as babbling is an unofficial client and it mimics the behaviour of an iOS device in order to establish a communication with Youtube APIs.

Player API

You've seen the playUrl tool above, but here's everything the Player lets you do:

playUrl(url: string, opts: IPlayableOptions = {}): Promise

  • url: The URL of the video or series you want to play
  • opts: An optional options map:
    • resume: boolean: if false, will not attempt to resume plaback

Play a video or series by its URL, as found in a browser. Returns a Promise that resolves when the video has been started.

play(result: IQueryResult, opts: IPlayableOptions = {}): Promise

  • result: A Result object
  • opts: As above

Play a search result from one of the other query methods. Returns a Promise that resolves when the video has been started.

findEpisodeFor(item: IQueryResult, query: IEpisodeQuery): Promise<IEpisodeQueryResult | undefined>

  • item: A Result object
  • query: An Episode Query object:
    • episodeIndex: 0-based index within a season
    • seasonIndex: 0-based season index

Try to find an episode for the given Result matching the given query. The result, if not-undefined, can be used with play(). The Promise will resolve to undefined if the item is not a series, or there is no such season/episode combination.

queryByTitle(title: string, onError?: AppSpecificErrorHandler): AsyncIterable<IQueryResult>

  • title: The media item title you want to play
  • onError: A handler when one app encounters an error:
    • fn(app: string, e: Error)
    • If omitted, every error will be thrown; you may instead want to simply log the error so errors in one app don't crash the whole query

Look for media items (eg series or movies) by their title. Returns an AsyncIterable of Query Results, to be consumed as eg:

for await (const result of p.queryByTitle("firefly")) {
    // do something with `result`
}

queryEpisodeForTitle(title: string, query: IEpisodeQuery, onError: AppSpecificErrorHandler): AsyncIterable<IEpisodeQueryResult>

This method is sort of a combination of queryByTitle and findEpisodeFor (see above), and the arguments are the same as for those methods. Some apps can perform this query efficiently, and it is the most common use-case, but others will be implemented naively as a composition of queryByTitle and findEpisodeFor.

getRecommendationsMap(): Promise<Map<string, AsyncIterable<IQueryResult>>>

Returns a map whose keys are app names (eg: "HuluApp") and the values are AsyncIterable objects in the same format as for queryByTitle. The query results returned by this method represent app-provided media recommendations.

queryRecommended(onError?: AppSpecificErrorHandler): AsyncIterable<IQueryResult>

Returns an AsyncIterable of recommendations as returned from getRecommendationsMap that has results from all the different apps interleaved together.

2.0.0

10 days ago

1.24.3

10 days ago

1.24.2

13 days ago

1.24.1

2 months ago

1.24.0

2 months ago

1.23.7

3 months ago

1.23.6

3 months ago

1.23.5

3 months ago

1.23.4

4 months ago

1.23.3

4 months ago

1.23.2

5 months ago

1.23.1

5 months ago

1.23.0

5 months ago

1.22.0

9 months ago

1.21.0

10 months ago

1.20.0

12 months ago

1.19.0

1 year ago

1.18.1

1 year ago

1.18.0

1 year ago

1.17.2

1 year ago

1.17.1

1 year ago

1.17.0

1 year ago

1.16.0

1 year ago

1.15.1

1 year ago

1.15.0

1 year ago

1.14.1

1 year ago

1.14.0

1 year ago

1.13.0

1 year ago

1.12.0

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.9.2

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago