1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-17 16:02:59 +00:00

remove url #21

This commit is contained in:
Luro02 2019-09-21 12:11:36 +02:00
parent ea75128aee
commit 71361ff328
9 changed files with 54 additions and 82 deletions

View file

@ -18,7 +18,6 @@ codecov = {repository = "sile/hls_m3u8"}
[dependencies]
failure = "0.1.5"
derive_builder = "0.7.2"
url = "2.1.0"
chrono = "0.4.9"
[dev-dependencies]

View file

@ -12,9 +12,7 @@ pub enum ErrorKind {
#[fail(display = "ChronoParseError: {}", _0)]
/// An error from the [Chrono](chrono) crate.
ChronoParseError(String),
#[fail(display = "UrlParseError: {}", _0)]
/// An error from the [Url](url) crate.
UrlParseError(String),
#[fail(display = "UnknownError: {}", _0)]
/// An unknown error occured.
UnknownError(String),
@ -184,10 +182,6 @@ impl Error {
Self::from(ErrorKind::BuilderError(value.to_string()))
}
pub(crate) fn url<T: ToString>(value: T) -> Self {
Self::from(ErrorKind::UrlParseError(value.to_string()))
}
pub(crate) fn chrono<T: ToString>(value: T) -> Self {
Self::from(ErrorKind::ChronoParseError(value.to_string()))
}
@ -211,12 +205,6 @@ impl From<::std::io::Error> for Error {
}
}
impl From<::url::ParseError> for Error {
fn from(value: ::url::ParseError) -> Self {
Error::url(value)
}
}
impl From<::chrono::ParseError> for Error {
fn from(value: ::chrono::ParseError) -> Self {
Error::chrono(value)

View file

@ -2,8 +2,6 @@ use std::fmt;
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use url::Url;
use crate::tags;
use crate::Error;
@ -55,7 +53,7 @@ impl FromStr for Lines {
continue;
}
} else {
Line::Uri(line.trim().parse()?)
Line::Uri(line.trim().to_string())
}
}
};
@ -93,7 +91,7 @@ impl DerefMut for Lines {
#[derive(Debug, PartialEq, Eq)]
pub enum Line {
Tag(Tag),
Uri(Url),
Uri(String),
}
#[allow(clippy::large_enum_variant)]

View file

@ -2,7 +2,6 @@ use std::fmt;
use std::iter;
use derive_builder::Builder;
use url::Url;
use crate::tags::{
ExtInf, ExtXByteRange, ExtXDateRange, ExtXDiscontinuity, ExtXKey, ExtXMap, ExtXProgramDateTime,
@ -34,7 +33,7 @@ pub struct MediaSegment {
/// Sets an [ExtInf] tag.
inf_tag: ExtInf,
/// Sets an Uri.
uri: Url,
uri: String,
}
impl MediaSegmentBuilder {
@ -81,7 +80,7 @@ impl MediaSegment {
MediaSegmentBuilder::default()
}
/// Returns the URI of the media segment.
pub const fn uri(&self) -> &Url {
pub const fn uri(&self) -> &String {
&self.uri
}

View file

@ -2,8 +2,6 @@ use std::fmt;
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use url::Url;
use crate::types::{DecryptionKey, EncryptionMethod, ProtocolVersion};
use crate::utils::tag;
use crate::Error;
@ -20,7 +18,7 @@ impl ExtXSessionKey {
/// Makes a new [ExtXSessionKey] tag.
/// # Panic
/// This method will panic, if the [EncryptionMethod] is None.
pub fn new(method: EncryptionMethod, uri: Url) -> Self {
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
if method == EncryptionMethod::None {
panic!("The EncryptionMethod is not allowed to be None");
}
@ -36,7 +34,7 @@ impl ExtXSessionKey {
///
/// let mut key = ExtXSessionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// assert_eq!(
@ -93,7 +91,7 @@ mod test {
fn test_display() {
let mut key = ExtXSessionKey::new(
EncryptionMethod::Aes128,
"https://www.example.com/hls-key/key.bin".parse().unwrap(),
"https://www.example.com/hls-key/key.bin",
);
key.set_iv([
16, 239, 143, 117, 140, 165, 85, 17, 85, 132, 187, 91, 60, 104, 127, 82,
@ -116,13 +114,13 @@ mod test {
.unwrap(),
ExtXSessionKey::new(
EncryptionMethod::Aes128,
"https://priv.example.com/key.php?r=52".parse().unwrap()
"https://priv.example.com/key.php?r=52"
)
);
let mut key = ExtXSessionKey::new(
EncryptionMethod::Aes128,
"https://www.example.com/hls-key/key.bin".parse().unwrap(),
"https://www.example.com/hls-key/key.bin",
);
key.set_iv([
16, 239, 143, 117, 140, 165, 85, 17, 85, 132, 187, 91, 60, 104, 127, 82,

View file

@ -1,8 +1,6 @@
use std::fmt;
use std::str::FromStr;
use url::Url;
use crate::attribute::AttributePairs;
use crate::types::{
ClosedCaptions, DecimalFloatingPoint, DecimalResolution, HdcpLevel, ProtocolVersion,
@ -15,7 +13,7 @@ use crate::Error;
/// [4.3.4.2. EXT-X-STREAM-INF]: https://tools.ietf.org/html/rfc8216#section-4.3.4.2
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExtXStreamInf {
uri: Url,
uri: String,
bandwidth: u64,
average_bandwidth: Option<u64>,
codecs: Option<String>,
@ -32,9 +30,9 @@ impl ExtXStreamInf {
pub(crate) const PREFIX: &'static str = "#EXT-X-STREAM-INF:";
/// Makes a new `ExtXStreamInf` tag.
pub const fn new(uri: Url, bandwidth: u64) -> Self {
pub fn new<T: ToString>(uri: T, bandwidth: u64) -> Self {
ExtXStreamInf {
uri,
uri: uri.to_string(),
bandwidth,
average_bandwidth: None,
codecs: None,
@ -49,7 +47,7 @@ impl ExtXStreamInf {
}
/// Returns the URI that identifies the associated media playlist.
pub const fn uri(&self) -> &Url {
pub const fn uri(&self) -> &String {
&self.uri
}
@ -193,7 +191,7 @@ impl FromStr for ExtXStreamInf {
let bandwidth = bandwidth.ok_or(Error::missing_value("EXT-X-BANDWIDTH"))?;
Ok(ExtXStreamInf {
uri: uri.parse()?,
uri: uri.to_string(),
bandwidth,
average_bandwidth,
codecs,
@ -220,7 +218,7 @@ mod test {
assert_eq!(
stream_inf,
ExtXStreamInf::new("http://www.example.com".parse().unwrap(), 1000)
ExtXStreamInf::new("http://www.example.com", 1000)
);
}
@ -228,14 +226,14 @@ mod test {
fn test_requires_version() {
assert_eq!(
ProtocolVersion::V1,
ExtXStreamInf::new("http://www.example.com".parse().unwrap(), 1000).requires_version()
ExtXStreamInf::new("http://www.example.com", 1000).requires_version()
);
}
#[test]
fn test_display() {
assert_eq!(
ExtXStreamInf::new("http://www.example.com".parse().unwrap(), 1000).to_string(),
ExtXStreamInf::new("http://www.example.com/", 1000).to_string(),
"#EXT-X-STREAM-INF:BANDWIDTH=1000\nhttp://www.example.com/".to_string()
);
}

View file

@ -2,8 +2,6 @@ use std::fmt;
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use url::Url;
use crate::types::{DecryptionKey, EncryptionMethod};
use crate::utils::tag;
use crate::Error;
@ -22,14 +20,12 @@ impl ExtXKey {
/// Makes a new `ExtXKey` tag.
/// # Example
/// ```
/// use url::Url;
///
/// use hls_m3u8::tags::ExtXKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let key = ExtXKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// assert_eq!(
@ -37,7 +33,7 @@ impl ExtXKey {
/// "#EXT-X-KEY:METHOD=AES-128,URI=\"https://www.example.com/\""
/// );
/// ```
pub const fn new(method: EncryptionMethod, uri: Url) -> Self {
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
Self(DecryptionKey::new(method, uri))
}
@ -128,7 +124,7 @@ mod test {
key.set_iv([
16, 239, 143, 117, 140, 165, 85, 17, 85, 132, 187, 91, 60, 104, 127, 82,
]);
key.set_uri("https://www.example.com".parse().unwrap());
key.set_uri(Some("https://www.example.com"));
key.set_key_format_versions("1/2/3");
assert_eq!(key.to_string(), "#EXT-X-KEY:METHOD=NONE".to_string());
@ -142,13 +138,13 @@ mod test {
.unwrap(),
ExtXKey::new(
EncryptionMethod::Aes128,
"https://priv.example.com/key.php?r=52".parse().unwrap()
"https://priv.example.com/key.php?r=52"
)
);
let mut key = ExtXKey::new(
EncryptionMethod::Aes128,
"https://www.example.com/hls-key/key.bin".parse().unwrap(),
"https://www.example.com/hls-key/key.bin",
);
key.set_iv([
16, 239, 143, 117, 140, 165, 85, 17, 85, 132, 187, 91, 60, 104, 127, 82,

View file

@ -2,7 +2,6 @@ use std::fmt;
use std::str::FromStr;
use derive_builder::Builder;
use url::Url;
use crate::attribute::AttributePairs;
use crate::types::{EncryptionMethod, InitializationVector, ProtocolVersion};
@ -14,7 +13,7 @@ use crate::Error;
pub struct DecryptionKey {
pub(crate) method: EncryptionMethod,
#[builder(setter(into, strip_option), default)]
pub(crate) uri: Option<Url>,
pub(crate) uri: Option<String>,
#[builder(setter(into, strip_option), default)]
pub(crate) iv: Option<InitializationVector>,
#[builder(setter(into, strip_option), default)]
@ -27,13 +26,11 @@ impl DecryptionKey {
/// Makes a new `DecryptionKey`.
/// # Example
/// ```
/// use url::Url;
///
/// use hls_m3u8::types::{EncryptionMethod, DecryptionKey};
///
/// let key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// assert_eq!(
@ -41,10 +38,10 @@ impl DecryptionKey {
/// "METHOD=AES-128,URI=\"https://www.example.com/\""
/// );
/// ```
pub const fn new(method: EncryptionMethod, uri: Url) -> Self {
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
Self {
method,
uri: Some(uri),
uri: Some(uri.to_string()),
iv: None,
key_format: None,
key_format_versions: None,
@ -58,7 +55,7 @@ impl DecryptionKey {
///
/// let key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// assert_eq!(
@ -82,7 +79,7 @@ impl DecryptionKey {
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// key.set_method(EncryptionMethod::SampleAes);
@ -105,39 +102,41 @@ impl DecryptionKey {
///
/// let key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// assert_eq!(
/// key.uri(),
/// &Some("https://www.example.com".parse().unwrap())
/// &Some("https://www.example.com/".to_string())
/// );
/// ```
pub const fn uri(&self) -> &Option<Url> {
pub const fn uri(&self) -> &Option<String> {
&self.uri
}
/// Sets the `URI` attribute.
///
/// This attribute is required, if the [EncryptionMethod] is not None.
/// # Note
/// This attribute is required, if the [EncryptionMethod] is not `None`.
///
/// # Example
/// ```
/// use hls_m3u8::types::{DecryptionKey, EncryptionMethod};
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// key.set_uri("http://www.google.com".parse().unwrap());
/// key.set_uri(Some("http://www.google.com/"));
///
/// assert_eq!(
/// key.to_string(),
/// "METHOD=AES-128,URI=\"http://www.google.com/\"".to_string()
/// );
/// ```
pub fn set_uri(&mut self, value: Url) {
self.uri = Some(value);
pub fn set_uri<T: ToString>(&mut self, value: Option<T>) {
self.uri = value.map(|v| v.to_string());
}
/// Returns the IV (Initialization Vector) attribute.
@ -149,7 +148,7 @@ impl DecryptionKey {
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// key.set_iv([
@ -178,7 +177,7 @@ impl DecryptionKey {
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// key.set_iv([
@ -207,7 +206,7 @@ impl DecryptionKey {
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// key.set_key_format("key_format_attribute");
@ -230,7 +229,7 @@ impl DecryptionKey {
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// key.set_key_format("key_format_attribute");
@ -257,7 +256,7 @@ impl DecryptionKey {
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// key.set_key_format_versions("1/2/3/4/5");
@ -280,7 +279,7 @@ impl DecryptionKey {
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// key.set_key_format_versions("1/2/3/4/5");
@ -301,7 +300,7 @@ impl DecryptionKey {
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com".parse().unwrap()
/// "https://www.example.com/"
/// );
///
/// assert_eq!(
@ -333,7 +332,7 @@ impl FromStr for DecryptionKey {
for (key, value) in input.parse::<AttributePairs>()? {
match key.as_str() {
"METHOD" => method = Some((value.parse())?),
"URI" => uri = Some(unquote(value).parse()?),
"URI" => uri = Some(unquote(value)),
"IV" => iv = Some((value.parse())?),
"KEYFORMAT" => key_format = Some(unquote(value)),
"KEYFORMATVERSIONS" => key_format_versions = Some(unquote(value)),
@ -391,7 +390,7 @@ mod test {
fn test_builder() {
let key = DecryptionKey::builder()
.method(EncryptionMethod::Aes128)
.uri("https://www.example.com".parse::<Url>().unwrap())
.uri("https://www.example.com/")
.iv([
16, 239, 143, 117, 140, 165, 85, 17, 85, 132, 187, 91, 60, 104, 127, 82,
])
@ -409,7 +408,7 @@ mod test {
fn test_display() {
let mut key = DecryptionKey::new(
EncryptionMethod::Aes128,
"https://www.example.com/hls-key/key.bin".parse().unwrap(),
"https://www.example.com/hls-key/key.bin",
);
key.set_iv([
16, 239, 143, 117, 140, 165, 85, 17, 85, 132, 187, 91, 60, 104, 127, 82,
@ -432,13 +431,13 @@ mod test {
.unwrap(),
DecryptionKey::new(
EncryptionMethod::Aes128,
"https://priv.example.com/key.php?r=52".parse().unwrap()
"https://priv.example.com/key.php?r=52"
)
);
let mut key = DecryptionKey::new(
EncryptionMethod::Aes128,
"https://www.example.com/hls-key/key.bin".parse().unwrap(),
"https://www.example.com/hls-key/key.bin",
);
key.set_iv([
16, 239, 143, 117, 140, 165, 85, 17, 85, 132, 187, 91, 60, 104, 127, 82,
@ -453,10 +452,7 @@ mod test {
key
);
let mut key = DecryptionKey::new(
EncryptionMethod::Aes128,
"http://www.example.com".parse().unwrap(),
);
let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "http://www.example.com");
key.set_iv([
16, 239, 143, 117, 140, 165, 85, 17, 85, 132, 187, 91, 60, 104, 127, 82,
]);

View file

@ -36,11 +36,11 @@ fn test_simple_playlist() {
assert_eq!(
media_playlist.segments()[0].uri(),
&"http://media.example.com/entire1.ts".parse().unwrap()
&"http://media.example.com/entire1.ts".to_string()
);
assert_eq!(
media_playlist.segments()[1].uri(),
&"http://media.example.com/entire2.ts".parse().unwrap()
&"http://media.example.com/entire2.ts".to_string()
);
}