Compare commits

..

No commits in common. "68e47894619a842820ea0537d3f2cf3d502c3be7" and "d8206b00c49cc9cb51bdc669804ab51e5ed09674" have entirely different histories.

7 changed files with 175 additions and 637 deletions

423
src-tauri/Cargo.lock generated
View file

@ -86,6 +86,26 @@ dependencies = [
"system-deps 6.1.1", "system-deps 6.1.1",
] ]
[[package]]
name = "audiotags"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f47bdf1acc4fa4113f8aa72bb3bfe62a61443c61d0d997b723ba61ce102c79b"
dependencies = [
"audiotags-dev-macro",
"id3",
"metaflac",
"mp4ameta",
"readme-rustdocifier",
"thiserror",
]
[[package]]
name = "audiotags-dev-macro"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b79298591161f312f06327df7963063ee07466be303dcc3084a44ec293cb36e"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -419,6 +439,30 @@ dependencies = [
"crossbeam-utils", "crossbeam-utils",
] ]
[[package]]
name = "crossbeam-deque"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
"scopeguard",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.16" version = "0.8.16"
@ -590,6 +634,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]] [[package]]
name = "embed-resource" name = "embed-resource"
version = "2.3.0" version = "2.3.0"
@ -600,7 +650,7 @@ dependencies = [
"rustc_version", "rustc_version",
"toml 0.7.8", "toml 0.7.8",
"vswhom", "vswhom",
"winreg 0.51.0", "winreg",
] ]
[[package]] [[package]]
@ -775,12 +825,6 @@ dependencies = [
"syn 2.0.37", "syn 2.0.37",
] ]
[[package]]
name = "futures-sink"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
[[package]] [[package]]
name = "futures-task" name = "futures-task"
version = "0.3.28" version = "0.3.28"
@ -1107,25 +1151,6 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "h2"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833"
dependencies = [
"bytes",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http",
"indexmap 1.9.3",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.3" version = "0.12.3"
@ -1204,72 +1229,12 @@ dependencies = [
"itoa 1.0.9", "itoa 1.0.9",
] ]
[[package]]
name = "http-body"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
dependencies = [
"bytes",
"http",
"pin-project-lite",
]
[[package]] [[package]]
name = "http-range" name = "http-range"
version = "0.1.5" version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573" checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]]
name = "httparse"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
[[package]]
name = "httpdate"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "hyper"
version = "0.14.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468"
dependencies = [
"bytes",
"futures-channel",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"httparse",
"httpdate",
"itoa 1.0.9",
"pin-project-lite",
"socket2 0.4.9",
"tokio",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "hyper-tls"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
dependencies = [
"bytes",
"hyper",
"native-tls",
"tokio",
"tokio-native-tls",
]
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.57" version = "0.1.57"
@ -1400,12 +1365,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "ipnet"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6"
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.8" version = "0.4.8"
@ -1538,8 +1497,10 @@ checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128"
name = "lissen" name = "lissen"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"anyhow",
"audiotags",
"id3", "id3",
"reqwest", "rayon",
"serde", "serde",
"serde_json", "serde_json",
"tauri", "tauri",
@ -1652,10 +1613,15 @@ dependencies = [
] ]
[[package]] [[package]]
name = "mime" name = "metaflac"
version = "0.3.17" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "e1470d3cc1bb0d692af5eb3afb594330b8ba09fd91c32c4e1c6322172a5ba750"
dependencies = [
"byteorder",
"hex",
"log",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
@ -1668,33 +1634,20 @@ dependencies = [
] ]
[[package]] [[package]]
name = "mio" name = "mp4ameta"
version = "0.8.8" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" checksum = "eb23d62e8eb5299a3f79657c70ea9269eac8f6239a76952689bcd06a74057e81"
dependencies = [ dependencies = [
"libc", "lazy_static",
"wasi 0.11.0+wasi-snapshot-preview1", "mp4ameta_proc",
"windows-sys 0.48.0",
] ]
[[package]] [[package]]
name = "native-tls" name = "mp4ameta_proc"
version = "0.2.11" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" checksum = "07dcca13d1740c0a665f77104803360da0bdb3323ecce2e93fa2c959a6d52806"
dependencies = [
"lazy_static",
"libc",
"log",
"openssl",
"openssl-probe",
"openssl-sys",
"schannel",
"security-framework",
"security-framework-sys",
"tempfile",
]
[[package]] [[package]]
name = "ndk" name = "ndk"
@ -1871,50 +1824,6 @@ dependencies = [
"windows-sys 0.42.0", "windows-sys 0.42.0",
] ]
[[package]]
name = "openssl"
version = "0.10.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c"
dependencies = [
"bitflags 2.4.0",
"cfg-if",
"foreign-types",
"libc",
"once_cell",
"openssl-macros",
"openssl-sys",
]
[[package]]
name = "openssl-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]]
name = "openssl-probe"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]] [[package]]
name = "overload" name = "overload"
version = "0.1.1" version = "0.1.1"
@ -2300,6 +2209,32 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
[[package]]
name = "rayon"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "readme-rustdocifier"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08ad765b21a08b1a8e5cdce052719188a23772bcbefb3c439f0baaf62c56ceac"
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.16" version = "0.2.16"
@ -2373,43 +2308,6 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
[[package]]
name = "reqwest"
version = "0.11.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1"
dependencies = [
"base64 0.21.4",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"hyper",
"hyper-tls",
"ipnet",
"js-sys",
"log",
"mime",
"native-tls",
"once_cell",
"percent-encoding",
"pin-project-lite",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",
"tokio-native-tls",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"winreg 0.50.0",
]
[[package]] [[package]]
name = "rfd" name = "rfd"
version = "0.10.0" version = "0.10.0"
@ -2489,15 +2387,6 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "schannel"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88"
dependencies = [
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "scoped-tls" name = "scoped-tls"
version = "1.0.1" version = "1.0.1"
@ -2510,29 +2399,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "security-framework"
version = "2.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de"
dependencies = [
"bitflags 1.3.2",
"core-foundation",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.22.0" version = "0.22.0"
@ -2613,18 +2479,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [
"form_urlencoded",
"itoa 1.0.9",
"ryu",
"serde",
]
[[package]] [[package]]
name = "serde_with" name = "serde_with"
version = "3.3.0" version = "3.3.0"
@ -2733,26 +2587,6 @@ version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "socket2"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "socket2"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e"
dependencies = [
"libc",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "soup2" name = "soup2"
version = "0.2.1" version = "0.2.1"
@ -3250,36 +3084,8 @@ checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
"libc",
"mio",
"num_cpus", "num_cpus",
"pin-project-lite", "pin-project-lite",
"socket2 0.5.4",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
dependencies = [
"native-tls",
"tokio",
]
[[package]]
name = "tokio-util"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
] ]
[[package]] [[package]]
@ -3325,12 +3131,6 @@ dependencies = [
"winnow", "winnow",
] ]
[[package]]
name = "tower-service"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.37" version = "0.1.37"
@ -3402,12 +3202,6 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "try-lock"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.17.0" version = "1.17.0"
@ -3474,12 +3268,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]] [[package]]
name = "version-compare" name = "version-compare"
version = "0.0.11" version = "0.0.11"
@ -3528,15 +3316,6 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "want"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
dependencies = [
"try-lock",
]
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.9.0+wasi-snapshot-preview1" version = "0.9.0+wasi-snapshot-preview1"
@ -4001,16 +3780,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "winreg"
version = "0.50.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
dependencies = [
"cfg-if",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "winreg" name = "winreg"
version = "0.51.0" version = "0.51.0"

View file

@ -1,24 +1,26 @@
[package] [package]
authors = ["you"]
description = "A Tauri App"
edition = "2021"
license = ""
name = "lissen" name = "lissen"
repository = ""
version = "0.0.0" version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies] [build-dependencies]
tauri-build = {version = "1.4", features = [] } tauri-build = { version = "1.4", features = [] }
[dependencies] [dependencies]
id3 = "1.8.0" tauri = { version = "1.4", features = [ "dialog-open", "shell-open"] }
reqwest = {version = "0.11.20", features = ["json"] } serde = { version = "1.0", features = ["derive"] }
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
tauri = {version = "1.4", features = ["dialog-open", "shell-open"] } id3 = "1.8.0"
rayon = "1.8.0"
walkdir = "2.4.0" walkdir = "2.4.0"
anyhow = "1.0.75"
audiotags = "0.4.1"
[features] [features]
# this feature is used for production builds or when `devPath` points to the filesystem # this feature is used for production builds or when `devPath` points to the filesystem

