Compare commits
2 commits
70dffdec73
...
7589ec5051
Author | SHA1 | Date | |
---|---|---|---|
7589ec5051 | |||
79ef071751 |
5 changed files with 35 additions and 14 deletions
2
.env.example
Normal file
2
.env.example
Normal file
|
@ -0,0 +1,2 @@
|
|||
MUSIXMATCH_EMAIL=mail@example.com
|
||||
MUSIXMATCH_PASSWORD=super-secret
|
|
@ -49,6 +49,7 @@ env_logger = "0.10.0"
|
|||
dotenvy = "0.15.5"
|
||||
tokio = { version = "1.20.0", features = ["macros"] }
|
||||
futures = "0.3.21"
|
||||
path_macro = "1.0.0"
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
|
|
|
@ -24,3 +24,12 @@ lyrics site/app. If you want to use Musixmatch data for this purpose,
|
|||
you will have to give them money (see their
|
||||
[commercial plans](https://developer.musixmatch.com/plans))
|
||||
and use their [official API](https://developer.musixmatch.com/documentation).
|
||||
|
||||
## Development info
|
||||
|
||||
Running the tests requires Musixmatch credentials. The credentials are read
|
||||
from the `MUSIXMATCH_EMAIL` and `MUSIXMATCH_PASSWORD` environment variables.
|
||||
|
||||
To make local development easier, I have included `dotenvy` to read the
|
||||
credentials from an `.env` file. Copy the `.env.example` file
|
||||
in the root directory, rename it to `.env` and fill in your credentials.
|
||||
|
|
|
@ -112,7 +112,7 @@ impl Musixmatch {
|
|||
.gzip(true)
|
||||
.cookie_store(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
.expect("http client could not be constructed");
|
||||
|
||||
Self {
|
||||
inner: Arc::new(MusixmatchRef {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
use time::macros::{date, datetime};
|
||||
|
||||
|
@ -19,7 +22,7 @@ fn init() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn new_mxm() -> Musixmatch {
|
||||
fn new_mxm() -> Musixmatch {
|
||||
Musixmatch::new(
|
||||
&std::env::var("MUSIXMATCH_EMAIL").unwrap(),
|
||||
&std::env::var("MUSIXMATCH_PASSWORD").unwrap(),
|
||||
|
@ -27,6 +30,10 @@ pub fn new_mxm() -> Musixmatch {
|
|||
)
|
||||
}
|
||||
|
||||
fn testfile<P: AsRef<Path>>(name: P) -> PathBuf {
|
||||
path!(env!("CARGO_MANIFEST_DIR") / "testfiles" / name)
|
||||
}
|
||||
|
||||
mod album {
|
||||
use super::*;
|
||||
use musixmatch_inofficial::models::AlbumType;
|
||||
|
@ -679,7 +686,7 @@ mod track {
|
|||
|
||||
mod lyrics {
|
||||
use futures::stream::{self, StreamExt};
|
||||
use std::{fs::File, io::BufWriter, path::Path};
|
||||
use std::{fs::File, io::BufWriter};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -756,7 +763,7 @@ mod lyrics {
|
|||
|
||||
#[tokio::test]
|
||||
async fn download_testdata() {
|
||||
let json_path = Path::new("testfiles/lyrics.json");
|
||||
let json_path = testfile("lyrics.json");
|
||||
if json_path.exists() {
|
||||
return;
|
||||
}
|
||||
|
@ -772,7 +779,7 @@ mod lyrics {
|
|||
|
||||
#[tokio::test]
|
||||
async fn download_testdata_translation() {
|
||||
let json_path = Path::new("testfiles/translation.json");
|
||||
let json_path = testfile("translation.json");
|
||||
if json_path.exists() {
|
||||
return;
|
||||
}
|
||||
|
@ -818,7 +825,7 @@ mod lyrics {
|
|||
}
|
||||
|
||||
mod subtitles {
|
||||
use std::{fs::File, io::BufWriter, path::Path};
|
||||
use std::{fs::File, io::BufWriter};
|
||||
|
||||
use super::*;
|
||||
use musixmatch_inofficial::models::SubtitleFormat;
|
||||
|
@ -925,7 +932,7 @@ mod subtitles {
|
|||
|
||||
#[tokio::test]
|
||||
async fn download_testdata() {
|
||||
let json_path = Path::new("testfiles/subtitles.json");
|
||||
let json_path = testfile("subtitles.json");
|
||||
if json_path.exists() {
|
||||
return;
|
||||
}
|
||||
|
@ -946,15 +953,17 @@ mod subtitles {
|
|||
}
|
||||
|
||||
mod translation {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use musixmatch_inofficial::models::{Lyrics, Subtitle, TranslationList, TranslationMap};
|
||||
|
||||
use crate::testfile;
|
||||
|
||||
#[test]
|
||||
fn translation_test() {
|
||||
let lyrics_path = Path::new("testfiles/lyrics.json");
|
||||
let subtitles_path = Path::new("testfiles/subtitles.json");
|
||||
let translation_path = Path::new("testfiles/translation.json");
|
||||
let lyrics_path = testfile("lyrics.json");
|
||||
let subtitles_path = testfile("subtitles.json");
|
||||
let translation_path = testfile("translation.json");
|
||||
|
||||
let lyrics: Lyrics =
|
||||
serde_json::from_reader(BufReader::new(File::open(lyrics_path).unwrap())).unwrap();
|
||||
|
@ -966,13 +975,13 @@ mod translation {
|
|||
let t_map = TranslationMap::from(translations);
|
||||
|
||||
let lyrics_trans = t_map.translate_lyrics(&lyrics.lyrics_body);
|
||||
let expected_lyrics = std::fs::read_to_string("testfiles/translated_lyrics.txt").unwrap();
|
||||
let expected_lyrics = std::fs::read_to_string(testfile("translated_lyrics.txt")).unwrap();
|
||||
assert_eq!(lyrics_trans.trim(), expected_lyrics.trim());
|
||||
|
||||
let subtitles_trans = t_map.translate_subtitles(&subtitle.to_lines().unwrap());
|
||||
|
||||
let expected_lrc = std::fs::read_to_string("testfiles/translated_subtitles.lrc").unwrap();
|
||||
let expected_ttml = std::fs::read_to_string("testfiles/translated_subtitles.xml").unwrap();
|
||||
let expected_lrc = std::fs::read_to_string(testfile("translated_subtitles.lrc")).unwrap();
|
||||
let expected_ttml = std::fs::read_to_string(testfile("translated_subtitles.xml")).unwrap();
|
||||
|
||||
assert_eq!(subtitles_trans.to_lrc().trim(), expected_lrc.trim());
|
||||
assert_eq!(subtitles_trans.to_ttml().trim(), expected_ttml.trim());
|
||||
|
|
Loading…
Reference in a new issue