Struct M3uParser

Source
pub struct M3uParser<'a> {
    pub streams_info: Vec<Info>,
    /* private fields */
}
Expand description

M3U Parser struct for parsing and manipulating M3U files.

Fields§

§streams_info: Vec<Info>

Implementations§

Source§

impl<'a> M3uParser<'a>

Source

pub fn new(timeout: Option<Duration>) -> M3uParser<'a>

Creates a new instance of M3uParser.

§Arguments
  • timeout - An optional Duration specifying the timeout for network requests. If not provided, a default timeout of 5 seconds is used.
Source

pub async fn parse_m3u( &mut self, path: &str, check_live: bool, enforce_schema: bool, )

Parses the specified M3U playlist file or URL.

§Arguments
  • path - The path or URL of the M3U playlist.
  • check_live - A boolean indicating whether to check the availability of streams. If set to true, the parser will make a request to each stream URL to check its status.
  • enforce_schema - A boolean indicating whether to enforce the M3U schema. If set to true, only valid M3U entries will be parsed.
Source

pub fn reset_operations(&mut self)

Resets the operations of the M3uParser by restoring the backup of stream information.

This function restores the original state of the M3uParser by replacing the current stream information with the backup. This can be useful when you want to undo any modifications or filtering operations applied to the stream information.

Source

pub fn filter_by( &mut self, key: &str, filters: Vec<&str>, key_splitter: &str, retrieve: bool, nested_key: bool, )

Filters the stream information based on the specified key and filters.

This function applies filtering operations to the stream information based on the provided key and filters. The key represents the attribute of the stream information that will be filtered, and the filters specify the conditions that the attribute should match. The function allows filtering based on nested keys and provides options to retrieve or exclude the matching stream information.

§Arguments
  • key - The attribute key to filter by. Valid values are: “title”, “logo”, “url”, “category”, “tvg”, “country”, “language”, and “status”.
  • filters - A vector of filter strings. The stream information will be filtered based on these conditions.
  • key_splitter - The delimiter used to split the key for nested filtering. Set it to an empty string ("") if nested filtering is not required.
  • retrieve - A boolean value indicating whether to retrieve the matching stream information (true) or exclude it from the result (false).
  • nested_key - A boolean value indicating whether the key represents a nested key. If true, the key will be split using the key_splitter, and filtering will be applied to the nested key. If false, the key will be treated as a single key for filtering.
§Panics

The function will panic in the following scenarios:

  • If the nested key is provided but not in the format <key><key_splitter><nested_key>.
  • If the provided key is not one of the valid keys (“title”, “logo”, “url”, “category”, “tvg”, “country”, “language”, “status”).
Source

pub fn sort_by( &mut self, key: &str, key_splitter: &str, asc: bool, nested_key: bool, )

Sorts the stream information based on the specified key and sorting options.

This function sorts the stream information based on the provided key and sorting options. The key represents the attribute of the stream information that will be used for sorting. The function allows sorting based on nested keys and provides options to specify the sorting order.

§Arguments
  • key - The attribute key to sort by. Valid values are: “title”, “logo”, “url”, “category”, “tvg”, “country”, “language”, and “status”.
  • key_splitter - The delimiter used to split the key for nested sorting. Set it to an empty string ("") if nested sorting is not required.
  • asc - A boolean value indicating the sorting order. If true, the stream information will be sorted in ascending order based on the specified key. If false, the stream information will be sorted in descending order.
  • nested_key - A boolean value indicating whether the key represents a nested key. If true, the key will be split using the key_splitter, and sorting will be applied to the nested key. If false, the key will be treated as a single key for sorting.
§Panics

The function will panic in the following scenarios:

  • If the nested key is provided but not in the format <key><key_splitter><nested_key>.
  • If the provided key is not one of the valid keys (“title”, “logo”, “url”, “category”, “tvg”, “country”, “language”, “status”).
Source

pub fn remove_by_extension(&mut self, extensions: Vec<&str>)

Removes stream information based on the specified file extensions.

