Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y -qq pkg-config libssl-dev
sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
- name: Checking out sources
uses: actions/checkout@v1
- name: Running cargo build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
with:
toolchain: stable
override: true
# These dependencies are required for `clipboard`
- run: sudo apt-get install -y -qq libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
- uses: actions-rs/cargo@v1
with:
command: test
Expand Down
108 changes: 100 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dirs = "2.0.2"
clap = "2.33.0"
unicode-width = "0.1.6"
backtrace = "0.3.40"
clipboard = "0.5.0"

[[bin]]
bench = false
Expand Down
51 changes: 27 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,35 @@ A configuration file is located at `${HOME}/.config/spotify-tui/config.yml`
(not to be confused with client.yml which handles spotify authentication)

The following is a sample config.yml file:

```yaml
# Sample config file
# Sample config file

keybindings:
# Key stroke can be used if it only uses two keys:
# ctrl-q works,
# ctrl-alt-q doesn't.
back: 'ctrl-q'

jump_to_album: 'a'

# Shift modifiers use a capital letter (also applies with other modifier keys
# like ctrl-A)
jump_to_artist_album: 'A'

manage_devices: 'd'
decrease_volume: '-'
increase_volume: '+'
toggle_playback: ' '
seek_backwards: '<'
seek_forwards: '>'
next_track: 'n'
previous_track: 'p'
help: '?'
shuffle: 's'
repeat: 'r'
search: '/'
# Key stroke can be used if it only uses two keys:
# ctrl-q works,
# ctrl-alt-q doesn't.
back: "ctrl-q"

jump_to_album: "a"

# Shift modifiers use a capital letter (also applies with other modifier keys
# like ctrl-A)
jump_to_artist_album: "A"

manage_devices: "d"
decrease_volume: "-"
increase_volume: "+"
toggle_playback: " "
seek_backwards: "<"
seek_forwards: ">"
next_track: "n"
previous_track: "p"
copy_song_url: "c"
help: "?"
shuffle: "s"
repeat: "r"
search: "/"
```

## Limitations
Expand Down Expand Up @@ -165,6 +167,7 @@ After that there is not much to it.

1. [Install OpenSSL](https://docs.rs/openssl/0.10.25/openssl/#automatic)
1. [Install Rust](https://www.rust-lang.org/tools/install)
1. [Install `xorg-dev`](https://github.com/aweinstock314/rust-clipboard#prerequisites) (required for clipboard support)
1. Clone or fork this repo and `cd` to it
1. And then `cargo run`

Expand Down
25 changes: 24 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::config::ClientConfig;
use super::user_config::UserConfig;
use failure::err_msg;
use failure::{err_msg, format_err};
use rspotify::spotify::client::Spotify;
use rspotify::spotify::model::album::{FullAlbum, SavedAlbum, SimplifiedAlbum};
use rspotify::spotify::model::artist::FullArtist;
Expand All @@ -21,6 +21,9 @@ use std::collections::HashSet;
use std::time::Instant;
use tui::layout::Rect;

use clipboard::ClipboardContext;
use clipboard::ClipboardProvider;

pub const LIBRARY_OPTIONS: [&str; 6] = [
"Made For You",
"Recently Played",
Expand Down Expand Up @@ -236,6 +239,7 @@ pub struct App {
pub user: Option<PrivateUser>,
pub album_list_index: usize,
pub artists_list_index: usize,
pub clipboard_context: Option<ClipboardContext>,
}

impl App {
Expand Down Expand Up @@ -297,6 +301,7 @@ impl App {
},
user: None,
instant_since_last_current_playback_poll: Instant::now(),
clipboard_context: None,
}
}

Expand Down Expand Up @@ -648,6 +653,24 @@ impl App {
}
}

pub fn copy_song_url(&mut self) {
let clipboard = match &mut self.clipboard_context {
Some(ctx) => ctx,
None => return,
};

if let Some(FullPlayingContext {
item: Some(FullTrack { id: Some(id), .. }),
..
}) = &self.current_playback_context
{
if let Err(e) = clipboard.set_contents(format!("https://open.spotify.com/track/{}", id))
{
self.handle_error(format_err!("failed to set clipboard content: {}", e));
}
}
}

fn set_saved_tracks_to_table(&mut self, saved_track_page: &Page<SavedTrack>) {
self.set_tracks_to_table(
saved_track_page
Expand Down
Loading