View file

@ -1,13 +1,13 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!! // Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use id3::{Tag, TagLike};
use serde::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::HashSet;
use tauri::Manager;
use id3::{Tag, TagLike};
use serde::Serialize;
use walkdir::WalkDir; use walkdir::WalkDir;
#[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, PartialEq, Eq, Hash)]
pub struct LocalAlbum { pub struct Album {
pub name: String, pub name: String,
pub artist: String, pub artist: String,
pub year: i32, pub year: i32,
@ -15,16 +15,15 @@ pub struct LocalAlbum {
} }
#[tauri::command] #[tauri::command]
async fn get_local_albums( async fn get_local_albums(dirpath: String) -> Result<Vec<Album>, String> {
dirpath: String,
app_handle: tauri::AppHandle,
) -> Result<Vec<LocalAlbum>, String> {
let mut result = HashSet::new(); let mut result = HashSet::new();
for entry in WalkDir::new(dirpath).into_iter().filter_map(|e| e.ok()) { for entry in WalkDir::new(dirpath) {
let entry = entry.map_err(|e| e.to_string())?;
println!("{}", entry.path().display());
if entry.file_type().is_file() { if entry.file_type().is_file() {
let path = entry.path(); let path = entry.path();
if let Ok(tag) = Tag::read_from_path(path) { if let Ok(tag) = Tag::read_from_path(path) {
let album = LocalAlbum { let album = Album {
name: tag.album().unwrap_or("").to_string(), name: tag.album().unwrap_or("").to_string(),
artist: tag.artist().unwrap_or("").to_string(), artist: tag.artist().unwrap_or("").to_string(),
year: tag.year().unwrap_or(0), year: tag.year().unwrap_or(0),
@ -34,124 +33,16 @@ async fn get_local_albums(
.map(|ext| ext == "flac" || ext == "wav") .map(|ext| ext == "flac" || ext == "wav")
.unwrap_or(false), .unwrap_or(false),
}; };
let json_local_album = serde_json::to_value(&album).unwrap(); result.insert(album);
let new = result.insert(album);
if new {
app_handle
.emit_all("new_local_album", json_local_album)
.unwrap();
}
} }
} }
} }
Ok(result.into_iter().collect()) Ok(result.into_iter().collect())
} }
#[derive(Debug, Serialize, PartialEq, Eq, Hash)]
pub struct ScrobbledAlbum {
pub name: String,
pub artist: String,
pub playcount: u64,
}
#[derive(Debug, Deserialize)]
pub enum Period {
Overall,
Week,
Month,
ThreeMonths,
SixMonths,
Year,
}
impl ToString for Period {
fn to_string(&self) -> String {
match self {
Period::Overall => "overall",
Period::Week => "7day",
Period::Month => "1month",
Period::ThreeMonths => "3month",
Period::SixMonths => "6month",
Period::Year => "12month",
}
.to_string()
}
}
#[tauri::command]
async fn get_top_scrobbled_albums(
user: String,
period: Period,
limit: u64,
api_key: Option<String>,
app_handle: tauri::AppHandle,
) -> Result<Vec<ScrobbledAlbum>, String> {
let api_key = api_key
.or_else(|| option_env!("LASTFM_API_KEY").map(|s| s.to_string()))
.ok_or("No API key supplied.")?;
let period = period.to_string();
let page_size = 50;
let mut final_result = Vec::new();
let mut page = 1;
while final_result.len() < limit as usize {
let url = format!(
"https://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user={user}&api_key={api_key}&period={period}&limit={page_size}&page={page}&format=json");
println!("Fetching {}", url);
let resp = reqwest::get(&url)
.await
.map_err(|e| e.to_string())?
.json::<serde_json::Value>()
.await
.map_err(|e| e.to_string())?;
let albums = resp["topalbums"]["album"]
.as_array()
.ok_or("no albums found")?;
let mut result = Vec::new();
for album in albums {
let name = album["name"].as_str().ok_or("no album name")?.to_string();
let artist = album["artist"]["name"]
.as_str()
.ok_or("no artist name")?
.to_string();
let playcount = album["playcount"]
.as_str()
.ok_or("no playcount")?
.parse()
.map_err(|_| "failed to parse playcount")?;
result.push(ScrobbledAlbum {
name,
artist,
playcount,
});
}
app_handle
.emit_all(
"new_scrobbled_albums",
serde_json::to_value(&result).unwrap(),
)
.unwrap();
final_result.extend(result);
page += 1;
}
Ok(final_result)
}
fn main() { fn main() {
// https://github.com/tauri-apps/tauri/issues/5143#issuecomment-1311815517
std::env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
tauri::Builder::default() tauri::Builder::default()
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![get_local_albums])
get_top_scrobbled_albums,
get_local_albums
])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }

