-
Notifications
You must be signed in to change notification settings - Fork 886
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
Migrate video player from video.js to shaka-player #4978
Merged
FreeTubeBot
merged 128 commits into
FreeTubeApp:development
from
absidue:shaka-migration
Sep 2, 2024
Merged
Changes from all commits
Commits
Show all changes
128 commits
Select commit
Hold shift + click to select a range
fb01262
Migrate video player from video.js to shaka-player
absidue cecb33f
Fix syntax error introduced during cleanup
absidue 1be8648
Fix typo
absidue 2341b62
Merge branch 'development' into shaka-migration
absidue 89217a3
Show bitrate in stats for Invidious legacy formats
absidue 5e1731f
Sort legacy formats by bitrate instead of qualityLabel
absidue 6eef018
Use Invidious' newly added isPostLiveDvr property
absidue 500ef3d
Invidious correctly returns the ratelimit for DASH manifests now
absidue 7eb03fb
Properly hide unsupported screenshot functionality outside of Electron
absidue c45c84f
Sort captions in data initialiser
absidue e8ffd0d
Merge branch 'development' into shaka-migration
absidue aa6326b
Update shaka-player to version 4.8.1
absidue 96df390
Use textTrackLabelFormat configuration option
absidue 5983de2
Switch to manifestPreprocessorTXml
absidue 4bf7d04
Add support for VR videos that use equirectangular projection
absidue e406fb1
The AV1 video streams work okay for vr, so allow list them too
absidue e9f9fbd
Merge branch 'development' into shaka-migration
absidue 3221642
Use woff2 (169 KB) Material Icons font instead of otf (390 KB)
absidue 8b533d1
Use material icons for custom player elements
absidue b3b05e9
Fix legacy formats exception
absidue cb4d0f2
Merge branch 'development' into shaka-migration
absidue 5a701b7
Merge branch 'development' into shaka-migration
absidue ead227e
Update shaka-player to version 4.8.3
absidue 334e302
Sort default quality values the same as in the player
absidue 1408f5f
Merge branch 'development' into shaka-migration
absidue 29b2128
Cleanup representations search in live subtitle fix
absidue b8626f2
Slightly speed up sortCaptions
absidue b80909c
Fix setPositionState error when playback rate is 0
absidue 9f0cef1
Merge branch 'development' into shaka-migration
absidue be46412
Update shaka-player to version 4.8.4
absidue da81416
Fix playback rate changes getting overridden
absidue 6bf7805
Fix current chapter index not updating
absidue 00b4809
Fix next video not automatically playing
absidue 977f0d7
Fix volume changes not propagating to the mute button
absidue de19bb7
Reduce work done during UI config updates
absidue 449b708
Fix UI customizations not applying after UI config changes
absidue 5f7980d
Update shaka-player to version 4.8.5
absidue bcbb498
Replace non-reactive workaround with a Vue 3 friendly one
absidue 8db84d4
Merge branch 'development' into shaka-migration
absidue 2e5fe8e
Fix error when all sponsorblock segments are set to do nothing
absidue a9a4c07
Add some guards to hopefully reduce errors during fast naviagtions
absidue 287dbff
Make SponsorBlock failure non-fatal
absidue ef275f2
Merge branch 'development' into shaka-migration
absidue a5f75ab
Merge branch 'development' into shaka-migration
absidue ff9fd8a
Merge branch 'development' into shaka-migration
absidue 0db16c3
Update shaka-player to version 4.8.6
absidue 4540173
Merge branch 'development' into shaka-migration
absidue d847a0f
Update shaka-player to version 4.8.8
absidue a6f02a6
Merge branch 'development' into shaka-migration
absidue b0262f5
Update shaka-player to version 4.9.0
absidue 90018d7
Merge branch 'development' into shaka-migration
absidue 399e318
Update shaka-player to version 4.9.1
absidue 475b5b8
Minor performance improvements
absidue d421924
Merge branch 'development' into shaka-migration
absidue a54cbf3
Update shaka-player to version 4.9.6
absidue 581b9a2
Merge branch 'development' into shaka-migration
absidue a239ec6
Update shaka-player to version 4.9.9
absidue 2918b09
Merge branch 'development' into shaka-migration
absidue bd25335
Fix sponsor block markers not showing up
absidue 1c951b2
Add some basic error messages for expired urls and ratelimits
absidue 6410f81
Add some basic error messages for 403s
absidue 7c2505b
Cleanup code comments
absidue 80fe87c
Migrate player to composition API for better performance
absidue a4a485b
Merge branch 'development' into shaka-migration
absidue 64ccb66
Use reactive for stats instead of ref, as it never gets reassigned
absidue 0ad03f5
Merge branch 'development' into shaka-migration
absidue ee4c9a0
Update shaka-player to version 4.10.0
absidue 816d1ea
Fix i18n import in custom player components
absidue 570d518
Add chapter markers
absidue 92e3c1b
Move shaka-player CSS import into the Vue file
absidue 7935335
Bump mpd_version from 5 to 7
absidue c85062a
Apply suggestions from code review
absidue 0ebf3c4
Merge branch 'development' into shaka-migration
absidue 50a42c0
Fix seeking with the arrow keys
absidue 70cdb0d
Merge branch 'development' into shaka-migration
absidue d30666a
Update shaka-player to version 4.10.3
absidue aca8c8b
Truncate long video titles to the screen width in the full screen ove…
absidue 4151fad
Merge branch 'development' into shaka-migration
absidue 9db9622
Merge branch 'development' into shaka-migration
absidue 8308e47
Fix mouse scroll handlers firing multiple times
absidue 15184f8
Cleanup unneeded code
absidue a554c91
Merge branch 'development' into shaka-migration
absidue af7e5a9
Update shaka-player to version 4.10.6
absidue 308aa43
Various small optimisations
absidue f24d7ed
Move skipped sponsorblock segement messages to the top right corner
absidue 7fcc1d8
Support prefers-reduced-transparency in overlays
absidue eff7062
Merge branch 'development' into shaka-migration
absidue 2de5a1a
Fix stylelint errors
absidue c6e9184
Update shaka-player to version 4.10.7
absidue 193c0b9
Merge branch 'development' into shaka-migration
absidue 13f5654
Update shaka-player to version 4.10.8
absidue 2ba01f9
Only use variants that are predicted to play smoothly
absidue 64446ee
Only set preferredDecodingAttributes for DASH playback
absidue dfe3b4b
Implement a custom audio track selector instead of using shaka-player's
absidue 1aeffee
Move skipped sponsorblock segement messages to the bottom right corner
absidue db42898
Merge branch 'development' into shaka-migration
absidue e4eca34
Fix scrolling over the big play pause button not working
absidue d38d40e
Update shaka-player to version 4.10.9
absidue b152ac4
Fix some type issues
absidue f600465
Add support for secondary audio tracks
absidue 8d4d4bf
Downgrade shaka-player to fix subtitle alignment
absidue 6f665f1
Actually downgrade shaka-player
absidue 3ef3d0f
Fix Invidious API error
absidue 8e4beb8
Update outdated comment
absidue ae78771
Fix multiple audio track detection for Invidious
absidue 8d07c12
Fix duplicate qualities with the Invidious API
absidue 942df17
Use vp9 streams if the Invidious instance is running a new enough ver…
absidue 6a94be2
Merge branch 'development' into shaka-migration
absidue 9b9c067
Merge branch 'development' into shaka-migration
absidue 4202fe4
When an error occurs with the thumbnails just log it
absidue d8bea95
Include the video ID in the error logs
absidue 52dc3f3
Merge branch 'development' into shaka-migration
absidue 639d2df
Merge branch 'development' into shaka-migration
absidue 6908a9e
Gracefully handle the internet connection disappearing during playback
absidue 704e49e
Show a message while buffering if it was caused by the internet conne…
absidue 64aec23
Fix the text color and RTL handling
absidue 816e5f5
Merge branch 'development' into shaka-migration
absidue 489a668
Cleanup the Invidious DASH manifest in builds without the local API
absidue 3d313bf
Fix quality selection when switching from audio to DASH
absidue 060f271
Merge branch 'development' into shaka-migration
absidue 4c26976
Update shaka-player to version 4.10.10
absidue 6e2e888
Fix position and alignment for auto-generated subtitles
absidue 0801740
Merge branch 'development' into shaka-migration
absidue 9f8f868
Update shaka-player to version 4.10.11
absidue 2ce0726
Use the HLS manifests for live streams
absidue a36c497
Merge branch 'development' into shaka-migration
absidue 14b8ea8
Merge branch 'development' into shaka-migration
absidue f49c9ed
Update shaka-player to version 4.10.12
absidue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const { readFileSync, readdirSync } = require('fs') | ||
|
||
function getPreloadedLocales() { | ||
const localesFile = readFileSync(`${__dirname}/../node_modules/shaka-player/dist/locales.js`, 'utf-8') | ||
|
||
const localesLine = localesFile.match(/^\/\/ LOCALES: ([\w, -]+)$/m) | ||
|
||
if (!localesLine) { | ||
throw new Error("Failed to parse shaka-player's preloaded locales") | ||
} | ||
|
||
return localesLine[1].split(',').map(locale => locale.trim()) | ||
} | ||
|
||
function getAllLocales() { | ||
const filenames = readdirSync(`${__dirname}/../node_modules/shaka-player/ui/locales`) | ||
|
||
return new Set(filenames | ||
.filter(filename => filename !== 'source.json' && filename.endsWith('.json')) | ||
.map(filename => filename.replace('.json', ''))) | ||
} | ||
|
||
/** | ||
* Maps the shaka locales to FreeTube's active ones | ||
* This allows us to know which locale files are actually needed | ||
* and which shaka locale needs to be activated for a given FreeTube one. | ||
* @param {Set<string>} shakaLocales | ||
* @param {string[]} freeTubeLocales | ||
*/ | ||
function getMappings(shakaLocales, freeTubeLocales) { | ||
/** | ||
* @type {[string, string][]} | ||
* Using this structure as it gets passed to `new Map()` in the player component | ||
* The first element is the FreeTube locale, the second one is the shaka-player one | ||
**/ | ||
const mappings = [] | ||
|
||
for (const locale of freeTubeLocales) { | ||
if (shakaLocales.has(locale)) { | ||
mappings.push([ | ||
locale, | ||
locale | ||
]) | ||
} else if (shakaLocales.has(locale.replace('_', '-'))) { | ||
mappings.push([ | ||
locale, | ||
locale.replace('_', '-') | ||
]) | ||
} else if (shakaLocales.has(locale.split(/[-_]/)[0])) { | ||
mappings.push([ | ||
locale, | ||
locale.split(/[-_]/)[0] | ||
]) | ||
} | ||
} | ||
|
||
// special cases | ||
|
||
mappings.push( | ||
// according to https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | ||
// "no" is the macro language for "nb" and "nn" | ||
[ | ||
'nb_NO', | ||
'no' | ||
], | ||
[ | ||
'nn', | ||
'no' | ||
], | ||
|
||
// according to https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | ||
// "iw" is the old/original code for Hebrew, these days it's "he" | ||
[ | ||
'he', | ||
'iw' | ||
], | ||
|
||
// not sure why we have pt, pt-PT and pt-BR in the FreeTube locales | ||
// as pt and pt-PT are the same thing, but we should handle it here anyway | ||
[ | ||
'pt', | ||
'pt-PT' | ||
] | ||
) | ||
|
||
return mappings | ||
} | ||
|
||
function getShakaLocales() { | ||
const shakaLocales = getAllLocales() | ||
|
||
/** @type {string[]} */ | ||
const freeTubeLocales = JSON.parse(readFileSync(`${__dirname}/../static/locales/activeLocales.json`, 'utf-8')) | ||
|
||
const mappings = getMappings(shakaLocales, freeTubeLocales) | ||
|
||
const preloaded = getPreloadedLocales() | ||
|
||
const shakaMappings = mappings.map(mapping => mapping[1]) | ||
|
||
// use a set to deduplicate the list | ||
// we don't need to bundle any locale files that are already embedded in shaka-player/preloaded | ||
|
||
/** @type {string[]} */ | ||
const toBeBundled = [...new Set(shakaMappings.filter(locale => !preloaded.includes(locale)))] | ||
|
||
return { | ||
SHAKA_LOCALE_MAPPINGS: mappings, | ||
SHAKA_LOCALES_PREBUNDLED: preloaded, | ||
SHAKA_LOCALES_TO_BE_BUNDLED: toBeBundled | ||
} | ||
} | ||
|
||
module.exports = getShakaLocales() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// This script fixes shaka not exporting its type definitions and referencing remote google fonts in its CSS | ||
// by adding an export line to the type definitions and downloading the fonts and updating the CSS to point to the local files | ||
// this script only makes changes if they are needed, so running it multiple times doesn't cause any problems | ||
|
||
import { appendFileSync, closeSync, ftruncateSync, openSync, readFileSync, writeFileSync, writeSync } from 'fs' | ||
import { resolve } from 'path' | ||
|
||
const SHAKA_DIST_DIR = resolve(import.meta.dirname, '../node_modules/shaka-player/dist') | ||
|
||
function fixTypes() { | ||
let fixedTypes = false | ||
|
||
let fileHandleNormal | ||
try { | ||
fileHandleNormal = openSync(`${SHAKA_DIST_DIR}/shaka-player.ui.d.ts`, 'a+') | ||
|
||
const contents = readFileSync(fileHandleNormal, 'utf-8') | ||
|
||
// This script is run after every `yarn install`, even if shaka-player wasn't updated | ||
// So we want to check first, if we actually need to make any changes | ||
// or if the ones from the previous run are still intact | ||
if (!contents.includes('export default shaka')) { | ||
appendFileSync(fileHandleNormal, 'export default shaka;\n') | ||
|
||
fixedTypes = true | ||
} | ||
} finally { | ||
if (typeof fileHandleNormal !== 'undefined') { | ||
closeSync(fileHandleNormal) | ||
} | ||
} | ||
|
||
let fileHandleDebug | ||
try { | ||
fileHandleDebug = openSync(`${SHAKA_DIST_DIR}/shaka-player.ui.debug.d.ts`, 'a+') | ||
|
||
const contents = readFileSync(fileHandleDebug, 'utf-8') | ||
|
||
// This script is run after every `yarn install`, even if shaka-player wasn't updated | ||
// So we want to check first, if we actually need to make any changes | ||
// or if the ones from the previous run are still intact | ||
if (!contents.includes('export default shaka')) { | ||
appendFileSync(fileHandleDebug, 'export default shaka;\n') | ||
|
||
fixedTypes = true | ||
} | ||
} finally { | ||
if (typeof fileHandleDebug !== 'undefined') { | ||
closeSync(fileHandleDebug) | ||
} | ||
} | ||
|
||
if (fixedTypes) { | ||
console.log('Fixed shaka-player types') | ||
} | ||
} | ||
|
||
async function removeRobotoFont() { | ||
let cssFileHandle | ||
try { | ||
cssFileHandle = openSync(`${SHAKA_DIST_DIR}/controls.css`, 'r+') | ||
|
||
let cssContents = readFileSync(cssFileHandle, 'utf-8') | ||
|
||
const beforeReplacement = cssContents.length | ||
cssContents = cssContents.replace(/@font-face\{font-family:Roboto;[^}]+\}/, '') | ||
|
||
if (cssContents.length !== beforeReplacement) { | ||
ftruncateSync(cssFileHandle) | ||
writeSync(cssFileHandle, cssContents, 0, 'utf-8') | ||
|
||
console.log('Removed shaka-player Roboto font, so it uses ours') | ||
} | ||
} finally { | ||
if (typeof cssFileHandle !== 'undefined') { | ||
closeSync(cssFileHandle) | ||
} | ||
} | ||
} | ||
|
||
async function replaceAndDownloadMaterialIconsFont() { | ||
let cssFileHandle | ||
try { | ||
cssFileHandle = openSync(`${SHAKA_DIST_DIR}/controls.css`, 'r+') | ||
|
||
let cssContents = readFileSync(cssFileHandle, 'utf-8') | ||
|
||
const fontFaceRegex = /@font-face{font-family:'Material Icons Round'[^}]+format\('opentype'\)}/ | ||
|
||
if (fontFaceRegex.test(cssContents)) { | ||
const cssResponse = await fetch('https://fonts.googleapis.com/icon?family=Material+Icons+Round', { | ||
headers: { | ||
// Without the user-agent it returns the otf file instead of the woff2 one | ||
'user-agent': 'Firefox/125.0' | ||
} | ||
}) | ||
|
||
const text = await cssResponse.text() | ||
|
||
let newFontCSS = text.match(/(@font-face\s*{[^}]+})/)[1].replaceAll('\n', '') | ||
|
||
|
||
const urlMatch = newFontCSS.match(/https:\/\/fonts\.gstatic\.com\/s\/materialiconsround\/(?<version>[^\/]+)\/[^.]+\.(?<extension>[\w]+)/) | ||
|
||
const url = urlMatch[0] | ||
const { version, extension } = urlMatch.groups | ||
|
||
const fontResponse = await fetch(url) | ||
const fontContent = new Uint8Array(await fontResponse.arrayBuffer()) | ||
|
||
const filename = `shaka-materialiconsround-${version}.${extension}` | ||
writeFileSync(`${SHAKA_DIST_DIR}/${filename}`, fontContent) | ||
|
||
newFontCSS = newFontCSS.replace(url, `./${filename}`) | ||
|
||
cssContents = cssContents.replace(fontFaceRegex, newFontCSS) | ||
|
||
ftruncateSync(cssFileHandle) | ||
writeSync(cssFileHandle, cssContents, 0, 'utf-8') | ||
|
||
console.log('Changed shaka-player Material Icons Rounded font to use the smaller woff2 format instead of otf') | ||
console.log('Downloaded shaka-player Material Icons Rounded font') | ||
} | ||
} catch (e) { | ||
console.error(e) | ||
} finally { | ||
if (typeof cssFileHandle !== 'undefined') { | ||
closeSync(cssFileHandle) | ||
} | ||
} | ||
} | ||
|
||
fixTypes() | ||
await removeRobotoFont() | ||
await replaceAndDownloadMaterialIconsFont() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not super important since it is only ran for developers but maybe we could include this in another file so we can keep it up to date (doesn't need to be changed for this PR imo)