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

Support multiple audio tracks and AV1 for Invidious by using the local API DASH manifest generator #3942

Merged
merged 7 commits into from
Sep 25, 2023

Conversation

absidue
Copy link
Member

@absidue absidue commented Aug 25, 2023

Support multiple audio tracks and AV1 for Invidious by using the local API DASH manifest generator

Pull Request Type

  • Bugfix
  • Feature Implementation

Related issue

closes #3382

Description

Currently Invidious doesn't support multiple audio tracks in their API response or DASH manifest, they are also missing the important fields width, height for all video streams and fps and qualityLabel for the AV1 formats in their API responses.

This pull request adds multiple audio track support for Invidious, without requiring any changes on their side, a side effect of that ,is that we can also support AV1 formats properly for Invidious.

This pull request takes advantage of YouTube.js exposing its DASH manifest generator and its ability to parse language and role information from the streaming URLs. Unfortunately due to the missing fields in the API responses (mentioned in the first paragraph), this pull request still makes a request to Invidious' manifest endpoint, so that it can extract the height, width and fps from it, for the locally generated manifest. As video.js was already making that request before, this doesn't cause any extra load on Invidious instances.

YouTube.js usually deciphers the formats as part of the manifest generation process, as that requires sending a request to YouTube to check if there is a new player and a second one to fetch it if there is (would use the one from the cache if it's the same one), I decided to make the deciphering a no-op while generating the Invidious manifest (it will still decipher for the local API one).
While we could use the deciphering to unthrottle age-restricted videos on Invidious (Invidious doesn't do its own deciphering and the bypass doesn't use the android endpoint, with the magic params that bypass throttling), I decided against it, to avoid making the extra requests. If unthrottling those is still desirable, I could see if there is a way to detect age restricted videos on Invidious and implement deciphering just for those ones (only if backend fallback is enabled of course) in a follow-up pull request.

Testing

dubbed and descriptive audio tracks: https://youtu.be/Kn56bMZ9OE8 (dubbed at 1:35, descriptive at 1:40)
audio tracks in multiple languages: https://youtu.be/jObOjhUkf50
AV1 formats: https://youtu.be/njX2bu-_Vw4

Also test proxying if you can find an Invidious instance it works on.

Desktop

  • OS: Windows
  • OS Version: 10
  • FreeTube version: 0.19.0

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) August 25, 2023 17:49
@github-actions github-actions bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Aug 25, 2023
PikachuEXE
PikachuEXE previously approved these changes Aug 27, 2023
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the test videos didnt start in the original track by default. The Local API always starts with the original track.

Is this intended behavior?

@absidue
Copy link
Member Author

absidue commented Aug 28, 2023

It should start with the default one, was messing around a lot in FreeTube and YouTube.js while making it, so maybe I broke something along the way or maybe it's dependant on one of the YouTube.js changes I made while making this.

I'll take a look and get back to you.

@absidue
Copy link
Member Author

absidue commented Aug 29, 2023

@efb4f5ff-1298-471a-8973-3d47447115dc Should work now, created a pull request to YouTube.js with the bug fix and upgraded to the version with it now.

PikachuEXE
PikachuEXE previously approved these changes Sep 2, 2023
@github-actions github-actions bot added PR: merge conflicts / rebase needed and removed PR: waiting for review For PRs that are complete, tested, and ready for review labels Sep 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2023

Conflicts have been resolved. A maintainer will review the pull request shortly.

@absidue
Copy link
Member Author

absidue commented Sep 9, 2023

Added language names with the Intl.DisplayNames API, so now the labels match the local API ones. This means they should now look and feel the same.

@absidue absidue added the PR: waiting for review For PRs that are complete, tested, and ready for review label Sep 9, 2023

