How to extract closed caption transcript from YouTube video?

后端 未结 10 542
囚心锁ツ
囚心锁ツ 2020-12-22 19:32

Is it possible to extract the closed caption transcript from YouTube videos?

We have over 200 webcasts on YouTube and each is at least one hour long. YouTube has clo

相关标签:
10条回答
  • 2020-12-22 19:51

    (Obligatory 'this is probably an internal youtube.com interface and might break at any time')

    Instead of linking to another tool that does this, here's an answer to the question of "how to do this"

    Use fiddler or your browser devtools (e.g. Chrome) to inspect the youtube.com HTTP traffic, and there's a response from /api/timedtext that contains the closed caption info as XML.

    It seems that a response like this:

        <p t="0" d="5430" w="1">
            <s p="2" ac="136">we&#39;ve</s>
            <s t="780" ac="252"> got</s>
        </p>
        <p t="2280" d="7170" w="1">
            <s ac="243">we&#39;re</s>
            <s t="810" ac="233"> going</s>
        </p>
    

    means at time 0 is the word we've and at time 0+780 is the word got and at time 2280+810 is the word going, etc. This time is in milliseconds so for time 3090 you'd want to append &t=3 to the URL.

    You can use any tool to stitch together the XML into something readable, but here's my Power BI Desktop script to find words like "privilege":

    let
        Source = Xml.Tables(File.Contents("C:\Download\body.xml")),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Attribute:format", Int64.Type}}),
        body = #"Changed Type"{0}[body],
        p = body{0}[p],
        #"Changed Type1" = Table.TransformColumnTypes(p,{{"Attribute:t", Int64.Type}, {"Attribute:d", Int64.Type}, {"Attribute:w", Int64.Type}, {"Attribute:a", Int64.Type}, {"Attribute:p", Int64.Type}}),
        #"Expanded s" = Table.ExpandTableColumn(#"Changed Type1", "s", {"Attribute:ac", "Attribute:p", "Attribute:t", "Element:Text"}, {"s.Attribute:ac", "s.Attribute:p", "s.Attribute:t", "s.Element:Text"}),
        #"Changed Type2" = Table.TransformColumnTypes(#"Expanded s",{{"s.Attribute:t", Int64.Type}}),
        #"Removed Other Columns" = Table.SelectColumns(#"Changed Type2",{"s.Attribute:t", "s.Element:Text", "Attribute:t"}),
        #"Replaced Value" = Table.ReplaceValue(#"Removed Other Columns",null,0,Replacer.ReplaceValue,{"s.Attribute:t"}),
        #"Filtered Rows" = Table.SelectRows(#"Replaced Value", each [#"s.Element:Text"] <> null),
        #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Time", each [#"Attribute:t"] + [#"s.Attribute:t"]),
        #"Filtered Rows1" = Table.SelectRows(#"Added Custom", each ([#"s.Element:Text"] = " privilege" or [#"s.Element:Text"] = " privileged" or [#"s.Element:Text"] = " privileges" or [#"s.Element:Text"] = "privilege" or [#"s.Element:Text"] = "privileges"))
    in
        #"Filtered Rows1"
    
    0 讨论(0)
  • 2020-12-22 19:51

    Choose Open Transcript from the ... dropdown to the right of the vote up/down and share links.

    This will open a Transcript scrolling div on the right side.

    You can then use Copy. Note that you cannot use Select All but need to click the top line, then scroll to the bottom using the scroll thumb, and then shift-click on the last line.

    Note that you can also search within this text using the normal web page search.

    0 讨论(0)
  • 2020-12-22 19:55

    Following document says only the owner of the channel can do this via standard youtube interface: https://developers.google.com/youtube/2.0/developers_guide_protocol_captions?hl=en

    Cheap fix: You can click on the "interactive transscript" button - and copy the content this way. Of course you lose the milliseconds this way.

    Extremely cheap fix: A shared youtube account - so that multiple people can edit and upload caption files.

    Challenging solution: The youtube API allows downloading and uploading of caption files via HTTP... You may write a youtube API application to provide a browser user interface for uploading or downloading for ANY user or particular users.

    Here is an example project for this in java http://apiblog.youtube.com/2011/01/youtube-captions-uploader-web-app.html

    Here is very simple example of a working upload for everybody: http://yt-captions-uploader.appspot.com/

    0 讨论(0)
  • 2020-12-22 19:57

    With the YouTube video updated as of June 2020 it's very straight forward

    1. select on the 3 dots next to like/dislike buttons to open further menu options
    2. select "add translations"
    3. select language
    4. click autogenerate if needed
    5. click Actions > Download

    You will get and .sbv file

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题