Initial commit

This commit is contained in:
tranxuanthang
2022-10-23 04:01:27 +07:00
commit 0e99f1a13a
41 changed files with 8006 additions and 0 deletions

10
.editorconfig Normal file
View File

@@ -0,0 +1,10 @@
root = true
[*]
indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

7
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
"recommendations": [
"Vue.volar",
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer"
]
}

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# LRCGET
Utility for mass-downloading LRC synced lyrics for your offline music library.

BIN
app-icon.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

14
index.html Normal file
View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LRCGET</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

2848
package-lock.json generated Normal file
View File

File diff suppressed because it is too large Load Diff

26
package.json Normal file
View File

@@ -0,0 +1,26 @@
{
"name": "lrcget",
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^1.1.0",
"mdue": "^0.1.4",
"overlayscrollbars-vue": "^0.3.0",
"path-browserify": "^1.0.1",
"vue": "^3.2.37"
},
"devDependencies": {
"@tauri-apps/cli": "^1.1.0",
"@vitejs/plugin-vue": "^3.0.1",
"autoprefixer": "^10.4.12",
"postcss": "^8.4.18",
"tailwindcss": "^3.2.1",
"vite": "^3.0.2"
}
}

6
postcss.config.cjs Normal file
View File

@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

6
public/tauri.svg Normal file
View File

@@ -0,0 +1,6 @@
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

1
public/vite.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

4
src-tauri/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/

4099
src-tauri/Cargo.lock generated Normal file
View File

File diff suppressed because it is too large Load Diff

35
src-tauri/Cargo.toml Normal file
View File

@@ -0,0 +1,35 @@
[package]
name = "lrcget"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.57"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.1", features = ["api-all"] }
globwalk = "0.8.1"
audiotags = "0.4.1"
id3 = { git = "https://github.com/tranxuanthang/rust-id3", branch = "slash-fix" }
metaflac = "0.2.5"
lrc = "0.1.7"
reqwest = { version = "0.11.12", features = ["json"] }
window-shadows = "0.2.0"
mp3-duration = "0.1.10"
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]

3
src-tauri/build.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

BIN
src-tauri/icons/128x128.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
src-tauri/icons/32x32.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
src-tauri/icons/icon.icns Normal file
View File

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
src-tauri/icons/icon.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

347
src-tauri/src/main.rs Normal file
View File