This function removes stream information based on the file extensions specified in the extensions parameter. It internally calls the filter_by function with the “url” attribute as the key and filters the stream information that matches any of the provided extensions.

§Arguments
  • extensions - A vector of file extensions to be removed. Each extension should be a string.
Source

pub fn retrieve_by_extension(&mut self, extensions: Vec<&str>)

Retrieves stream information based on the specified file extensions.

This function retrieves stream information based on the file extensions specified in the extensions parameter. It internally calls the filter_by function with the “url” attribute as the key and filters the stream information that matches any of the provided extensions.

§Arguments
  • extensions - A vector of file extensions to be retrieved. Each extension should be a string.
Source

pub fn remove_by_category(&mut self, extensions: Vec<&str>)

Removes stream information based on the specified categories.

This function removes stream information based on the categories specified in the extensions parameter. It internally calls the filter_by function with the “category” attribute as the key and filters out the stream information that matches any of the provided categories.

§Arguments
  • categories - A vector of categories to be removed. Each category should be a string.
Source

pub fn retrieve_by_category(&mut self, extensions: Vec<&str>)

Retrieves stream information based on the specified categories.

This function retrieves stream information based on the categories specified in the extensions parameter. It internally calls the filter_by function with the “category” attribute as the key and filters the stream information that matches any of the provided categories.

§Arguments
  • categories - A vector of categories to be retrieved. Each category should be a string.
Source

pub fn get_json(&self, preety: bool) -> Result<String>

Retrieves the stream information in JSON format.

This function returns the stream information in JSON format. The JSON can be either pretty-formatted or compact depending on the preety parameter.

§Arguments
  • pretty - A boolean indicating whether to format the JSON output in a pretty, human-readable way.
§Returns

A serde_json::Result<String> representing the JSON output. If the serialization to JSON is successful, the result will contain the JSON string. Otherwise, an error indicating the reason for the failure will be returned.

Source

pub fn get_vector(&self) -> Vec<Info>

Retrieves a vector containing all stream information.

This function returns a deep clone of the internal streams_info vector, which contains all the stream information.

§Returns

A Vec<Info> containing all stream information. If there is no stream information available, an empty vector will be returned.

Source

pub fn get_random_stream(&mut self, random_shuffle: bool) -> Option<&Info>

Retrieves a random stream from the available stream information.

This function randomly selects a stream from the available stream information. The random_shuffle parameter determines whether to shuffle the stream information before selecting a random stream. If the stream information is empty, None will be returned.

§Arguments
  • random_shuffle - A boolean indicating whether to shuffle the stream information before selecting a random stream.
§Returns

An Option<&Info> representing the randomly selected stream. If a stream is successfully selected, the result will contain a reference to the stream. Otherwise, if the stream information is empty, None will be returned.

Source

pub fn to_file(&self, filename: &str, format: &str)

Saves the stream information to a file in the specified format.

This function saves the stream information to a file with the given filename and format. If the filename already contains a file extension, it will be used as the format. Otherwise, the format parameter will be used as the file extension.

The supported formats are “json” and “m3u”. For “json” format, the stream information will be saved as a JSON string in a pretty printed format. For “m3u” format, the stream information will be saved as an M3U playlist.

§Arguments
  • filename - A string representing the name of the file to be saved. If the file already exists, it will be overwritten.
  • format - A string representing the format in which the stream information should be saved. If the filename already contains a file extension, it will be used as the format. Otherwise, the format parameter will be used as the file extension.
§Panics

This function panics if there is an error while converting the stream information to the specified format or if there is an error while saving the file.

Auto Trait Implementations§

§

impl<'a> !Freeze for M3uParser<'a>

§

impl<'a> RefUnwindSafe for M3uParser<'a>

§

impl<'a> Send for M3uParser<'a>

§

impl<'a> Sync for M3uParser<'a>

§

impl<'a> Unpin for M3uParser<'a>

§

impl<'a> UnwindSafe for M3uParser<'a>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,