Skip to content

Commit

Permalink
Merge pull request #3 from victor-iyi/master
Browse files Browse the repository at this point in the history
Minor changes and refactor
  • Loading branch information
deven96 authored Dec 12, 2020
2 parents 95ca6d8 + 887d8c8 commit 26898cf
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 452 deletions.
49 changes: 3 additions & 46 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "mythra"
version = "0.1.0"
version = "0.1.1"
authors = ["Diretnan Domnan <diretnandomnan@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = { version = "3.1.0", features = ["openssl"] }
actix-web = { version = "3.3.2", features = ["openssl"] }
actix-cors = "0.5.3"
actix-rt = "1.1.1"
async-trait = "0.1.41"
clap = { version = "3.0.0-beta.2", features = ["yaml"] }
cursive = "0.15.0"
env_logger = "0.8.1"
error-chain = "0.4"
error-chain = "0.12"
fantoccini = "0.14.2"
futures = "0.3.5"
indicatif = "0.15.0"
Expand Down
80 changes: 27 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,52 @@
# Mythra

<!-- markdownlint-disable-next-line -->
<p align="center"><img src="assets/muse.jpeg" alt="mythra" height="100px"></p>

<div align="center">
<table>
<tr>
<td>Web API</td>
<td>
<a href="https://github.com/deven96/mythra/actions/">
<img src="https://github.com/deven96/mythra/workflows/Deploy%20to%20Heroku/badge.svg" alt="Deploy Status">
</a>
</td>
</tr>
<tr>
<td>Build and Test</td>
<td>
<a href="https://github.com/deven96/mythra/actions/">
<img src="https://github.com/deven96/mythra/workflows/Build%20and%20Test/badge.svg" alt="Test Status">
</a>
</td>
</tr>
<tr>
<td>Documentation</td>
<td>
<a href="https://bisoncorps.stoplight.io/docs/mythra/reference/Mythra.v1.yaml/">
<img src="https://github.com/deven96/mythra/workflows/Deploy%20docs%20to%20Stoplight/badge.svg" alt="Docs Status">
</a>
</td>
</tr>
<tr>
<td>Releases</td>
<td>
<a href="https://github.com/deven96/mythra/releases">
<img src="https://github.com/deven96/mythra/workflows/Release%20to%20GitHub/badge.svg" alt="Releases Status">
</a>
</td>
</tr>
</table>
</div>
<!-- ![Mythra](assets/muse.jpeg) -->

# Mythra
| Build Type | Status |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Web API | [![Deploy status](https://github.com/deven96/mythra/workflows/Deploy%20to%20Heroku/badge.svg)](https://github.com/deven96/mythra/actions/) |
| Build and Test | [![Test status](https://github.com/deven96/mythra/workflows/Build%20and%20Test/badge.svg)](https://github.com/deven96/mythra/actions/) |
| Documentation | [![Docs status](https://github.com/deven96/mythra/workflows/Deploy%20docs%20to%20Stoplight/badge.svg)](https://bisoncorps.stoplight.io/docs/mythra/reference/Mythra.v1.yaml) |
| Releases | [![Release status](https://github.com/deven96/mythra/workflows/Release%20to%20GitHub/badge.svg)](https://github.com/deven96/mythra/releases) |

In my bid to learn rust I am trying to make a music web scraper



In order to use either the `ncurses` or the `pancurses` backend of a dependent library `cursive`, you will need the ncurses library installed on your system.

## Archlinux

```
```sh
pacman -S ncurses
```

## Ubuntu

```
apt-get install libncursesw5-dev
```sh
apt-get install libncursesw5-dev libssl-dev
```

## Fedora

```
yum install ncurses-devel
```sh
yum install ncurses-devel openssl-devel
```

## macOS

```
```sh
brew install ncurses
```

### Engines

- FreeMP3Cloud

- MP3Red

## Installation

With Rust installed

You must have [chromedriver](https://chromedriver.chromium.org/) available on path and running on port 4444
Expand All @@ -92,23 +64,25 @@ cargo run
./target/debug/mythra search --query "Justin Timberlake Mirrors"

```

Or download from Github [Releases](https://github.com/deven96/mythra/releases)

## Example

<p align="center"><img src="assets/example.gif" alt="mythra example"></p>
![Mythra example](assets/example.gif)
<!-- <p align="center"><img src="assets/example.gif" alt="mythra example"></p> -->

## Deployment

The deployed API version from `mythra api` is available. Please read the [API documentation](https://bisoncorps.stoplight.io/docs/mythra/reference/Mythra.v1.yaml) for usage

## License

This project is opened under the [GNU AGPLv3](https://github.com/deven96/mythra/blob/master/LICENSE) which allows very broad use for both academic and commercial purposes.

This project is opened under the [GNU AGPLv3](./LICENSE) which allows very broad use for both academic and commercial purposes.

## Credits
Library/Resource | Use
------- | -----
[Stoplight](https://stoplight.io) | Generating API docs
[Fantoccini](https://github.com/jonhoo/fantoccini/) | Scraping javascript sites using chromedriver/geckodriver

| Library/Resource | Use |
| --------------------------------------------------- | -------------------------------------------------------- |
| [Stoplight](https://stoplight.io) | Generating API docs |
| [Fantoccini](https://github.com/jonhoo/fantoccini/) | Scraping javascript sites using chromedriver/geckodriver |
79 changes: 39 additions & 40 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
use actix_web::{http::StatusCode, web, App, HttpServer, HttpResponse};
//use actix_cors::Cors;
use actix_web::{middleware::Logger};
use crate::types::MusicRequest;
use crate::engines::mp3red;
use crate::engines::freemp3cloud;
use log::{error, debug};
use crate::engines::mp3red;
use crate::types::MusicRequest;

use actix_web::{http::StatusCode, web, App, HttpResponse, HttpServer};
//use actix_cors::Cors;
use actix_web::middleware::Logger;
use log::{debug, error};

async fn search(web::Query(info): web::Query<MusicRequest>) -> HttpResponse {
debug!("Request for client with engine={} and query={}!", info.engine, info.query);
let query = info.query.clone();
let engine = info.engine.clone();
let engine_match = engine.as_str();
match engine_match {
"mp3red" => {
let e = mp3red::MP3Red{};
let res = e.search(query).await.ok();
HttpResponse::Ok().json(res.unwrap())
},
"freemp3cloud" => {
let e = freemp3cloud::FreeMP3Cloud{};
let res = e.search(query).await.ok();
HttpResponse::Ok().json(res.unwrap())
},
_ => {
error!("Engine {} is unsupported", engine_match);
HttpResponse::new(StatusCode::NOT_FOUND)
},
debug!(
"Request for client with engine={} and query={}!",
info.engine, info.query
);
let query = info.query.clone();
let engine = info.engine.clone();
let engine_match = engine.as_str();
match engine_match {
"mp3red" => {
let e = mp3red::MP3Red {};
let res = e.search(query).await.ok();
HttpResponse::Ok().json(res.unwrap())
}
"freemp3cloud" => {
let e = freemp3cloud::FreeMP3Cloud {};
let res = e.search(query).await.ok();
HttpResponse::Ok().json(res.unwrap())
}
_ => {
error!("Engine {} is unsupported", engine_match);
HttpResponse::new(StatusCode::NOT_FOUND)
}
}
}

pub async fn api(port: &str) -> std::io::Result<()> {
let address: &str = &(format!("0.0.0.0:{}", port))[..];
HttpServer::new(||
App::new()
.wrap(Logger::default())
.wrap(Logger::new("%a %{User-Agent}i"))
.service(
web::resource("/search")
.route(
web::get().to(search)
)
)
)
.bind(address)
.unwrap()
.run()
.await
HttpServer::new(|| {
App::new()
.wrap(Logger::default())
.wrap(Logger::new("%a %{User-Agent}i"))
.service(web::resource("/search").route(web::get().to(search)))
})
.bind(address)
.unwrap()
.run()
.await
}
Loading

0 comments on commit 26898cf

Please sign in to comment.