mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-31 21:22:22 +00:00
parent
e17688a2da
commit
a5ebefd736
5 changed files with 54 additions and 1 deletions
|
@ -16,6 +16,7 @@ librespot = { version = "0.4", default-features = false }
|
|||
tokio = "1.0"
|
||||
futures = "0.3"
|
||||
anyhow = "1.0"
|
||||
url = "2.3"
|
||||
|
||||
[lib]
|
||||
name = "gstspotify"
|
||||
|
|
|
@ -21,4 +21,10 @@ The `spotifyaudiosrc` element can be used to play a song from Spotify using its
|
|||
|
||||
```
|
||||
gst-launch-1.0 spotifyaudiosrc username=$USERNAME password=$PASSWORD track=spotify:track:3i3P1mGpV9eRlfKccjDjwi ! oggdemux ! vorbisdec ! audioconvert ! autoaudiosink
|
||||
```
|
||||
|
||||
The element also implements an URI handler which accepts credentials and cache settings as URI parameters:
|
||||
|
||||
```console
|
||||
gst-launch-1.0 playbin3 uri=spotify:track:3i3P1mGpV9eRlfKccjDjwi?username=$USERNAME\&password=$PASSWORD\&cache-credentials=cache\&cache-files=cache
|
||||
```
|
|
@ -83,6 +83,7 @@ impl ObjectSubclass for SpotifyAudioSrc {
|
|||
const NAME: &'static str = "GstSpotifyAudioSrc";
|
||||
type Type = super::SpotifyAudioSrc;
|
||||
type ParentType = gst_base::BaseSrc;
|
||||
type Interfaces = (gst::URIHandler,);
|
||||
}
|
||||
|
||||
impl ObjectImpl for SpotifyAudioSrc {
|
||||
|
@ -413,3 +414,45 @@ impl Sink for BufferSink {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl URIHandlerImpl for SpotifyAudioSrc {
|
||||
const URI_TYPE: gst::URIType = gst::URIType::Src;
|
||||
|
||||
fn protocols() -> &'static [&'static str] {
|
||||
&["spotify"]
|
||||
}
|
||||
|
||||
fn uri(&self) -> Option<String> {
|
||||
let settings = self.settings.lock().unwrap();
|
||||
|
||||
if settings.track.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(settings.track.clone())
|
||||
}
|
||||
}
|
||||
|
||||
fn set_uri(&self, uri: &str) -> Result<(), glib::Error> {
|
||||
gst::debug!(CAT, imp: self, "set URI: {}", uri);
|
||||
|
||||
let url = url::Url::parse(uri)
|
||||
.map_err(|e| glib::Error::new(gst::URIError::BadUri, &format!("{:?}", e)))?;
|
||||
|
||||
// allow to configure auth and cache settings from the URI
|
||||
for (key, value) in url.query_pairs() {
|
||||
match key.as_ref() {
|
||||
"username" | "password" | "cache-credentials" | "cache-files" => {
|
||||
self.instance().set_property(&key, value.as_ref());
|
||||
}
|
||||
_ => {
|
||||
gst::warning!(CAT, imp: self, "unsupported query: {}={}", key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.instance()
|
||||
.set_property("track", format!("{}:{}", url.scheme(), url.path()));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use gst::prelude::*;
|
|||
mod imp;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct SpotifyAudioSrc(ObjectSubclass<imp::SpotifyAudioSrc>) @extends gst_base::BaseSrc, gst::Element, gst::Object;
|
||||
pub struct SpotifyAudioSrc(ObjectSubclass<imp::SpotifyAudioSrc>) @extends gst_base::BaseSrc, gst::Element, gst::Object, @implements gst::URIHandler;
|
||||
}
|
||||
|
||||
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
||||
|
|
|
@ -5565,6 +5565,9 @@
|
|||
"GInitiallyUnowned",
|
||||
"GObject"
|
||||
],
|
||||
"interfaces": [
|
||||
"GstURIHandler"
|
||||
],
|
||||
"klass": "Source/Audio",
|
||||
"long-name": "Spotify source",
|
||||
"pad-templates": {
|
||||
|
|
Loading…
Reference in a new issue