Spaces:
Sleeping
Sleeping
File size: 987 Bytes
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 |
## Julia py_init file
module Transcriber
using PyCall
function __init__()
py"""
from youtube_transcript_api import YouTubeTranscriptApi
def get_transcript(video_id):
return YouTubeTranscriptApi.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 |