@@ -0,0 +1,347 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::error::Error;
use std::fmt;
use audiotags;
use globwalk::glob;
use id3::{TagLike};
use metaflac;
use reqwest;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use tauri::Manager;
use window_shadows::set_shadow;
use mp3_duration;
#[derive(Serialize, Deserialize, Clone, Debug)]
struct MusicItem {
file_path: String,
file_name: String,
track_name: String,
album_name: String,
artist_name: String,
lyrics: String,
duration: f64
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct LrcLibGetResponse {
plain_lyrics: Option<String>,
synced_lyrics: Option<String>,
instrumental: bool,
lang: Option<String>,
isrc: Option<String>,
spotify_id: Option<String>,
name: Option<String>,
album_name: Option<String>,
artist_name: Option<String>,
release_date: Option<String>,
duration: Option<f64>
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct LrcLibResponseError {
status_code: Option<u16>,
error: String,
message: String
}
impl Error for LrcLibResponseError {}
impl fmt::Display for LrcLibResponseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.error, self.message)
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
struct ApplyLyricsProgressPayload {
progress: f32,
successed_items_count: u32,
failed_items_count: u32,
processed_items_count: u32,
total_items_count: u32,
current_track: MusicItem,
current_status: LrcLibStatus,
current_message: Option<String>
}
#[derive(Serialize, Deserialize, Debug, Clone)]
enum LrcLibStatus {
Success,
Failure
}
#[tauri::command]
async fn get_music_files(directory: String, app_handle: tauri::AppHandle) -> Option<Vec<MusicItem>> {
let files = glob(format!("{}\\**\\*.{{mp3,m4a,flac}}", directory));
match files {
Ok(mut files) => {
let mut result: Vec<MusicItem> = Vec::new();
for file in &mut files {
if let Ok(file) = file {
let file_extension = file
.path()
.extension()
.unwrap()
.to_str()
.unwrap()
.to_owned();
let tag = audiotags::Tag::new().read_from_path(file.path());
let mut lyrics = "".to_owned();
/*
if file_extension == "flac" {
let flactag = metaflac::Tag::read_from_path(file.path()).unwrap();
let synced_lyrics_list_result = flactag.get_vorbis("LYRICS");
if let Some(synced_lyrics_list) = synced_lyrics_list_result {
for synced_lyrics in synced_lyrics_list.take(1) {
lyrics = synced_lyrics.to_owned();
}
}
}
if file_extension == "mp3" {
let id3tag = id3::Tag::read_from_path(file.path()).unwrap();
for synced_lyrics in id3tag.synchronised_lyrics() {
let mut lyrics_builder = lrc::Lyrics::new();
for timed_line in &synced_lyrics.content {
lyrics_builder.add_timed_line(lrc::TimeTag::new(timed_line.0), &timed_line.1).unwrap();
}
lyrics = lyrics_builder.to_string();
}
}
*/
let lrc_file_path = lrc_file_path(file.path().display().to_string());
let lrc_content = std::fs::read_to_string(lrc_file_path);
if let Ok(lrc_content) = lrc_content {
lyrics = lrc_content;
}
if let Ok(tag) = tag {
let track_name = tag.title().unwrap_or("").to_owned();
let mut album_name = tag.album_title().unwrap_or("").to_owned();
let mut artist_name = tag.artist().unwrap_or("").to_owned();
// let mut artist_name = tag.artists().unwrap_or(Vec::new()).join(", ").to_owned();
if file_extension == "mp3" {
let id3tag = id3::Tag::read_from_path(file.path()).unwrap();
if let Some(album) = id3tag.album() {
album_name = album.to_owned();
}
if let Some(artist) = id3tag.artist() {
artist_name = artist.to_owned();
}
}
let duration = match tag.duration() {
Some(duration) => duration,
None => {
if file_extension == "mp3" {
match mp3_duration::from_path(file.path()) {
Ok(duration) => duration.as_secs_f64(),
Err(_) => 0.0
}
} else {
0.0
}
}
};
if !track_name.is_empty()
&& !album_name.is_empty()
&& !artist_name.is_empty()
{
result.push(MusicItem {
file_path: file.path().display().to_string(),
file_name: file
.path()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_owned(),
track_name,
album_name,
artist_name,
lyrics,
duration
});
}
}
}
}
Some(result)
}
Err(_) => None,
}
}
async fn get_lyrics_from_lrclib(
music_item: &MusicItem,
) -> Result<LrcLibGetResponse, Box<dyn Error>> {
let params = vec![
("artist_name", music_item.artist_name.to_owned()),
("track_name", music_item.track_name.to_owned()),
("album_name", music_item.album_name.to_owned()),
("duration", music_item.duration.round().to_string()),
];
let url = reqwest::Url::parse_with_params("https://lrclib.net/api/get", &params)?;
let res = reqwest::get(url).await?;
match res.status() {
reqwest::StatusCode::OK => {
Ok(res.json::<LrcLibGetResponse>().await?)
},
reqwest::StatusCode::NOT_FOUND | reqwest::StatusCode::BAD_REQUEST | reqwest::StatusCode::BAD_REQUEST | reqwest::StatusCode::SERVICE_UNAVAILABLE | reqwest::StatusCode::INTERNAL_SERVER_ERROR => {
Err(res.json::<LrcLibResponseError>().await?.into())
},
_ => {
Err(LrcLibResponseError {
status_code: None,
error: "UnknownError".to_string(),
message: "Unknown error happened".to_string()
}.into())
}
}
}
fn lrc_file_path(file_path: String) -> PathBuf {
let path = PathBuf::from(file_path);
let file_name = path.file_name().unwrap().to_str().unwrap().to_owned();
let parent_path = path.parent().unwrap();
let file_name_without_extension = std::path::Path::new(&file_name)
.file_stem()
.unwrap()
.to_str()
.unwrap()
.to_owned();
let mut lrc_file_name = file_name_without_extension.to_owned();
lrc_file_name.push_str(".lrc");
let lrc_file_path = parent_path.join(lrc_file_name);
lrc_file_path
}
#[tauri::command]
async fn apply_lyrics(
music_items: Vec<MusicItem>,
is_create_lrc: bool,
is_embed: bool,
skip_tracks_have_existing_lyrics: bool,
app_handle: tauri::AppHandle,
) {
let mut processed_items_count = 0;
let mut successed_items_count = 0;
let mut failed_items_count = 0;
let mut status: LrcLibStatus;
let mut message: Option<String>;
for music_item in &music_items {
if !music_item.lyrics.is_empty() && skip_tracks_have_existing_lyrics == true {
continue;
}
let data = get_lyrics_from_lrclib(&music_item).await;
match data {
Ok(data) => {
let synced_lyrics = &data.synced_lyrics.clone().unwrap_or_default();
if !synced_lyrics.is_empty() {
let lrc_file_path = lrc_file_path((&music_item.file_path).to_owned());
std::fs::write(lrc_file_path, synced_lyrics).expect("Unable to write file");
}
successed_items_count = successed_items_count + 1;
status = LrcLibStatus::Success;
if *&data.instrumental {
message = Some("Track is instrumental".to_string());
} else {
message = Some("Retrieved lyrics successfully".to_string());
}
},
Err(dyn_err) => {
failed_items_count = failed_items_count + 1;
let error = dyn_err.downcast_ref::<LrcLibResponseError>();
match error {
Some(error) => {
status = LrcLibStatus::Failure;
message = Some((&error.message).to_owned());
},
None => {
status = LrcLibStatus::Failure;
message = Some("Unknown Error".to_string());
}
}
}
}
processed_items_count = processed_items_count + 1;
let music_items = music_items.clone();
let music_item = music_item.clone();
let app_handle = app_handle.clone();
std::thread::spawn(move || {
let total_items_count = music_items.len();
app_handle
.emit_all(
"apply-lyrics-progress",
ApplyLyricsProgressPayload {
progress: (processed_items_count as f32) / (music_items.len() as f32),
successed_items_count,
failed_items_count,
processed_items_count,
total_items_count: total_items_count.try_into().unwrap(),
current_track: music_item,
current_status: status,
current_message: message
},
)
.unwrap();
});
}
}
#[tauri::command]
fn open_devtools(window: tauri::Window) {
#[cfg(debug_assertions)]
{
window.open_devtools();
}
}
fn main() {
tauri::Builder::default()
.setup(|app| {
let window = app.get_window("main").unwrap();
#[cfg(target_os = "windows")]
set_shadow(&window, true).expect("Unsupported platform!");
Ok(())
})
.invoke_handler(tauri::generate_handler![
get_music_files,
apply_lyrics,
open_devtools
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

70
src-tauri/tauri.conf.json Normal file
View File

@@ -0,0 +1,70 @@
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": false
},
"package": {
"productName": "LRCGET",
"version": "0.0.4"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"active": true,
"category": "Music",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "net.lrclib.lrcget",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"minWidth": 1024,
"minHeight": 768,
"width": 1024,
"height": 768,
"resizable": true,
"title": "LRCGET",
"decorations": false,
"transparent": true
}
]
}
}

