mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-06-20 23:20:36 +00:00
parent
e17688a2da
commit
a5ebefd736
|
@ -16,6 +16,7 @@ librespot = { version = "0.4", default-features = false }
|
||||||
tokio = "1.0"
|
tokio = "1.0"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
url = "2.3"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "gstspotify"
|
name = "gstspotify"
|
||||||
|
|
|
@ -22,3 +22,9 @@ 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
|
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";
|
const NAME: &'static str = "GstSpotifyAudioSrc";
|
||||||
type Type = super::SpotifyAudioSrc;
|
type Type = super::SpotifyAudioSrc;
|
||||||
type ParentType = gst_base::BaseSrc;
|
type ParentType = gst_base::BaseSrc;
|
||||||
|
type Interfaces = (gst::URIHandler,);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for SpotifyAudioSrc {
|
impl ObjectImpl for SpotifyAudioSrc {
|
||||||
|
@ -413,3 +414,45 @@ impl Sink for BufferSink {
|
||||||
Ok(())
|
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;
|
mod imp;
|
||||||
|
|
||||||
glib::wrapper! {
|
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> {
|
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
||||||
|
|
|
@ -5565,6 +5565,9 @@
|
||||||
"GInitiallyUnowned",
|
"GInitiallyUnowned",
|
||||||
"GObject"
|
"GObject"
|
||||||
],
|
],
|
||||||
|
"interfaces": [
|
||||||
|
"GstURIHandler"
|
||||||
|
],
|
||||||
"klass": "Source/Audio",
|
"klass": "Source/Audio",
|
||||||
"long-name": "Spotify source",
|
"long-name": "Spotify source",
|
||||||
"pad-templates": {
|
"pad-templates": {
|
||||||
|
|
Loading…
Reference in a new issue