1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
#![warn(missing_docs)]
#![deny(missing_debug_implementations, missing_copy_implementations,
        trivial_casts, trivial_numeric_casts,
        unsafe_code,
        unstable_features,
        unused_import_braces, unused_qualifications)]

//!
//! # mpris
//!
//! `mpris` is an idiomatic library for dealing with MPRIS2-compatible media players over D-Bus.
//!
//! This would mostly apply to the Linux-ecosystem which is a heavy user of D-Bus.
//!
//! ## Getting started
//!
//! Some hints on how to use this library:
//!
//! 1. Look at the examples under `examples/`.
//! 2. Look at the `PlayerFinder` struct.
//!

#[macro_use]
extern crate error_chain;
extern crate dbus;

/// Module containing all the error types.
///
/// This is generated by [`error-chain`][error-chain], which makes it possible to integrate to other crates' uses
/// of `error-chain`.
///
/// [error-chain]: https://crates.io/crates/error-chain
#[allow(missing_docs)]
pub mod errors {
    error_chain!{
        foreign_links {
            DBusError(::dbus::Error);
        }

        errors {
            /// No MPRIS2-compatible player could be found.
            NoPlayerFound {
                description("No player found")
                display("Could not find a compatible MPRIS2 player running right now.")
            }

            /// The `trackId` field could not be read from the player metadata.
            ///
            /// Non-conforming implementations of the MPRIS2 protocol might omit the required
            /// `trackId` field, which would then return this error.
            TrackIdMissing {
                description("track_id missing")
                display("mpris:trackid not present in metadata")
            }

            /// PlaybackStatus had an invalid string value.
            InvalidPlaybackStatus(value: String) {
                description("invalid PlaybackStatus value")
                display("PlaybackStatus must be one of Playing, Paused, Stopped, but was {}", value)
            }

            /// Something went wrong with a D-Bus call or parsing the results from it.
            DBusCallError(message: String) {
                description("D-Bus call failed")
                display("D-Bus call failed: {}", message)
            }
        }
    }
}

mod generated;
mod extensions;

mod pooled_connection;
mod find;
mod metadata;
mod player;
mod progress;

mod prelude {
    pub use errors::*;
}

pub use find::PlayerFinder;
pub use metadata::Metadata;
pub use player::Player;
pub use progress::{Progress, ProgressTracker};

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[allow(missing_docs)]
pub enum PlaybackStatus {
    Playing,
    Paused,
    Stopped,
}

impl ::std::str::FromStr for PlaybackStatus {
    type Err = errors::Error;

    fn from_str(string: &str) -> Result<Self, Self::Err> {
        use PlaybackStatus::*;

        match string {
            "Playing" => Ok(Playing),
            "Paused" => Ok(Paused),
            "Stopped" => Ok(Stopped),
            other => Err(
                errors::ErrorKind::InvalidPlaybackStatus(other.to_owned()).into(),
            ),
        }
    }
}