Files
YouTube.js/src/platform/README.md
Daniel Wykerd 87ed3960ff refactor!: replace unnecessary classes with pure functions (#468)
* deps: update linkedom

* refactor!: remove YTNodeGenerator in favour of namespaced pure functions

BREAKING CHANGES:
- Removes `YTNodeGenerator` from `import('youtubei.js').Generator` and exposes its functions directly in `import('youtubei.js').Generator`

* refactor!: replace Parser class with pure functions

- Remove Parser class in favour of pure functions
- Merge duplicate classes `AppendContinuationItemsAction` into a single class
- Move continuation parsers into a seperate file
- Add better custom logging support to parser methods as per issue #460

* refactor!: replace Proto class with pure functions

* chore: update package-lock.json

* refactor!: replace FormatUtils with pure functions and JSX components

- Replace linkedom DASH manifest generation with a dependency free JSX implementation
- Remove FormatUtils class in favour of pure functions
- Remove DOMParser requirement
- Remove duplicate types

* refactor: implement changes from #462

* chore: lint

* fix: deno support

* fix: render valid xml document

* fix: wrong function call in DashUtils

* fix: typo in parser

Co-authored-by: LuanRT <luan.lrt4@gmail.com>

* refactor!: move streaming info logic into seperate function

This allows users to access the same data available in the dash manifest while also simplifying the manifest generation

* chore: lint

* refactor: readability improvements & fixes

Remove redundant getAudioTrackGroups
General readability improvements in StreamingInfo.ts
Share response object between `getBitrate` and `getMimeType` as to not make duplicate requests

* build: remove unnecessary step in deno build

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

* refactor: move types to `types` directory

* docs: add back comments lost during refactor

* chore: lint

---------

Co-authored-by: LuanRT <luan.lrt4@gmail.com>
Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
2023-08-18 06:49:58 -03:00

1.9 KiB

Platform Support

YouTube.js is designed to be as platform agnostic as possible. To achieve this, we require all platforms wishing to use YouTube.js to provide a few shims around the platform's native APIs.

Supported Platforms

We provide shims for the following platforms:

  • Modern Browsers
  • Node.js
  • Deno

Contributing Support for a New Platform

If you wish to bring YouTube.js to another platform, you will need to provide the following shims as specified by the PlatformShim type:

  • runtime: String name of the platform.
  • info: Object containing the package information read from package.json.
    • version: The version of the package.
    • bugs_url: The URL to the package's bug tracker.
    • repository_url: The URL to the package's repository.
  • server: Boolean indicating whether the platform is a server or not. Used for setting some additional headers not possible on a web browser.
  • Cache: Class that implements the ICache interface using the platform's native APIs.
  • sha1hash(data: string): Function that takes a string and returns a SHA-1 hash of it.
  • uuidv4(): Function that returns a UUIDv4 string.
  • eval(code: string, env: Record<string, VMPrimative>): Function to evaluate untrusted javascript script and return the result.
  • fetch: WHATWG Fetch API implementation.
  • Headers: Headers implementation.
  • Request: Request implementation.
  • Response: Response implementation.
  • FormData: FormData implementation.
  • File: File implementation.
  • ReadableStream: ReadableStream implementation.

An entry point for the platform should be added in the src/platform directory and should be formatted as follows:

import { Platform } from '../utils/Utils.js';
import { PlatformShim } from "../types";
import { ICache } from '../types/Cache.js';

class Cache implements ICache {
  // ...
}

Platform.load({
    // ... shims
});

export * from './lib.js';
import Innertube from './lib.js';
export default Innertube;