mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
core API: move spotify_id to lib.rs
This commit is contained in:
parent
6a9084b00c
commit
4c2b641cad
11 changed files with 67 additions and 69 deletions
|
@ -11,7 +11,7 @@ use tempfile::NamedTempFile;
|
|||
|
||||
use core::channel::{Channel, ChannelData, ChannelError, ChannelHeaders};
|
||||
use core::session::Session;
|
||||
use core::util::FileId;
|
||||
use core::spotify_id::FileId;
|
||||
|
||||
const CHUNK_SIZE: usize = 0x20000;
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ use protobuf::{self, Message};
|
|||
use core::config::ConnectConfig;
|
||||
use core::mercury::MercuryError;
|
||||
use core::session::Session;
|
||||
use core::util::{SeqGenerator, SpotifyId};
|
||||
use core::spotify_id::SpotifyId;
|
||||
use core::util::SeqGenerator;
|
||||
use core::version;
|
||||
|
||||
use protocol;
|
||||
|
|
|
@ -5,7 +5,7 @@ use futures::sync::oneshot;
|
|||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
|
||||
use util::{FileId, SpotifyId};
|
||||
use spotify_id::{FileId, SpotifyId};
|
||||
use util::SeqGenerator;
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)]
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::path::Path;
|
|||
use std::path::PathBuf;
|
||||
|
||||
use authentication::Credentials;
|
||||
use util::FileId;
|
||||
use spotify_id::FileId;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Cache {
|
||||
|
|
|
@ -44,5 +44,6 @@ pub mod diffie_hellman;
|
|||
pub mod keymaster;
|
||||
pub mod mercury;
|
||||
pub mod session;
|
||||
pub mod spotify_id;
|
||||
pub mod util;
|
||||
pub mod version;
|
||||
|
|
|
@ -6,10 +6,8 @@ use std::mem;
|
|||
use std::ops::{Mul, Rem, Shr};
|
||||
|
||||
mod int128;
|
||||
mod spotify_id;
|
||||
|
||||
pub use util::int128::u128;
|
||||
pub use util::spotify_id::{FileId, SpotifyId};
|
||||
|
||||
pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
|
||||
rng.gen_iter().take(size).collect()
|
||||
|
|
|
@ -7,7 +7,7 @@ use tokio_core::reactor::Core;
|
|||
use librespot::core::authentication::Credentials;
|
||||
use librespot::playback::config::{PlayerConfig, SessionConfig};
|
||||
use librespot::core::session::Session;
|
||||
use librespot::core::util::SpotifyId;
|
||||
use librespot::core::spotify_id::SpotifyId;
|
||||
|
||||
use librespot::audio_backend;
|
||||
use librespot::player::Player;
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::io::Write;
|
|||
|
||||
use core::channel::ChannelData;
|
||||
use core::session::Session;
|
||||
use core::util::FileId;
|
||||
use core::spotify_id::FileId;
|
||||
|
||||
pub fn get(session: &Session, file: FileId) -> ChannelData {
|
||||
let (channel_id, channel) = session.channel().allocate();
|
||||
|
|
|
@ -13,7 +13,8 @@ use linear_map::LinearMap;
|
|||
|
||||
use core::mercury::MercuryError;
|
||||
use core::session::Session;
|
||||
use core::util::{SpotifyId, FileId, StrChunksExt};
|
||||
use core::spotify_id::{FileId, SpotifyId};
|
||||
use core::util::StrChunksExt;
|
||||
|
||||
pub use protocol::metadata::AudioFile_Format as FileFormat;
|
||||
|
||||
|
@ -22,7 +23,8 @@ fn countrylist_contains(list: &str, country: &str) -> bool {
|
|||
}
|
||||
|
||||
fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) -> bool
|
||||
where I: IntoIterator<Item = &'s protocol::metadata::Restriction>
|
||||
where
|
||||
I: IntoIterator<Item = &'s protocol::metadata::Restriction>,
|
||||
{
|
||||
let mut forbidden = "".to_string();
|
||||
let mut has_forbidden = false;
|
||||
|
@ -30,9 +32,9 @@ fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) ->
|
|||
let mut allowed = "".to_string();
|
||||
let mut has_allowed = false;
|
||||
|
||||
let rs = restrictions.into_iter().filter(|r|
|
||||
r.get_catalogue_str().contains(&catalogue.to_owned())
|
||||
);
|
||||
let rs = restrictions
|
||||
.into_iter()
|
||||
.filter(|r| r.get_catalogue_str().contains(&catalogue.to_owned()));
|
||||
|
||||
for r in rs {
|
||||
if r.has_countries_forbidden() {
|
||||
|
@ -46,12 +48,12 @@ fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) ->
|
|||
}
|
||||
}
|
||||
|
||||
(has_forbidden || has_allowed) &&
|
||||
(!has_forbidden || !countrylist_contains(forbidden.as_str(), country)) &&
|
||||
(!has_allowed || countrylist_contains(allowed.as_str(), country))
|
||||
(has_forbidden || has_allowed)
|
||||
&& (!has_forbidden || !countrylist_contains(forbidden.as_str(), country))
|
||||
&& (!has_allowed || countrylist_contains(allowed.as_str(), country))
|
||||
}
|
||||
|
||||
pub trait Metadata : Send + Sized + 'static {
|
||||
pub trait Metadata: Send + Sized + 'static {
|
||||
type Message: protobuf::MessageStatic;
|
||||
|
||||
fn base_url() -> &'static str;
|
||||
|
@ -136,9 +138,7 @@ impl Metadata for Track {
|
|||
.iter()
|
||||
.map(|alt| SpotifyId::from_raw(alt.get_gid()))
|
||||
.collect(),
|
||||
available: parse_restrictions(msg.get_restriction(),
|
||||
&country,
|
||||
"premium"),
|
||||
available: parse_restrictions(msg.get_restriction(), &country, "premium"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,6 @@ impl Metadata for Album {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Metadata for Artist {
|
||||
type Message = protocol::metadata::Artist;
|
||||
|
||||
|
@ -198,22 +197,21 @@ impl Metadata for Artist {
|
|||
|
||||
let top_tracks: Vec<SpotifyId> = match msg.get_top_track()
|
||||
.iter()
|
||||
.find(|tt| !tt.has_country() || countrylist_contains(tt.get_country(), &country)) {
|
||||
Some(tracks) => {
|
||||
tracks.get_track()
|
||||
.find(|tt| !tt.has_country() || countrylist_contains(tt.get_country(), &country))
|
||||
{
|
||||
Some(tracks) => tracks
|
||||
.get_track()
|
||||
.iter()
|
||||
.filter(|track| track.has_gid())
|
||||
.map(|track| SpotifyId::from_raw(track.get_gid()))
|
||||
.collect::<Vec<_>>()
|
||||
},
|
||||
None => Vec::new()
|
||||
.collect::<Vec<_>>(),
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
|
||||
Artist {
|
||||
id: SpotifyId::from_raw(msg.get_gid()),
|
||||
name: msg.get_name().to_owned(),
|
||||
top_tracks: top_tracks
|
||||
top_tracks: top_tracks,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::time::Duration;
|
|||
|
||||
use config::{Bitrate, PlayerConfig};
|
||||
use core::session::Session;
|
||||
use core::util::SpotifyId;
|
||||
use core::spotify_id::SpotifyId;
|
||||
|
||||
use audio_backend::Sink;
|
||||
use audio::{AudioFile, AudioDecrypt};
|
||||
|
|
Loading…
Reference in a new issue