Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve support for dubbed content #293

Merged
merged 5 commits into from
Jan 27, 2023
Merged

Conversation

LuanRT
Copy link
Owner

@LuanRT LuanRT commented Jan 23, 2023

Description

The goal of this PR is to make it easier to identify and extract the audio tracks of videos with multilingual audio. I'm also considering adding an option to filter out unwanted formats from the DASH manifest and download function, which is why this is a WIP. (done)

Usage

import { Innertube, UniversalCache, YTNodes } from 'youtubei.js';

(async () => {
  const yt = await Innertube.create({ cache: new UniversalCache(), generate_session_locally: true });
  
  const search = await yt.search('mrbeast I Survived 50 Hours In Antarctica', { type: 'video' });
  const video_id = search.results?.firstOfType(YTNodes.Video)?.id as string;

  const info = await yt.getInfo(video_id);
  
  // Remove unwanted formats from the DASH manifest:
  console.log(info.toDash(undefined, (fmt) => {
    // Remove all non-English audio tracks (the data in info.captions.audio_tracks is quite helpful for this specifically)
    if (fmt.language && fmt.language !== 'en')
      return true;
    return false;
  }));

  console.log(info.toDash(undefined, (fmt) => {
    // Remove all dubbed audio tracks
    if (fmt.is_dubbed)
      return true;
    return false;
  }));

  // Download a specific audio track:
  const stream = await yt.download(video_id, {
    type: 'audio', language: 'hi' /** Default: 'original' */
  });

  // ...
})();

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

This will allow us to filter out unwanted languages.
And a simple language option to VideoInfo's download method.
@github-actions github-actions bot added the docs label Jan 27, 2023
@LuanRT LuanRT marked this pull request as ready for review January 27, 2023 02:29
@LuanRT LuanRT merged commit d6c5a9b into main Jan 27, 2023
@LuanRT LuanRT deleted the feat/dubbed-content-support branch January 27, 2023 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant