Compare commits
No commits in common. "7589ec5051b304a76034430c7cce34f9f808b9e8" and "70dffdec73dc7ee5604d65202f53f5b59afa5422" have entirely different histories.
7589ec5051
...
70dffdec73
5 changed files with 14 additions and 35 deletions
|
@ -1,2 +0,0 @@
|
|||
MUSIXMATCH_EMAIL=mail@example.com
|
||||
MUSIXMATCH_PASSWORD=super-secret
|
|
@ -49,7 +49,6 @@ 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,12 +24,3 @@ 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()
|
||||
.expect("http client could not be constructed");
|
||||
.unwrap();
|
||||
|
||||
Self {
|
||||
inner: Arc::new(MusixmatchRef {
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
use time::macros::{date, datetime};
|
||||
|
||||
|
@ -22,7 +19,7 @@ fn init() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn new_mxm() -> Musixmatch {
|
||||
pub fn new_mxm() -> Musixmatch {
|
||||
Musixmatch::new(
|
||||
&std::env::var("MUSIXMATCH_EMAIL").unwrap(),
|
||||
&std::env::var("MUSIXMATCH_PASSWORD").unwrap(),
|
||||
|
@ -30,10 +27,6 @@ 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;
|
||||
|
@ -686,7 +679,7 @@ mod track {
|
|||
|
||||
mod lyrics {
|
||||
use futures::stream::{self, StreamExt};
|
||||
use std::{fs::File, io::BufWriter};
|
||||
use std::{fs::File, io::BufWriter, path::Path};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -763,7 +756,7 @@ mod lyrics {
|
|||
|
||||
#[tokio::test]
|
||||
async fn download_testdata() {
|
||||
let json_path = testfile("lyrics.json");
|
||||
let json_path = Path::new("testfiles/lyrics.json");
|
||||
if json_path.exists() {
|
||||
return;
|
||||
}
|
||||
|
@ -779,7 +772,7 @@ mod lyrics {
|
|||
|
||||
#[tokio::test]
|
||||
async fn download_testdata_translation() {
|
||||
let json_path = testfile("translation.json");
|
||||
let json_path = Path::new("testfiles/translation.json");
|
||||
if json_path.exists() {
|
||||
return;
|
||||
}
|
||||
|
@ -825,7 +818,7 @@ mod lyrics {
|
|||
}
|
||||
|
||||
mod subtitles {
|
||||
use std::{fs::File, io::BufWriter};
|
||||
use std::{fs::File, io::BufWriter, path::Path};
|
||||
|
||||
use super::*;
|
||||
use musixmatch_inofficial::models::SubtitleFormat;
|
||||
|
@ -932,7 +925,7 @@ mod subtitles {
|
|||
|
||||
#[tokio::test]
|
||||
async fn download_testdata() {
|
||||
let json_path = testfile("subtitles.json");
|
||||
let json_path = Path::new("testfiles/subtitles.json");
|
||||
if json_path.exists() {
|
||||
return;
|
||||
}
|
||||
|
@ -953,17 +946,15 @@ mod subtitles {
|
|||
}
|
||||
|
||||
mod translation {
|
||||
use std::{fs::File, io::BufReader};
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
|
||||
use musixmatch_inofficial::models::{Lyrics, Subtitle, TranslationList, TranslationMap};
|
||||
|
||||
use crate::testfile;
|
||||
|
||||
#[test]
|
||||
fn translation_test() {
|
||||
let lyrics_path = testfile("lyrics.json");
|
||||
let subtitles_path = testfile("subtitles.json");
|
||||
let translation_path = testfile("translation.json");
|
||||
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: Lyrics =
|
||||
serde_json::from_reader(BufReader::new(File::open(lyrics_path).unwrap())).unwrap();
|
||||
|
@ -975,13 +966,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(testfile("translated_lyrics.txt")).unwrap();
|
||||
let expected_lyrics = std::fs::read_to_string("testfiles/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(testfile("translated_subtitles.lrc")).unwrap();
|
||||
let expected_ttml = std::fs::read_to_string(testfile("translated_subtitles.xml")).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();
|
||||
|
||||
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