84
src/App.vue Normal file
View File

@@ -0,0 +1,84 @@
<template>
<div class="h-screen w-screen flex flex-col select-none rounded-lg">
<div data-tauri-drag-region class="flex justify-end items-start h-10 text-sm">
<div v-if="!isProd" class="py-2 px-4 text-hoa-1400 hover:bg-hoa-600 active:bg-hoa-800 transition" @click="openDevtools">
<Bug />
</div>
<div class="py-2 px-4 text-hoa-1400 hover:bg-hoa-600 active:bg-hoa-800 transition" @click="minimizeWindow">
<WindowMinimize />
</div>
<div class="py-2 px-4 text-hoa-1400 hover:bg-hoa-600 active:bg-hoa-800 transition" @click="maximizeWindow">
<WindowMaximize />
</div>
<div class="py-2 px-4 text-hoa-1400 hover:text-hoa-200 hover:bg-hoa-1400 active:bg-hoa-1500 active:text-hoa-200 transition" @click="closeWindow">
<WindowClose />
</div>
</div>
<div class="flex-grow overflow-hidden">
<ChooseDirectory v-if="step === 1" @progressStep="toStep3" />
<SelectStrategy v-else-if="step === 2" @progressStep="toStep3" />
<ApplyLyrics :musicItems="musicItems" :isCreateLRC="isCreateLRC" :isEmbed="isEmbed" :skipTracksHaveExistingLyrics="skipTracksHaveExistingLyrics" @startOver="startOver" v-else-if="step === 3" />
</div>
</div>
</template>
<script setup>
import { Bug } from 'mdue'
import { WindowMinimize } from 'mdue'
import { WindowMaximize } from 'mdue'
import { WindowClose } from 'mdue'
import ChooseDirectory from "./components/ChooseDirectory.vue";
import SelectStrategy from "./components/SelectStrategy.vue";
import ApplyLyrics from "./components/ApplyLyrics.vue";
import { ref } from 'vue'
import { appWindow } from '@tauri-apps/api/window'
import { invoke } from '@tauri-apps/api/tauri'
const step = ref(1)
const musicItems = ref(null)
const isCreateLRC = ref(true)
const isEmbed = ref(false)
const skipTracksHaveExistingLyrics = ref(true)
const isProd = ref(import.meta.env.PROD)
const toStep2 = (musicItems2) => {
console.log(musicItems2)
musicItems.value = musicItems2
step.value = 2
}
const toStep3 = (musicItems2, isCreateLRC2, isEmbed2, skipTracksHaveExistingLyrics2) => {
musicItems.value = musicItems2
isCreateLRC.value = isCreateLRC2
isEmbed.value = isEmbed2
skipTracksHaveExistingLyrics.value = skipTracksHaveExistingLyrics2
step.value = 3
}
const startOver = () => {
musicItems.value = null
isCreateLRC.value = true
isEmbed.value = false
skipTracksHaveExistingLyrics.value = true
step.value = 1
}
const openDevtools = () => {
invoke("open_devtools");
}
const minimizeWindow = () => {
appWindow.minimize()
}
const maximizeWindow = () => {
appWindow.toggleMaximize()
}
const closeWindow = () => {
appWindow.close()
}
</script>
<style>
</style>

