Skip to content

Commit

Permalink
Merge pull request #731 from stevenleadbeater/development
Browse files Browse the repository at this point in the history
Use Oauth2 login with spotify
  • Loading branch information
xou816 authored Nov 19, 2024
2 parents f71cdf3 + 4c9921f commit e3a9c2a
Show file tree
Hide file tree
Showing 55 changed files with 5,534 additions and 1,922 deletions.
2,716 changes: 2,074 additions & 642 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spot"
version = "0.4.1"
version = "0.6.0"
edition = "2018"
license = "MIT"

Expand All @@ -26,7 +26,7 @@ version = "^0.17.9"
features = ["v2_60"]

[dependencies.librespot]
version = "0.4.2"
version = "0.6.0"
features = ["alsa-backend", "pulseaudio-backend", "gstreamer-backend"]

[dependencies.tokio]
Expand Down Expand Up @@ -73,3 +73,6 @@ lazy_static = "1.4.0"
log = "0.4.17"
env_logger = "0.10.0"
percent-encoding = "2.2.0"
oauth2 = "4.4"
url = "2.4.1"
open = "5.3.0"
3,901 changes: 2,815 additions & 1,086 deletions cargo-sources.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(
'spot',
version: '0.4.1',
version: '0.6.0',
meson_version: '>= 0.59.0',
default_options: ['warning_level=2', 'buildtype=release'],
)
Expand Down
1 change: 1 addition & 0 deletions src/api/api_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub struct Artist {

impl WithImages for Artist {
fn images(&self) -> &[Image] {
#[allow(clippy::manual_unwrap_or_default)]
if let Some(ref images) = self.images {
images
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/api/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum CacheError {
pub type ETag = String;

pub enum CacheFile {
Fresh(Vec<u8>, Option<ETag>),
Fresh(Vec<u8>),
Expired(Vec<u8>, Option<ETag>),
None,
}
Expand Down Expand Up @@ -138,7 +138,7 @@ impl CacheManager {
let (file, expiry) = join!(fs::read(&path), self.read_expiry_file(resource));

match (file, policy) {
(Ok(buf), CachePolicy::IgnoreExpiry) => Ok(CacheFile::Fresh(buf, None)),
(Ok(buf), CachePolicy::IgnoreExpiry) => Ok(CacheFile::Fresh(buf)),
(Ok(buf), CachePolicy::Revalidate) => {
let expiry = expiry.unwrap_or(CacheExpiry::Never);
let etag = expiry.etag().cloned();
Expand All @@ -150,7 +150,7 @@ impl CacheManager {
Ok(if expiry.is_expired() {
CacheFile::Expired(buf, etag)
} else {
CacheFile::Fresh(buf, etag)
CacheFile::Fresh(buf)
})
}
(_, CachePolicy::IgnoreCached) => Ok(CacheFile::None),
Expand Down Expand Up @@ -260,7 +260,7 @@ impl CacheManager {
{
let file = self.read_cache_file(resource, policy).await?;
match file {
CacheFile::Fresh(buf, _) => Ok(buf),
CacheFile::Fresh(buf) => Ok(buf),
CacheFile::Expired(buf, etag) => match fetch(etag).await? {
FetchResult::NotModified(expiry) => {
let meta = self.cache_meta_path(resource);
Expand Down
1 change: 1 addition & 0 deletions src/api/cached_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub trait SpotifyApiClient {

fn player_resume(&self, device_id: String) -> BoxFuture<SpotifyResult<()>>;

#[allow(dead_code)]
fn player_next(&self, device_id: String) -> BoxFuture<SpotifyResult<()>>;

fn player_seek(&self, device_id: String, pos: usize) -> BoxFuture<SpotifyResult<()>>;
Expand Down
49 changes: 49 additions & 0 deletions src/api/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!doctype html>
<html>
<head>
<title>Spot</title>
<style>
body {
background: linear-gradient(#1f1f1f 0%, #121212 100%);
height: 100%;
background-repeat: no-repeat;
background-attachment: fixed;
font-family: sans-serif;
font-size: 18px;
color: white;
}
.success {
background: #121212;
width: 60%;
margin: 32px auto;
padding: 16px;
text-align: center;
background: #121212;
border-radius: 8px;
}
.success h2 {
margin-top: 0;
}
</style>
</head>
<body>
<section class="success">
<svg height="48px" viewBox="0 0 16 16" width="48px" stroke="white" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<clipPath id="c">
<rect height="152" width="192"/>
</clipPath>
<g clip-path="url(#c)" mask="url(#b)" transform="matrix(1 0 0 1 -168 -16)">
<path d="m 72 66 c -19.882812 0 -36 16.117188 -36 36 v 2 c 0 -19.882812 16.117188 -36 36 -36 s 36 16.117188 36 36 v -2 c 0 -19.882812 -16.117188 -36 -36 -36 z m 0 0" fill="#241f31"/>
</g>
<g fill="#241f31">
<path d="m 3 3.855469 l -2.84375 4.925781 c -0.2304688 0.398438 -0.09375 0.90625 0.304688 1.132812 l 7.941406 4.585938 l 4 -6.929688 l -4.402344 -2.542968 v 4.140625 c 0 1 -0.832031 1.832031 -1.828125 1.832031 h -1.339844 c -1 0 -1.832031 -0.832031 -1.832031 -1.832031 z m 10.269531 4.214843 l -4 6.929688 l 1.011719 0.585938 c 0.398438 0.230468 0.90625 0.09375 1.136719 -0.304688 l 3.167969 -5.492188 c 0.230468 -0.394531 0.09375 -0.902343 -0.304688 -1.132812 z m 0 0"/>
<path d="m 4.832031 0 c -0.460937 0 -0.832031 0.371094 -0.832031 0.832031 v 8.335938 c 0 0.460937 0.371094 0.832031 0.832031 0.832031 h 1.335938 c 0.460937 0 0.832031 -0.371094 0.832031 -0.832031 v -8.335938 c 0 -0.460937 -0.371094 -0.832031 -0.832031 -0.832031 z m 0.667969 7.5 c 0.277344 0 0.5 0.222656 0.5 0.5 s -0.222656 0.5 -0.5 0.5 s -0.5 -0.222656 -0.5 -0.5 s 0.222656 -0.5 0.5 -0.5 z m 0 0"/>
</g>
</svg>
<h2>Spot connected</h2>
<p>
Logged in successfully! You may close this window.
</p>
</section>
</body>
</html>
1 change: 1 addition & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod cached_client;
mod client;

pub mod cache;
pub(crate) mod oauth2;

pub use cached_client::{CachedSpotifyClient, SpotifyApiClient, SpotifyResult};
pub use client::SpotifyApiError;
Expand Down
Loading

0 comments on commit e3a9c2a

Please sign in to comment.