Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rezkhaleghi committed Nov 28, 2024
1 parent 472ede9 commit f481cc9
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
serde_json = "1.0"
dotenv = "0.15" # Rust bindings for yt-dlp (or call directly)
async-trait = "0.1.83"
async-trait = "0.1.83"
109 changes: 108 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,108 @@
# pj-player
# PJ-Player

PJ-Player is a Rust-based application that allows users to search and download audio tracks from various sources like YouTube and Internet Archive. The program uses external tools like `yt-dlp` and `wget` for downloading audio and supports searching from multiple platforms via their respective APIs.

## Features

- **Search for audio** on YouTube, Internet Archive, and (future) Spotify.
- **Download audio** from YouTube or Internet Archive.
- Support for **command-line arguments** and **interactive search**.
- Customizable search query input via terminal.

## Requirements

Before running PJ-Player, you need to ensure that the following dependencies are installed on your system:

- **Rust**: This project is written in Rust. Install Rust by following the instructions at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).
- **yt-dlp**: A YouTube downloader tool. Install it from [https://github.com/yt-dlp/yt-dlp](https://github.com/yt-dlp/yt-dlp).
- **wget**: A command-line tool to download files from the web. Install it from [https://www.gnu.org/software/wget/](https://www.gnu.org/software/wget/).
- **dotenv**: The application uses environment variables for certain configurations (like YouTube API key). Install the necessary `.env` file and configure API keys.

## Installation

To use [`PJ-Player`]

1. **Install Rust** (if not already installed):

- Follow the instructions on the official [Rust installation page](https://www.rust-lang.org/tools/install).
- On most systems, you can install it via the following command:
```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

2. **Clone the Repository**:
Clone this repository to your local machine:

```sh
git clone https://github.com/rezkhaleghi/pj-player.git
cd pj-player
```

3. **Build the Project**:
Build the pjgrep application with the following command:

```sh
cargo build --release
```

4. **Install the Binary**:
Optionally, you can copy the binary to a directory in your `$PATH` (e.g., `/usr/local/bin` or `~/bin`) for easy access:

```sh
cp target/release/pjplayer /usr/local/bin/pjplayer
```

## Usage

1. **Run the application without any arguments**:

```sh
pjplayer "Portishead Glorybox"
```

2. **Select the source where you want to search for the song**:

```sh
Where would you like to search for the song?
(Press ENTER to default to WWW)
1. YouTube
2. Internet Archive
```

3. **Select the result number you wish to download from the search results list and wait for the file to finish downloading.**:

````sh
Found the following results:
1. Portishead - Glory Box (ID: 4qQyUi4zfDs, Source: YouTube)
2. Portishead - Glory Box - Remastered (ID: yAKX51r7erw, Source: YouTube)
3. Portishead Glory Box Live At Roseland NY ( Best Audio) (ID: MnMTK8EdsOc, Source: YouTube)
4. Portishead - Glory Box (lyrics) (ID: g2lhOPjLEfk, Source: YouTube)
5. Portishead - Glory box (Roseland NYC) (HQ) (ID: SLrkE6T_m5Y, Source: YouTube)
6. Glory Box (Live) (ID: JBfAtRvW1Ao, Source: YouTube)
7. Portishead - Glory Box (Lyrics) [Tiktok Song] (ID: 2XTLhm6EcFw, Source: YouTube)
8. Portishead Glory Box Live (ID: C3LK5ELvZwI, Source: YouTube)
9. Portishead - Glory Box (HD Version) (ID: 6ylDDs3mdJE, Source: YouTube)
10. Portishead - glory box (ID: yF-GvT8Clnk, Source: YouTube)
```

## Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

## Author

Created and maintained by "PocketJack (Rez Khaleghi)"

- GitHub: https://github.com/rezkhaleghi
- Email: [email protected]

## License

This project is licensed under the MIT License. See the LICENSE file for details.

## Acknowledgements

- [Rust Programming Language](https://www.rust-lang.org/)

# pj-grep
````
14 changes: 8 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ async fn main() {

// Ask the user to choose a source
println!("Where would you like to search for the song?");
println!("(Press ENTER to default to WWW)");
println!("1. YouTube");
println!("2. Internet Archive");
println!("3. Spotify");
println!("4. WWW (YouTube + Internet Archive)");
// println!("4. WWW (YouTube + Internet Archive)");

let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
let choice: usize = input.trim().parse().expect("Invalid input");

// If input is empty, default to WWW (4)
let choice: usize = input.trim().parse().unwrap_or(4); // Default to 4 (WWW) if input is empty or invalid

let source = match choice {
1 => Source::YouTube,
Expand Down Expand Up @@ -113,8 +116,7 @@ async fn main() {

/// Searches for a song on YouTube using the YouTube Data API.
async fn search_youtube(query: &str) -> Result<Vec<(String, String, Source)>, Box<dyn std::error::Error>> {
// let api_key = env::var("YOUTUBE_API_KEY").expect("Missing YouTube API Key");
let api_key = "AIzaSyD9sc6z8J8I-imV-htavHTb1NP_q3EDcOY";
let api_key = "AIzaSyD9sc6z8J8I-imV-htavHTb1NP_q3EDcOY"; // Add your API key here
let url = format!(
"https://www.googleapis.com/youtube/v3/search?part=snippet&q={}&type=video&maxResults=10&key={}",
query, api_key
Expand Down Expand Up @@ -236,10 +238,10 @@ fn get_query_from_terminal() -> String {
}

// If no arguments, prompt the user for the search query
println!("Enter the search query:");
println!("Please enter the name of the song or artist you'd like to search for (e.g., 'Glorybox by Portishead' or 'Tool Sober'): ");
let mut query = String::new();
io::stdin()
.read_line(&mut query)
.expect("Failed to read line");
query.trim().to_string() // Return the query without trailing whitespace
query.trim().to_string()
}

0 comments on commit f481cc9

Please sign in to comment.