View File

@@ -0,0 +1,108 @@
<template>
<div class="flex flex-col w-full h-full">
<div class="flex-grow flex flex-col justify-center items-center w-full p-6">
<div v-if="progress < 1.0" class="m-4 text-hoa-1200 text-sm font-bold uppercase">Applying lyrics...</div>
<div v-else class="m-4 text-hoa-1200 text-sm font-bold uppercase">Done! Happy singing!</div>
<div class="flex flex-col items-center justify-center mb-4 gap-4 text-gray-200 w-full">
<div class="w-full bg-hoa-300 h-1 mb-6 rounded">
<div class="bg-hoa-800 h-1" :style="{ width: `${Math.round(progress * 100)}%` }"></div>
</div>
<div class="text-hoa-800 w-full flex justify-start text-xs mb-4">
<div class="grid w-auto gap-3 grid-cols-2">
<div class="uppercase font-bold text-hoa-800">Total items</div>
<div class="font-bold text-right text-hoa-800">{{ totalItemsCount }}</div>
<div class="uppercase font-bold text-green-800">Successed items</div>
<div class="font-bold text-right text-green-800">{{ successedItemsCount }}</div>
<div class="uppercase font-bold text-red-800">Not found/failed items</div>
<div class="font-bold text-right text-red-800">{{ failedItemsCount }}</div>
</div>
</div>
<OverlayScrollbars class="rounded p-3 h-64 bg-brave-98 w-full font-mono overflow-auto flex flex-col-reverse text-sm"
:options="{
scrollbars: { theme: 'os-theme-light' }
}"
>
<div v-for="log in applyLog" :key="log.trackName" :class="{ 'text-green-800': log.status === 'Success', 'text-red-800': log.status === 'Failure' }">
<strong>{{ log.trackName }} - {{ log.artistName }}</strong>:
<span>{{ log.message }}</span>
</div>
</OverlayScrollbars>
</div>
</div>
<div class="p-6 w-full flex justify-center bg-brave-90">
<button type="button" @click="startOver"
class="px-6 py-2 bg-brave-primary rounded-full uppercase font-bold text-white transition"
:class="{ 'bg-opacity-30': progress < 1.0, 'hover:bg-brave-35 active:bg-brave-30': progress >= 1.0 }"
:disabled="progress < 1.0"
>
Start Over
</button>
</div>
</div>
</template>
<script setup>
import { ref, onMounted, defineProps, defineEmits } from 'vue'
import { invoke } from '@tauri-apps/api/tauri'
import { listen } from '@tauri-apps/api/event'
const props = defineProps({
musicItems: Object,
isCreateLRC: Boolean,
isEmbed: Boolean,
skipTracksHaveExistingLyrics: Boolean
})
const emit = defineEmits(['startOver'])
const progress = ref(0.0)
const processedItemsCount = ref(0)
const successedItemsCount = ref(0)
const failedItemsCount = ref(0)
const totalItemsCount = ref(0)
const applyLog = ref([])
const startOver = () => {
emit('startOver')
}
onMounted(async () => {
let musicItems
if (props.skipTracksHaveExistingLyrics) {
musicItems = props.musicItems.filter((item) => item.lyrics === null || item.lyrics.length === 0)
} else {
musicItems = props.musicItems
}
invoke("apply_lyrics", {
musicItems: musicItems,
isCreateLrc: props.isCreateLRC,
isEmbed: props.isEmbed,
skipTracksHaveExistingLyrics: props.skipTracksHaveExistingLyrics
}).then(() => {
console.log('done')
progress.value = 1.0
})
listen('apply-lyrics-progress', (event) => {
const payload = event.payload
console.log(payload)
progress.value = payload.progress
processedItemsCount.value = payload.processed_items_count
successedItemsCount.value = payload.successed_items_count
failedItemsCount.value = payload.failed_items_count
totalItemsCount.value = payload.total_items_count
applyLog.value.unshift({
status: payload.current_status,
message: payload.current_message,
trackName: payload.current_track.track_name,
artistName: payload.current_track.artist_name
})
})
})
</script>

