Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

How to find out YouTube 'auto subtitle language' with JavaScript? (get auto captions language)

  1. I developed YouTube subtitle extraction.
    My program fetches subtitles for 'user selected language'.

enter image description here



  1. However, there were so many languages ??to choose from.

enter image description here



  1. So, I used the link below to get the 'subtitles language list of for the video'.
    http://video.google.com/timedtext?v=${youtubeID}&type=list
    http://video.google.com/timedtext?v=oIa3BFBHJFI&type=list (example)

enter image description here

my code:

        fetch(`http://video.google.com/timedtext?v=${youtubeID}&type=list`
        .then(res => res.text())                                                 // 1. xml -> get text
        .then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))  // 2. text -> xml
        .then(data => {
            let tempLanguageList = [];
            let xml = data.getElementsByTagName("transcript_list")[0];          

            // get language
            for (let i = 0; i < xml.childElementCount; i++) {
                let item = xml.children.item(i);   // ??: <track id=?"22" name lang_code=?"en" lang_original=?"English" lang_translated=?"English" lang_default=?"true">?</track>?
                let itemObject = item.getAttribute("lang_code") + ", " + item.getAttribute("lang_original")
                tempLanguageList.push(itemObject);  // ex) en
            }

            console.log("tempLanguageList: ", tempLanguageList);
        })

result:

enter image description here



  1. However, the automatic subtitles were not displayed in the link above. enter image description here

(add) For example, https://youtu.be/D_M9fl_Cj9I in this video,'english' is an automatic subtitle and 'korea' is a manual subtitle.

enter image description here

But when I check it, english did not appear on the list.
http://video.google.com/timedtext?v=D_M9fl_Cj9I&type=list

enter image description here



[question]
How can I check the 'language list of automatic subtitles' for a specific YouTube video?

question from:https://stackoverflow.com/questions/65895932/how-to-find-out-youtube-auto-subtitle-language-with-javascript-get-auto-capt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...