Input: Change all Youtube-dl functions to take AsRef<str> (#70)
Unifies the API on all ytdl functions to remove some friction in passing in Strings, Cows, strs, and so on. Closes #57.
This commit is contained in:
@@ -132,8 +132,8 @@ impl Restartable {
|
|||||||
///
|
///
|
||||||
/// The cost of restarting and seeking will probably be *very* high:
|
/// The cost of restarting and seeking will probably be *very* high:
|
||||||
/// expect a pause if you seek backwards.
|
/// expect a pause if you seek backwards.
|
||||||
pub async fn ytdl_search(name: &str, lazy: bool) -> Result<Self> {
|
pub async fn ytdl_search(name: impl AsRef<str>, lazy: bool) -> Result<Self> {
|
||||||
Self::ytdl(format!("ytsearch1:{}", name), lazy).await
|
Self::ytdl(format!("ytsearch1:{}", name.as_ref()), lazy).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn prep_with_handle(&mut self, handle: Handle) {
|
pub(crate) fn prep_with_handle(&mut self, handle: Handle) {
|
||||||
@@ -381,7 +381,7 @@ impl Seek for Restartable {
|
|||||||
|
|
||||||
self.position = offset;
|
self.position = offset;
|
||||||
},
|
},
|
||||||
Live(input, rec) =>
|
Live(input, rec) => {
|
||||||
if offset < self.position {
|
if offset < self.position {
|
||||||
// regen at given start point
|
// regen at given start point
|
||||||
// We're going back in time.
|
// We're going back in time.
|
||||||
@@ -405,6 +405,7 @@ impl Seek for Restartable {
|
|||||||
} else {
|
} else {
|
||||||
// march on with live source.
|
// march on with live source.
|
||||||
self.position += input.consume(offset - self.position);
|
self.position += input.consume(offset - self.position);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Working(_, _, _, _) => {
|
Working(_, _, _, _) => {
|
||||||
return Err(IoError::new(
|
return Err(IoError::new(
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ const YOUTUBE_DL_COMMAND: &str = if cfg!(feature = "youtube-dlc") {
|
|||||||
/// Uses `youtube-dlc` if the `"youtube-dlc"` feature is enabled.
|
/// Uses `youtube-dlc` if the `"youtube-dlc"` feature is enabled.
|
||||||
///
|
///
|
||||||
/// [`Restartable::ytdl`]: crate::input::restartable::Restartable::ytdl
|
/// [`Restartable::ytdl`]: crate::input::restartable::Restartable::ytdl
|
||||||
pub async fn ytdl(uri: &str) -> Result<Input> {
|
pub async fn ytdl(uri: impl AsRef<str>) -> Result<Input> {
|
||||||
_ytdl(uri, &[]).await
|
_ytdl(uri.as_ref(), &[]).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn _ytdl(uri: &str, pre_args: &[&str]) -> Result<Input> {
|
pub(crate) async fn _ytdl(uri: &str, pre_args: &[&str]) -> Result<Input> {
|
||||||
@@ -170,6 +170,6 @@ pub(crate) async fn _ytdl_metadata(uri: &str) -> Result<Metadata> {
|
|||||||
/// Uses `youtube-dlc` if the `"youtube-dlc"` feature is enabled.
|
/// Uses `youtube-dlc` if the `"youtube-dlc"` feature is enabled.
|
||||||
///
|
///
|
||||||
/// [`Restartable::ytdl_search`]: crate::input::restartable::Restartable::ytdl_search
|
/// [`Restartable::ytdl_search`]: crate::input::restartable::Restartable::ytdl_search
|
||||||
pub async fn ytdl_search(name: &str) -> Result<Input> {
|
pub async fn ytdl_search(name: impl AsRef<str>) -> Result<Input> {
|
||||||
ytdl(&format!("ytsearch1:{}", name)).await
|
ytdl(&format!("ytsearch1:{}", name.as_ref())).await
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user