View File

@@ -0,0 +1,127 @@
<template>
<div v-if="!directoryForScan" class="flex justify-center items-center w-full h-full p-4">
<button type="button" @click="chooseDirectory" class="p-3 w-48 h-48 bg-brave-primary rounded-full uppercase font-bold text-white hover:bg-brave-35 hover:scale-110 active:bg-brave-30 text-sm transition">
Choose directory
</button>
</div>
<div v-else class="w-full h-full flex flex-col">
<div class="p-2 bg-brave-primary flex rounded items-stretch m-6">
<div class="flex-grow text-sm font-bold px-2 py-2 text-white">{{ directoryForScan }}</div>
<button type="button" @click="chooseDirectory" class="bg-brave-30 hover:bg-brave-25 active:bg-brave-20 transition text-white rounded py-2 px-4 text-xs font-bold uppercase h-full">Change directory</button>
</div>
<div v-if="loading" class="p-6 text-hoa-1500 rounded flex items-center justify-center h-full">
<Loading class="animate-spin text-xl" />
</div>
<div v-else-if="musicItems && musicItems.length > 0" class="flex-grow flex flex-col items-center overflow-hidden w-full">
<div class="mt-3 text-brave-5 text-sm font-bold uppercase">Found <strong>{{ musicItems.length }}</strong> tracks</div>
<div class="flex-grow p-6 w-full">
<OverlayScrollbars class="text-hoa-200 h-full overflow-y-auto rounded-lg">
<table class="table-auto w-full">
<thead class="">
<tr class="bg-brave-90 text-brave-10 w-full">
<th class="p-3">Track</th>
<th class="p-3">Artist</th>
<th class="p-3">Album</th>
<th class="p-3">Duration</th>
<th class="p-3">Lyrics</th>
</tr>
</thead>
<tbody class="">
<tr v-for="musicItem in musicItems" :key="musicItem.file_path" class="p-3 bg-white border-2 border-brave-98 last:border-none text-brave-10 text-sm">
<td class="p-3">{{ musicItem.track_name }}</td>
<td class="p-3">{{ musicItem.artist_name }}</td>
<td class="p-3">{{ musicItem.album_name }}</td>
<td v-if="musicItem.duration" class="p-3 text-center">{{ humanizeDuration(Math.round(musicItem.duration)) }}</td>
<td v-else class="p-3"></td>
<td v-if="musicItem.lyrics" class="p-3 text-center"><div class="flex items-center justify-center"><CheckCircle class="text-green-700" /></div></td>
<td v-else class="p-3"></td>
</tr>
</tbody>
</table>
</OverlayScrollbars>
</div>
<div class="p-6 w-full flex justify-between bg-brave-90">
<div class="flex items-center">
<input id="skip-tracks" type="checkbox" v-model="skipTracksHaveExistingLyrics" class="w-4 h-4 text-hoa-600 bg-hoa-1100 accent-hoa-1100 rounded border-hoa-300">
<label for="skip-tracks" class="ml-2 text-sm font-medium text-hoa-1500">Skip tracks that already have lyrics</label>
</div>
<button type="button" @click="progressStep" class="px-6 py-2 bg-brave-primary rounded-full uppercase font-bold text-white hover:bg-brave-35 active:bg-brave-30 transition">
Confirm and download lyrics
</button>
</div>
</div>
<div v-else class="p-3 text-brave-10 flex items-center justify-center h-full">
Could not find any music files
</div>
</div>
</template>
<script setup>
import { open } from "@tauri-apps/api/dialog"
import { audioDir } from '@tauri-apps/api/path'
import { ref, watch, defineEmits } from 'vue'
import { invoke } from '@tauri-apps/api/tauri'
import { CheckCircle, Loading } from 'mdue'
import path from 'path'
const emit = defineEmits(['progressStep'])
const directoryForScan = ref(null)
const musicItems = ref(null)
const loading = ref(false)
const skipTracksHaveExistingLyrics = ref(true)
const progressStep = () => {
emit('progressStep', musicItems.value, true, false, skipTracksHaveExistingLyrics.value)
}
const humanizeDuration = (duration) => {
return new Date(duration * 1000).toISOString().substring(14, 19)
}
const chooseDirectory = async () => {
const dirPath = await audioDir();
const selected = await open({
defaultPath: dirPath,
directory: true,
recursive: true
})
if (selected) {
directoryForScan.value = selected
}
}
watch(directoryForScan, async (newDirectory) => {
loading.value = true
try {
const result = await invoke("get_music_files", { directory: newDirectory })
if (result && result.length > 0) {
musicItems.value = result.sort((item1, item2) => {
if (item1.track_name < item2.track_name) {
return -1
}
if ( item1.track_name > item2.track_name) {
return 1
}
return 0
})
} else {
musicItems.value = []
}
} catch (error) {
throw error
} finally {
loading.value = false
}
})
</script>

View File

@@ -0,0 +1,53 @@
<template>
<div class="flex flex-col justify-center items-center w-full h-full p-4">
<div class="m-4 text-hoa-1500 text-sm">Select Strategy</div>
<div class="flex mb-4 gap-4 text-gray-200">
<button @click="chooseCreateLRC" class="text-left flex-1 border-4 rounded p-3 transition" :class="{ 'border-hoa-1400 bg-hoa-800/70': isCreateLRC, 'border-transparent bg-hoa-800/30': !isCreateLRC }">
<div class="font-bold text-hoa-1400 mb-3">Create separate LRC files</div>
<div class="text-sm text-hoa-1300">LRC lyrics files will be created in the same location with the music files and have the same name.</div>
</button>
<button @click="chooseEmbed" class="text-left flex-1 border-4 rounded p-3 transition" :class="{ 'border-hoa-1400 bg-hoa-800/70': isEmbed, 'border-transparent bg-hoa-800/30': !isEmbed }">
<div class="font-bold text-hoa-1400 mb-3">Embed lyrics to music files</div>
<div class="text-sm text-hoa-1300">Lyrics will be embedded to music files through SYLT tag (mp3) or LYRICS tag (flac). Limited players support.</div>
</button>
</div>
<div class="">
<div class="flex items-center">
<input id="skip-tracks" type="checkbox" v-model="skipTracksHaveExistingLyrics" class="w-4 h-4 text-hoa-600 bg-hoa-1100 accent-hoa-1100 rounded border-hoa-300 focus:ring-hoa-500 focus:ring-2">
<label for="skip-tracks" class="ml-2 text-sm font-medium text-hoa-1500">Skip tracks that already have lyrics</label>
</div>
</div>
<div class="p-3">
<button type="button" @click="progressStep" class="px-6 py-2 bg-hoa-1100 rounded-full uppercase font-bold text-white hover:bg-hoa-1200 active:bg-hoa-1300 transition">
Confirm
</button>
</div>
</div>
</template>
<script setup>
import { ref, defineEmits } from 'vue'
const emit = defineEmits(['progressStep'])
const isCreateLRC = ref(true)
const isEmbed = ref(false)
const skipTracksHaveExistingLyrics = ref(true)
const progressStep = () => {
emit('progressStep', isCreateLRC.value, isEmbed.value, skipTracksHaveExistingLyrics.value)
}
const chooseCreateLRC = () => {
isCreateLRC.value = true
isEmbed.value = false
}
const chooseEmbed = () => {
isCreateLRC.value = false
isEmbed.value = true
}
</script>

18
src/main.js Normal file
View File

@@ -0,0 +1,18 @@
import { createApp } from "vue";
import "./style.css";
import "overlayscrollbars/css/OverlayScrollbars.css";
import App from "./App.vue";
import { OverlayScrollbarsComponent } from "overlayscrollbars-vue";
createApp(App)
.component("OverlayScrollbars", OverlayScrollbarsComponent)
.mount("#app")
document.addEventListener(
"contextmenu",
(event) => {
event.preventDefault();
return false;
},
{ capture: true }
)

29
src/style.css Normal file
View File

@@ -0,0 +1,29 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
@apply bg-brave-95;
}
.titlebar {
height: 30px;
background: #329ea3;
user-select: none;
display: flex;
justify-content: flex-end;
position: fixed;
top: 0;
left: 0;
right: 0;
}
.titlebar-button {
display: inline-flex;
justify-content: center;
align-items: center;
width: 30px;
height: 30px;
}
.titlebar-button:hover {
background: #5bbec3;
}

52
tailwind.config.cjs Normal file
View File

@@ -0,0 +1,52 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./src/**/*.{html,js,vue}',
],
theme: {
extend: {
colors: {
hoa: {
"0": "#ffdbe4",
"100": "#ffd9e2",
"200": "#ffd4df",
"300": "#ffcdda",
"400": "#ffc3d3",
"500": "#ffb7cb",
"600": "#fea7c1",
"700": "#fe96b7",
"800": "#fc84ad",
"900": "#fb73a4",
"1000": "#f8639d",
"1100": "#f35697",
"1200": "#eb4a91",
"1300": "#dc4089",
"1400": "#c5367d",
"1500": "#a82c6c"
},
brave: {
100: "#ffffff",
99: "#fffbff",
98: "#fff8f8",
95: "#ffecf0",
90: "#ffd9e2",
80: "#ffb1c8",
70: "#ff84af",
60: "#ff4896",
50: "#df247d",
40: "#b90063",
35: "#a30057",
30: "#8e004b",
25: "#79003f",
20: "#650033",
15: "#510028",
10: "#3e001d",
5: "#2b0012",
0: "#000000",
primary: "#b90063"
}
}
},
},
plugins: [],
}

32
vite.config.js Normal file
View File

@@ -0,0 +1,32 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
// prevent vite from obscuring rust errors
clearScreen: false,
// tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
},
// to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ["VITE_", "TAURI_"],
build: {
// Tauri supports es2021
target: ["es2021", "chrome100", "safari13"],
// don't minify for debug builds
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
// produce sourcemaps for debug builds
sourcemap: !!process.env.TAURI_DEBUG,
},
resolve: {
alias: {
path: "path-browserify"
}
}
});