Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to determine whether the given input is a MasterPlaylist or MediaPlaylist #58

Open
Luro02 opened this issue Apr 26, 2020 · 0 comments
Labels
E-easy Effort: easy. A task that would be a great starting point for a new contributor. T-enhancement Type: enhancement. New feature or request

Comments

@Luro02
Copy link
Collaborator

Luro02 commented Apr 26, 2020

This would be relatively simple to do;

pub enum Playlist {
    Master(MasterPlaylist),
    Media(MediaPlaylist),
}

impl TryFrom<&str> for Playlist {
    type  Error = Error;

    fn try_from(input: &str) -> Result<Self, Self::Error> {
        match MasterPlaylist::try_from(input) {
            Ok(v) => Ok(Self::Master(v)),
            Err(e) => {
                if e.is_unexpected_tag() {
                    match MediaPlaylist::try_from(input) {
                        Ok(v) => Ok(Self::Media(v)),
                        Err(e) => {
                            if e.is_unexpected_tag() {
                                Err(Error::custom("failed to determine playlist type"))
                            } else {
                                Err(e)
                            }
                        }
                    }
                } else {
                    Err(e)
                }
            }
        }
    }
}

one might have to do some adjustments to the above code, like maybe remove the nesting to improve readability?

The documentation should mention that one most likely gets a MasterPlaylist initially and that this method is quite inefficient, because it would have to parse a MediaPlaylist and a MasterPlaylist in the worst case.

@Luro02 Luro02 added T-enhancement Type: enhancement. New feature or request E-easy Effort: easy. A task that would be a great starting point for a new contributor. labels Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Effort: easy. A task that would be a great starting point for a new contributor. T-enhancement Type: enhancement. New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant