Home:ALL Converter>python retrieve automatic captions with youtube_dl and transform to transcript

python retrieve automatic captions with youtube_dl and transform to transcript

Ask Time:2018-12-07T04:47:01         Author:wuz

Json Formatter

The automatic english captions extracted from youtube contains not the information in a readable form and duplicated text information.

welcome<00:00:01.790><c> my</c><00:00:02.790><c> name</c><c.colorCCCCCC><00:00:02.820><c> is</c><00:00:03.210><c> Helga</c></c><c.colorE5E5E5><00:00:03.449><c> Vieira</c><00:00:03.929><c> and</c><00:00:04.080><c> this</c></c>

00:00:04.670 --> 00:00:04.680 align:start position:0%
welcome my name<c.colorCCCCCC> is Helga</c><c.colorE5E5E5> Vieira and this
 </c>

My code:

def captions_test02(url):
    ydl = youtube_dl.YoutubeDL({'writesubtitles': True, 'allsubtitles': True, 'writeautomaticsub': True})
    res = ydl.extract_info(url, download=False)
    if res['requested_subtitles'] and res['requested_subtitles']['en']:
        print('Grabbing vtt file from ' + res['requested_subtitles']['en']['url'])
        response = requests.get(res['requested_subtitles']['en']['url'], stream=True)
        f1 = open("testfile01.txt", "w")
        f1.write(response.text)
        f1.close()
        if len(res['subtitles']) > 0:
            print('manual captions')
        else:
            print('automatic_captions')
    else:
        print('Youtube Video does not have any english captions')

if __name__ == '__main__':
    captions_test02("https://www.youtube.com/watch?v=tCTqNZW0wIk&t=2s")

Any suggestions to get a proper transcript? Starting point: https://shkspr.mobi/blog/2018/09/convert-webvtt-to-a-transcript-using-python/

Author:wuz,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53659427/python-retrieve-automatic-captions-with-youtube-dl-and-transform-to-transcript
yy