@@ -40,7 +40,7 @@ const compareQuality = (rendition, requestedQuality) => {
4040 return Math . abs ( quality - requestedQuality ) ;
4141}
4242
43- const getDirectLink = ( data , quality ) => {
43+ const getDirectLink = async ( data , quality , subtitleLang ) => {
4444 if ( ! data . files ) return ;
4545
4646 const match = data . files
@@ -56,8 +56,23 @@ const getDirectLink = (data, quality) => {
5656
5757 if ( ! match ) return ;
5858
59+ let subtitles ;
60+ if ( subtitleLang && data . config_url ) {
61+ const config = await fetch ( data . config_url )
62+ . then ( r => r . json ( ) )
63+ . catch ( ( ) => { } ) ;
64+
65+ if ( config && config . request ?. text_tracks ?. length ) {
66+ subtitles = config . request . text_tracks . find (
67+ t => t . lang . startsWith ( subtitleLang )
68+ ) ;
69+ subtitles = new URL ( subtitles . url , "https://player.vimeo.com/" ) . toString ( ) ;
70+ }
71+ }
72+
5973 return {
6074 urls : match . link ,
75+ subtitles,
6176 filenameAttributes : {
6277 resolution : `${ match . width } x${ match . height } ` ,
6378 qualityLabel : match . rendition ,
@@ -143,7 +158,7 @@ export default async function(obj) {
143158 response = await getHLS ( info . config_url , { ...obj , quality } ) ;
144159 }
145160
146- if ( ! response ) response = getDirectLink ( info , quality ) ;
161+ if ( ! response ) response = await getDirectLink ( info , quality , obj . subtitleLang ) ;
147162 if ( ! response ) response = { error : "fetch.empty" } ;
148163
149164 if ( response . error ) {
@@ -155,6 +170,10 @@ export default async function(obj) {
155170 artist : info . user . name ,
156171 } ;
157172
173+ if ( response . subtitles ) {
174+ fileMetadata . sublanguage = obj . subtitleLang ;
175+ }
176+
158177 return merge (
159178 {
160179 fileMetadata,
0 commit comments