Skip to main content

Response

Struct Response 

Source
pub struct Response { /* private fields */ }

Implementations§

Source§

impl Response

Source

pub fn new() -> Response

Source

pub fn extend_buffer(&mut self, buffer: &mut Buffer) -> Result<bool, HlsError>

Source

pub fn extend_frame( &mut self, frame: H2Frame, hpack_coding: &mut HackDecode, ) -> Result<bool, HlsError>

Source

pub fn push_raw(&mut self, raw: Vec<u8>)

Source

pub fn header(&self) -> &Header

Source

pub fn header_mut(&mut self) -> &mut Header

Source

pub fn raw_body(&self) -> &[u8]

Source

pub fn raw_string(&self) -> String

Source

pub fn clear_raw(&mut self)

Source

pub fn decode_body(&mut self) -> Result<&mut Body, HlsError>

Source

pub fn json(self) -> Result<JsonValue, HlsError>

Source

pub fn text(self) -> Result<String, HlsError>

Examples found in repository?
examples/m3u8_down.rs (line 59)
56    fn get_key(&mut self) -> Result<(), HlsError> {
57        println!("key url: {}", self.key_url);
58        self.req.set_url(self.key_url.as_str())?;
59        let key = self.req.send_check(Method::GET)?.text()?;
60        println!("key: {}; sequence: {}", key, self.sequence);
61        self.cipher.set_secret_key(key.into_bytes(), Some(self.sequence.to_be_bytes().to_vec()));
62        Ok(())
63    }
64
65    fn download(&mut self) -> Result<(), HlsError> {
66        self.req.set_url(self.index_url.as_str())?;
67        let body = self.req.send_check(Method::GET)?.text()?;
68        // println!("{}", body);
69        for line in body.split("\n") {
70            if line.starts_with("#EXT-X-MEDIA-SEQUENCE:") {
71                self.sequence = line.trim().replace("#EXT-X-MEDIA-SEQUENCE:", "").parse()?;
72                continue;
73            }
74            if line.starts_with("#EXT-X-KEY") {
75                let pos = line.find("URI=\"");
76                if let Some(pos) = pos {
77                    self.key_url = line[pos + 4..].trim().replace("\"", "");
78                }
79                if line.contains("=AES-128,") {
80                    self.cipher = Cipher::aes_128_cbc();
81                }
82                continue;
83            }
84            if line.starts_with("http") {
85                self.ts_urls.push(line.trim().to_string());
86            }
87        }
88        let mut timeout = Timeout::new();
89        timeout.set_read(5000);
90        timeout.set_write(5000);
91        timeout.set_connect(5000);
92        timeout.set_handle(30000);
93        timeout.set_handle_times(10);
94        self.req.set_timeout(timeout);
95        if !self.key_url.is_empty() { self.get_key()?; }
96        self.down_ts()?;
97        Ok(())
98    }
Source

pub fn bytes(self) -> Result<Vec<u8>, HlsError>

Examples found in repository?
examples/m3u8_down.rs (line 50)
45    fn down_ts(&mut self) -> Result<(), HlsError> {
46        let mut file = File::create("4.mp4")?;
47        for (index, ts_url) in self.ts_urls.iter().enumerate() {
48            println!("Downloading: {:3}/{}; url:{}", index, self.ts_urls.len(), ts_url);
49            self.req.set_url(ts_url)?;
50            let body = self.req.get()?.bytes()?;
51            file.write_all(&if self.key_url.is_empty() { body } else { self.cipher.decrypt(body)? })?;
52        }
53        Ok(())
54    }

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.