if (hasMultipleAudioTracks) {
// match YouTube's local API response with English
const languageNames = new Intl.DisplayNames('en-US', { type: 'language' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the user's current locale instead of using "en-US"?

Copy link
Member Author

@absidue absidue Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My goal with this pull request was to match the local API, so that you would have the same, identical user experience with both the local and the Invidious API (maybe I should have made the comment on the line above more clear).

If you want me to switch to using the users locale, I can do that, it'll just be a different user experience than with the local API or the Invidious API when it gets multiple audio track support (ideally we don't want to keep this hack around forever).

@efb4f5ff-1298-471a-8973-3d47447115dc

@efb4f5ff-1298-471a-8973-3d47447115dc Should work now, created a pull request to YouTube.js with the bug fix and upgraded to the version with it now.

So tested both videos again and both didnt start with the original audio

@absidue
Copy link
Member Author

absidue commented Sep 12, 2023

@efb4f5ff-1298-471a-8973-3d47447115dc Merged the development branch in again, hopefully that'll help, also make sure you have ran yarn install so that you actually have a youtube.js version installed that works.

src/renderer/helpers/api/invidious.js Outdated Show resolved Hide resolved
src/renderer/helpers/api/invidious.js Outdated Show resolved Hide resolved
Co-authored-by: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com>
@absidue
Copy link
Member Author

absidue commented Sep 21, 2023

Fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@ChunkyProgrammer ChunkyProgrammer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looked at XHR/Fetch in network tab and no requests to YouTube are made when proxying through invidious is enabled. We should probably be translating the languages to the user's locale but as local api doesn't currently do that, this can come later

@FreeTubeBot FreeTubeBot merged commit d91f82f into FreeTubeApp:development Sep 25, 2023
5 checks passed
@github-actions github-actions bot removed the PR: waiting for review For PRs that are complete, tested, and ready for review label Sep 25, 2023
@absidue absidue deleted the iv-audio-track-av1 branch September 25, 2023 14:57
PikachuEXE added a commit to PikachuEXE/FreeTube that referenced this pull request Sep 26, 2023
* development: (41 commits)
  Translated using Weblate (Finnish)
  Mobile/tablet channel page & share button visual improvements (FreeTubeApp#4061)
  Support multiple audio tracks and AV1 for Invidious by using the local API DASH manifest generator (FreeTubeApp#3942)
  Normalize ft-list-item grid height (FreeTubeApp#4043)
  Bump the stylelint group with 1 update (FreeTubeApp#4071)
  Bump the babel group with 1 update (FreeTubeApp#4069)
  Bump the eslint group with 1 update (FreeTubeApp#4070)
  Bump sass from 1.67.0 to 1.68.0 (FreeTubeApp#4072)
  Bump marked from 9.0.2 to 9.0.3 (FreeTubeApp#4073)
  Bump lefthook from 1.4.11 to 1.5.0 (FreeTubeApp#4074)
  Translated using Weblate (Chinese (Traditional))
  Translated using Weblate (Greek)
  Translated using Weblate (German)
  Translated using Weblate (Portuguese (Brazil))
  Translated using Weblate (French)
  Translated using Weblate (Icelandic)
  Translated using Weblate (Portuguese)
  Translated using Weblate (Polish)
  ! Fix in sub view, restoring last tab is bugged when visible tabs do not include tab to be restored (FreeTubeApp#4064)
  Translated using Weblate (Ukrainian)
  ...

# Conflicts:
#	src/renderer/components/ft-prompt/ft-prompt.css
PikachuEXE added a commit to PikachuEXE/FreeTube that referenced this pull request Oct 8, 2023
* feature/playlist-2023-05: (176 commits)
  ! Fix playlist item fetching for local API (FreeTubeApp#4102)
  ! Fix watch page video published time parsing (FreeTubeApp#4105)
  Translated using Weblate (Serbian)
  Bump youtubei.js from 6.4.0 to 6.4.1 (FreeTubeApp#4090)
  Bump rimraf from 5.0.1 to 5.0.5 (FreeTubeApp#4091)
  Bump the stylelint group with 2 updates (FreeTubeApp#4088)
  Bump electron from 22.3.24 to 22.3.25 (FreeTubeApp#4089)
  Translated using Weblate (Bulgarian)
  Update FT history import to accept key lastViewedPlaylistId (FreeTubeApp#4038)
  ! Fix ft-video having different URLs in links
  Translated using Weblate (Dutch)
  Translated using Weblate (Lithuanian)
  Translated using Weblate (Japanese)
  Translated using Weblate (Croatian)
  Translated using Weblate (Estonian)
  Translated using Weblate (Croatian)
  ! Fix external player handling for video in local playlist
  Translated using Weblate (Finnish)
  Mobile/tablet channel page & share button visual improvements (FreeTubeApp#4061)
  Support multiple audio tracks and AV1 for Invidious by using the local API DASH manifest generator (FreeTubeApp#3942)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants