MCPcopy Create free account
hub / github.com/akhildevelops/summarizer / caption

Method caption

youtube-transcript/src/parser.rs:27–46  ·  view source on GitHub ↗
(&'a self, from: &str, to: &str)

Source from the content-addressed store, hash-verified

25 fn html_string(&'a self) -> &'a str;
26
27 fn caption(&'a self, from: &str, to: &str) -> Result<Caption, error::Error> {
28 let html = self.html_string();
29 let start = html
30 .split_once(from)
31 .ok_or_else(|| error::Error::ParseError(format!("Cannot parse html for: {}", from)))?
32 .1;
33 let actual_json = start
34 .split_once(to)
35 .ok_or_else(|| error::Error::ParseError(format!("Cannot parse html to: {}", to)))?
36 .0;
37 let value: Captions = serde_json::from_str(actual_json)
38 .map_err(|x| error::Error::ParseError(format!("{}", x)))?;
39 let caption = value
40 .caption_tracks
41 .into_iter()
42 .filter(|x| x.lang_code == "en")
43 .next()
44 .ok_or(error::Error::ParseError("Cannot find lang en".into()))?;
45 Ok(caption)
46 }
47}
48
49impl<'a> HTMLParser<'a> for String {

Callers 2

test_captionFunction · 0.80
transcriptMethod · 0.80

Implementers 1

parser.rsyoutube-transcript/src/parser.rs

Calls 2

html_stringMethod · 0.80
into_iterMethod · 0.80

Tested by 1

test_captionFunction · 0.64