View file

@ -1,172 +1,39 @@
<script lang="ts"> <script lang="ts">
import { invoke } from "@tauri-apps/api/tauri"; import Greet from './lib/Greet.svelte'
import { open } from "@tauri-apps/api/dialog";
import { listen } from "@tauri-apps/api/event";
import { onMount } from "svelte";
import { period, username } from "./stores";
interface ScrobbledAlbum {
name: string;
artist: string;
playcount: number;
}
let scrobbledAlbums: ScrobbledAlbum[] = [];
let loadingScrobbledAlbums = false;
interface LocalAlbum {
name: string;
artist: string;
year: number;
lossless: boolean;
}
let localAlbums: LocalAlbum[] = [];
let loadingLocalAlbums = false;
onMount(() => {
listen("new_local_album", (event) => {
const album = event.payload as LocalAlbum;
localAlbums = [...localAlbums, album];
});
listen("new_scrobbled_albums", (event) => {
const newAlbums = event.payload as ScrobbledAlbum[];
scrobbledAlbums = [...scrobbledAlbums, ...newAlbums];
});
});
async function loadScrobbles() {
if (loadingScrobbledAlbums) {
return;
}
scrobbledAlbums = [];
loadingScrobbledAlbums = true;
try {
await invoke("get_top_scrobbled_albums", {
user: $username,
period: $period,
limit: 200,
});
} catch (e) {
handleError(e);
}
loadingScrobbledAlbums = false;
}
async function loadLocal() {
const selected = await open({
directory: true,
});
if (typeof selected === "string" && selected.length > 0) {
localAlbums = [];
loadingLocalAlbums = true;
try {
await invoke("get_local_albums", {
dirpath: selected,
});
} catch (e) {
handleError(e);
}
loadingLocalAlbums = false;
}
}
function handleError(e: unknown) {
console.error(e);
alert(e);
}
</script> </script>
<main> <main class="container">
<div class="main"> <h1>Welcome to Tauri!</h1>
<div class="scrobbles">
<div class="input">
<label>
Username:
<input type="text" bind:value={$username} />
</label>
<label>
Period:
<select bind:value={$period}>
<option value="Week">7 days</option>
<option value="Month">1 month</option>
<option value="ThreeMonths">3 months</option>
<option value="SixMonths">6 months</option>
<option value="Year">Year</option>
<option value="Overall">Overall</option>
</select>
</label>
<button on:click={loadScrobbles}>Load scrobbles</button> <div class="row">
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo vite" alt="Vite Logo" />
</a>
<a href="https://tauri.app" target="_blank">
<img src="/tauri.svg" class="logo tauri" alt="Tauri Logo" />
</a>
<a href="https://svelte.dev" target="_blank">
<img src="/svelte.svg" class="logo svelte" alt="Svelte Logo" />
</a>
</div> </div>
<div class="display"> <p>
<div class="label">Scrobbled albums: {scrobbledAlbums.length}</div> Click on the Tauri, Vite, and Svelte logos to learn more.
<div class="albums"> </p>
{#each scrobbledAlbums as album}
<div class="album"> <div class="row">
<div class="name">{album.name}</div> <Greet />
<div class="artist">{album.artist}</div>
<div class="playcount">Played: {album.playcount}</div>
</div>
{/each}
</div>
</div>
</div>
<div class="local">
<div class="input">
<button on:click={loadLocal}>Load local albums</button>
</div>
<div class="albums">
{#each localAlbums as album}
<div class="album">
<div class="name">{album.name}</div>
<div class="artist">{album.artist}</div>
<div class="year">{album.year}</div>
<div class="lossless">{album.lossless}</div>
</div>
{/each}
</div>
</div>
</div> </div>
</main> </main>
<style> <style>
main { .logo.vite:hover {
display: flex; filter: drop-shadow(0 0 2em #747bff);
flex-direction: column;
align-items: center;
}
.main {
display: flex;
width: 100vw;
}
.main > * {
flex-basis: 50%;
}
.albums {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin: 1rem;
}
.album {
display: flex;
flex-direction: column;
border: 1px solid white;
border-radius: 2px;
padding: 0.5rem;
}
.album {
& .name {
font-weight: bold;
} }
& .artist { .logo.svelte:hover {
font-size: 0.8em; filter: drop-shadow(0 0 2em #ff3e00);
} }
}
</style> </style>

27
src/lib/Greet.svelte Normal file
View file

@ -0,0 +1,27 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/tauri";
import { open } from "@tauri-apps/api/dialog";
let name = "";
let greetMsg = "";
async function greet() {
const selected = await open({
directory: true,
});
if (typeof selected === "string" && selected.length > 0) {
const res = await invoke("get_local_albums", {
dirpath: selected,
});
console.log({ res });
}
greetMsg = selected.toString();
}
</script>
<div>
<form class="row" on:submit|preventDefault={greet}>
<button type="submit">Load</button>
</form>
<p>{greetMsg}</p>
</div>

View file

@ -1,17 +0,0 @@
import { writable } from "svelte/store";
export const username = writable(localStorage.getItem("username"));
username.subscribe((value) => (localStorage.username = value));
export type Period =
| "Overall"
| "Week"
| "Month"
| "ThreeMonths"
| "SixMonths"
| "Year";
export const period = writable<Period>(
(localStorage.getItem("period") as Period) || "Overall"
);
period.subscribe((value) => (localStorage.period = value));

View file

@ -54,7 +54,6 @@ h1 {
} }
input, input,
select,
button { button {
border-radius: 8px; border-radius: 8px;
border: 1px solid transparent; border: 1px solid transparent;