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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! `lastfm` is an async Rust client to fetch your [Last.fm](https://last.fm) listening history or the track you are currently playing
//!
//! ## Installation
//!
//! Add the following to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! lastfm = "*"
//! ```
//!
//! Replace the `*` with the actual version you want to use.
//!
//!
//! Alternatively you can run:
//!
//! ```bash
//! cargo add lastfm
//! ````
//!
//! ## Usage
//!
//! To use this library you will need a Last.fm account and an API key.
//! You can get one by [registering an application](https://www.last.fm/api/account/create).
//! If you have already registered an application, you can find your API key in the [API settings](https://www.last.fm/api/accounts).
//!
//! ### Create a new client
//!
//! If you have your API key exposed through the `LASTFM_API_KEY` environment variable, you can use the `from_env` method:
//!
//! ```rust,no_run
//! # use lastfm::Client;
//! #
//! let client = Client::<String, &str>::from_env("YOUR_USERNAME");
//! ```
//!
//! Note: this method will panic if `LASTFM_API_KEY` is not set.
//!
//! Alternatively, you can use `try_from_env` which will return a `Result`.
//!
//! ```rust,no_run
//! # use lastfm::Client;
//! #
//! let maybe_client = Client::<String, &str>::try_from_env("YOUR_USERNAME");
//! match maybe_client {
//! Ok(client) => {
//! // do something with the client
//! }
//! Err(e) => {
//! // handle error
//! }
//! }
//! ```
//!
//! Finally, for more advanced configurations you can use a `Client::builder()`:
//!
//! ```rust
//! # use lastfm::Client;
//! #
//! let client = Client::builder().api_key("YOUR_API_KEY").username("YOUR_USERNAME").build();
//! ```
//!
//! ### Fetch the track you are currently playing
//!
//! ```rust,no_run
//! # use lastfm::Client;
//! #
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::builder().api_key("YOUR_API_KEY").username("YOUR_USERNAME").build();
//! let now_playing = client.now_playing().await?;
//! if let Some(track) = now_playing {
//! println!("Now playing: {} - {}", track.artist.name, track.name);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Fetch your listening history
//!
//! **Note**: You will need the `futures-util` crate to use the `Stream` returned by `all_tracks`.
//!
//!
//! ```rust,no_run
//! use futures_util::pin_mut;
//! use futures_util::stream::StreamExt;
//! # use lastfm::Client;
//! #
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::builder().api_key("YOUR_API_KEY").username("YOUR_USERNAME").build();
//! let tracks = client.all_tracks().await?;
//! println!("Total tracks: {}", tracks.total_tracks);
//!
//! let recent_tracks = tracks.into_stream();
//! pin_mut!(recent_tracks); // needed for iteration
//! while let Some(track) = recent_tracks.next().await {
//! match track {
//! Ok(track) => {
//! println!(
//! "{}: {} - {}",
//! track.date.to_rfc2822(),
//! track.artist.name,
//! track.name
//! );
//! }
//! Err(e) => {
//! println!("Error fetching data: {:?}", e);
//! }
//! }
//! }
//! Ok(())
//! }
//! ```
extern crate lazy_static;
pub use ;
pub use reqwest;