File size: 1,329 Bytes
acc66a1
 
 
 
 
 
 
 
527870d
acc66a1
527870d
 
 
 
 
 
 
 
 
 
 
 
acc66a1
 
527870d
acc66a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
## Julia py_init file 
module Transcriber 

using PyCall

function __init__()

    py"""
    import os
    from youtube_transcript_api import YouTubeTranscriptApi 
    from youtube_transcript_api.proxies import WebshareProxyConfig

    webuser = os.environ.get("webshareuser")
    websharepass = os.environ.get("websharepass")

    ytt_api = YouTubeTranscriptApi(
        proxy_config=WebshareProxyConfig(
            proxy_username=websharepass,
            proxy_password=websharepass,
        )
    )


    def get_transcript(video_id):
        return ytt_api.get_transcript(video_id)
    """
end

# test id: "SW14tOda_kI"
# get_transcript("SW14tOda_kI")
function get_transcript(video_id::String; textonly::Bool=true)
    transcript = py"get_transcript"(video_id)
    ## 
    if textonly
        transcript = [line["text"] for line in transcript]
    end
    return transcript
end

function get_transcript_text(video_id::String)
    transcript = py"get_transcript"(video_id)
    text = ""
    for line in transcript
        text *= line["text"] * " "
    end
    return text
end

function chunk_text(text::String, chunk_size::Int=280)
    chunks = []
    for i in 1:chunk_size:length(text)
        newchunk = text[i:min(i+chunk_size-1, length(text))]
        push!(chunks, newchunk)
    end
    return string.(chunks)
end

end