Compare commits

..

46 Commits
1.5.4 ... main

Author SHA1 Message Date
talwat
315fa105bf fix: don't start lowfi's UI unless in terminal 2025-05-01 09:46:17 +02:00
talwat
7cdd2e7694 feat: add star indicator for bookmarking 2025-04-23 14:14:49 +02:00
talwat
a89854e46f chore: remove test.txt 2025-04-23 14:00:54 +02:00
Tal
f1c6cbf026
docs: create ENVIRONMENT_VARS.md 2025-04-22 22:01:21 +02:00
talwat
d24c6b1a74 feat: implement basic bookmarking, still wip 2025-04-22 11:48:50 +02:00
talwat
a83a052ae9 docs: update disclaimer 2025-03-17 19:04:20 +01:00
talwat
a9cd30550c chore: bump version in preparation for 1.6.0 2025-03-17 18:34:11 +01:00
talwat
29dab7a77a docs: update flags list 2025-03-17 18:30:15 +01:00
talwat
fe70800502 docs: add fedora install instructions 2025-03-17 16:57:01 +01:00
talwat
d05f36a0bb chore: minor changes to internal docs 2025-03-17 16:54:16 +01:00
talwat
5db5146b8e feat: add option for fixed mpris name 2025-03-17 16:39:19 +01:00
talwat
34577efe8f feat: add buffer size option 2025-03-17 16:32:06 +01:00
talwat
968c1ee670 chore: formatting fix 2025-03-12 14:28:29 +01:00
talwat
bbdcfdd6f2 chore: bump version 2025-03-12 14:28:05 +01:00
talwat
8e843c12a2 docs: fix readme formatting 2025-03-12 14:23:26 +01:00
talwat
adcb20f2d0 fix: reform errors for track fetching 2025-03-12 14:21:37 +01:00
talwat
27fc505830 feat(internal): add extra flexibility to windows 2025-03-12 14:21:37 +01:00
Dario Griffo
66ccc44099
docs: add debian unofficial repository (#65)
* Add debian unofficial

* Update README.md
2025-03-12 07:10:14 +01:00
talwat
ca746c0902 chore: format & bump version 2025-03-03 15:06:27 +01:00
talwat
768f976e89 fix: allow for empty headers 2025-03-02 16:18:35 +01:00
talwat
84f386e0eb feat: add experimental local file loading in track lists 2025-02-28 19:07:22 +01:00
danielwerg
b68ce27d19
docs: fix typos and spelling (#62) 2025-02-27 08:14:51 +02:00
talwat
ed4b79d2bf chore: redo help menu descriptions 2025-02-26 14:45:02 +01:00
talwat
a4dd55fb28 fix: incorrect variable name on linux 2025-02-22 13:08:22 +01:00
talwat
3db4f9d402 chore: redo versioning 2025-02-22 10:49:22 +01:00
talwat
2a36bc72f3 fix: import necessary functions & types in silent_get_output_stream() 2025-02-21 22:06:56 +01:00
talwat
ce8f8d2845 fix: drop stream before aborting ui to prevent flicker 2025-02-21 21:50:20 +01:00
talwat
f0123fd2bc chore: add actual reason for sendableoutputstream allowing non send fields 2025-02-21 21:46:41 +01:00
talwat
ece88de1ae fix: tackle lots of clippy lints, along with removing outputstream from player struct 2025-02-21 21:44:32 +01:00
talwat
a720e9d2cf docs: mention space to pause 2025-02-20 10:29:37 +02:00
talwat
503b4fe9db docs(internal): add internal documentation for ui::flash_audio() 2025-02-19 23:48:31 +02:00
danielwerg
67a4c4f0ea
fix: show volume bar (mpris) (#59) 2025-02-19 23:43:14 +02:00
talwat
2b20bf7709 chore: specify album in MPRIS metadata, still untested 2025-02-18 22:09:16 +02:00
danielwerg
945b420cd8
chore: update chillhop track list (#56) 2025-02-18 21:50:07 +02:00
talwat
1e3c66679c fix: bug where text after ! in custom names wouldn't show up 2025-02-18 21:48:30 +02:00
talwat
840b1663e7 docs: tweak control documentation 2025-02-18 21:25:30 +02:00
danielwerg
7502d1cd17
docs: update controls (#58) 2025-02-18 20:20:00 +01:00
Beune
1480b62be9
feat: add mpv and vim-like keybindings (#57) 2025-02-17 20:49:06 +01:00
Tal
923ac05cf8 add functionality for custom track names 2025-02-15 12:51:53 +01:00
Tal
6a6823d078 feat: readd padding to borderless mode 2025-02-11 19:20:44 +01:00
Tal
1e491bb36f fix: make wiser use of the cfg macro 2025-02-09 15:58:08 +01:00
Tal
b87a525c74 feat: introduce -n for no borders 2025-02-09 15:38:33 +01:00
talwat
22a0851d40 chore: bump version 2025-01-14 11:13:31 +01:00
talwat
3db0623a72 fix: fix potential dangling pointer 2025-01-14 11:10:58 +01:00
Tal
22a2e7f986 chore: bump version 2025-01-07 22:34:34 +01:00
Tal
02a8e4f815 chore: update cargo lock 2025-01-07 22:33:49 +01:00
18 changed files with 1876 additions and 410 deletions

258
Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 4
[[package]] [[package]]
name = "Inflector" name = "Inflector"
@ -134,9 +134,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]] [[package]]
name = "async-broadcast" name = "async-broadcast"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20cd0e2e25ea8e5f7e9df04578dc6cf5c83577fd09b1a46aaf5c85e1c33f2a7e" checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"
dependencies = [ dependencies = [
"event-listener", "event-listener",
"event-listener-strategy", "event-listener-strategy",
@ -266,9 +266,9 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.83" version = "0.1.85"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -368,9 +368,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.20.0" version = "1.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a" checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -386,9 +386,9 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.2" version = "1.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" checksum = "a012a0df96dd6d06ba9a1b29d6402d1a5d77c6befd2566afdc26e10603dc93d7"
dependencies = [ dependencies = [
"jobserver", "jobserver",
"libc", "libc",
@ -435,9 +435,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.21" version = "4.5.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" checksum = "9560b07a799281c7e0958b9296854d6fafd4c5f31444a7e5bb1ad6dde5ccf1bd"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@ -445,9 +445,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.21" version = "4.5.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" checksum = "874e0dd3eb68bf99058751ac9712f622e61e6f393a94f7128fa26e3f02f5c7cd"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -457,9 +457,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.5.18" version = "4.5.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@ -469,9 +469,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.7.3" version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]] [[package]]
name = "colorchoice" name = "colorchoice"
@ -568,9 +568,9 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.20" version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]] [[package]]
name = "crossterm" name = "crossterm"
@ -766,7 +766,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -802,9 +802,9 @@ dependencies = [
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "2.2.0" version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]] [[package]]
name = "fnv" name = "fnv"
@ -973,7 +973,7 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
dependencies = [ dependencies = [
"unicode-width 0.1.14", "unicode-width",
] ]
[[package]] [[package]]
@ -995,9 +995,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]] [[package]]
name = "glob" name = "glob"
version = "0.3.1" version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
[[package]] [[package]]
name = "h2" name = "h2"
@ -1058,9 +1058,9 @@ dependencies = [
[[package]] [[package]]
name = "http" name = "http"
version = "1.1.0" 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 = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@ -1098,9 +1098,9 @@ checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946"
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "1.5.1" version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" checksum = "256fb8d4bd6413123cc9d91832d78325c48ff41677595be797d90f42969beae0"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@ -1118,9 +1118,9 @@ dependencies = [
[[package]] [[package]]
name = "hyper-rustls" name = "hyper-rustls"
version = "0.27.3" version = "0.27.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"http", "http",
@ -1383,9 +1383,9 @@ dependencies = [
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.74" version = "0.3.76"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@ -1399,9 +1399,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.167" version = "0.2.169"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
[[package]] [[package]]
name = "libloading" name = "libloading"
@ -1410,7 +1410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-targets 0.48.5", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -1453,7 +1453,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]] [[package]]
name = "lowfi" name = "lowfi"
version = "1.5.3" version = "1.6.0"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"arc-swap", "arc-swap",
@ -1472,7 +1472,6 @@ dependencies = [
"scraper", "scraper",
"tokio", "tokio",
"unicode-segmentation", "unicode-segmentation",
"unicode-width 0.2.0",
"url", "url",
] ]
@ -1534,9 +1533,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.8.0" version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394"
dependencies = [ dependencies = [
"adler2", "adler2",
] ]
@ -1684,9 +1683,9 @@ dependencies = [
[[package]] [[package]]
name = "object" name = "object"
version = "0.36.5" version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -1817,22 +1816,22 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]] [[package]]
name = "phf" name = "phf"
version = "0.11.2" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
dependencies = [ dependencies = [
"phf_macros", "phf_macros",
"phf_shared 0.11.2", "phf_shared 0.11.3",
] ]
[[package]] [[package]]
name = "phf_codegen" name = "phf_codegen"
version = "0.11.2" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a"
dependencies = [ dependencies = [
"phf_generator 0.11.2", "phf_generator 0.11.3",
"phf_shared 0.11.2", "phf_shared 0.11.3",
] ]
[[package]] [[package]]
@ -1847,22 +1846,22 @@ dependencies = [
[[package]] [[package]]
name = "phf_generator" name = "phf_generator"
version = "0.11.2" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
dependencies = [ dependencies = [
"phf_shared 0.11.2", "phf_shared 0.11.3",
"rand", "rand",
] ]
[[package]] [[package]]
name = "phf_macros" name = "phf_macros"
version = "0.11.2" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216"
dependencies = [ dependencies = [
"phf_generator 0.11.2", "phf_generator 0.11.3",
"phf_shared 0.11.2", "phf_shared 0.11.3",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
@ -1874,23 +1873,23 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
dependencies = [ dependencies = [
"siphasher", "siphasher 0.3.11",
] ]
[[package]] [[package]]
name = "phf_shared" name = "phf_shared"
version = "0.11.2" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
dependencies = [ dependencies = [
"siphasher", "siphasher 1.0.1",
] ]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.15" version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
[[package]] [[package]]
name = "pin-utils" name = "pin-utils"
@ -1965,9 +1964,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.37" version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -2004,9 +2003,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.5.7" version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
] ]
@ -2053,9 +2052,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.12.9" version = "0.12.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" checksum = "43e734407157c3c2034e0258f5e4473ddb361b1e85f95a66690d67264d7cd1da"
dependencies = [ dependencies = [
"base64", "base64",
"bytes", "bytes",
@ -2086,6 +2085,7 @@ dependencies = [
"system-configuration", "system-configuration",
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tower",
"tower-service", "tower-service",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
@ -2133,22 +2133,22 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.41" version = "0.38.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.23.19" version = "0.23.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"rustls-pki-types", "rustls-pki-types",
@ -2168,9 +2168,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-pki-types" name = "rustls-pki-types"
version = "1.10.0" version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37"
[[package]] [[package]]
name = "rustls-webpki" name = "rustls-webpki"
@ -2244,9 +2244,9 @@ dependencies = [
[[package]] [[package]]
name = "security-framework-sys" name = "security-framework-sys"
version = "2.12.1" version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32"
dependencies = [ dependencies = [
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@ -2273,18 +2273,18 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.215" version = "1.0.217"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.215" version = "1.0.217"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2293,9 +2293,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.133" version = "1.0.135"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr", "memchr",
@ -2388,6 +2388,12 @@ version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "siphasher"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.9" version = "0.4.9"
@ -2520,9 +2526,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.90" version = "2.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2572,15 +2578,16 @@ dependencies = [
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.14.0" version = "3.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"fastrand", "fastrand",
"getrandom",
"once_cell", "once_cell",
"rustix", "rustix",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -2626,9 +2633,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.41.1" version = "1.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
@ -2663,20 +2670,19 @@ dependencies = [
[[package]] [[package]]
name = "tokio-rustls" name = "tokio-rustls"
version = "0.26.0" version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37"
dependencies = [ dependencies = [
"rustls", "rustls",
"rustls-pki-types",
"tokio", "tokio",
] ]
[[package]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.12" version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-core", "futures-core",
@ -2702,6 +2708,27 @@ dependencies = [
"winnow", "winnow",
] ]
[[package]]
name = "tower"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
dependencies = [
"futures-core",
"futures-util",
"pin-project-lite",
"sync_wrapper",
"tokio",
"tower-layer",
"tower-service",
]
[[package]]
name = "tower-layer"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
[[package]] [[package]]
name = "tower-service" name = "tower-service"
version = "0.3.3" version = "0.3.3"
@ -2791,12 +2818,6 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]] [[package]]
name = "untrusted" name = "untrusted"
version = "0.9.0" version = "0.9.0"
@ -2877,9 +2898,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.97" version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
@ -2888,13 +2909,12 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.97" version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
"once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
@ -2903,9 +2923,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.47" version = "0.4.49"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dfaf8f50e5f293737ee323940c7d8b08a66a95a419223d9f41610ca08b0833d" checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@ -2916,9 +2936,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.97" version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -2926,9 +2946,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.97" version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2939,15 +2959,15 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.97" version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.74" version = "0.3.76"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -2975,7 +2995,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -3259,9 +3279,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.6.20" version = "0.6.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" checksum = "39281189af81c07ec09db316b302a3e67bf9bd7cbf6c820b50e35fee9c2fa980"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "lowfi" name = "lowfi"
version = "1.5.4" version = "1.6.0"
edition = "2021" edition = "2021"
description = "An extremely simple lofi player." description = "An extremely simple lofi player."
license = "MIT" license = "MIT"
@ -50,5 +50,4 @@ Inflector = "0.11.4"
lazy_static = "1.5.0" lazy_static = "1.5.0"
libc = "0.2.167" libc = "0.2.167"
url = "2.5.4" url = "2.5.4"
unicode-width = "0.2.0"
unicode-segmentation = "1.12.0" unicode-segmentation = "1.12.0"

6
ENVIRONMENT_VARS.md Normal file
View File

@ -0,0 +1,6 @@
# Environment Variables
Lowfi has some more specific options, usually as a result of minor feature requests, which are only documented here.
If you have some behaviour you'd like to change, which is quite specific, then see if one of these options suits you.
* `LOWFI_FIXED_MPRIS_NAME` - Limits the number of lowfi instances to one, but ensures the player name is always `lowfi`.

View File

@ -7,20 +7,19 @@ It'll do this as simply as it can: no albums, no ads, just lofi.
## Disclaimer ## Disclaimer
**All** of the audio files played in lowfi are from [Lofi Girl's](https://lofigirl.com/) website, **All** of the audio files embedded into in lowfi by default are from [Lofi Girl's](https://lofigirl.com/) website,
under their [licensing guidelines](https://form.lofigirl.com/CommercialLicense). under their [licensing guidelines](https://form.lofigirl.com/CommercialLicense).
If god forbid you're planning to use this in a commercial setting, please If, god forbid, you're planning to use lowfi in a commercial setting, please
follow their rules. follow their rules.
## Why? ## Why?
I really hate modern music platforms, and I wanted a small, "suckless" I really hate modern music platforms, and I wanted a small, "suckless"
app that would literally just play lofi without video so I could use it app that would just play random lofi without video.
whenever.
I also wanted it to be fairly resiliant to inconsistent networks, It was also designed to be fairly resilient to inconsistent networks,
so it buffers 5 whole songs at a time instead of parts of the same song. and as such it buffers 5 whole songs at a time instead of parts of the same song.
Although, lowfi is yet to be properly tested in difficult conditions, Although, lowfi is yet to be properly tested in difficult conditions,
so don't rely on it too much until I do that. See [Scraping](#scraping) if so don't rely on it too much until I do that. See [Scraping](#scraping) if
@ -44,7 +43,7 @@ On Linux, you'll also need openssl & alsa, as well as their headers.
- `alsa-lib` on Arch, `libasound2-dev` on Ubuntu. - `alsa-lib` on Arch, `libasound2-dev` on Ubuntu.
- `openssl` on Arch, `libssl-dev` on Ubuntu. - `openssl` on Arch, `libssl-dev` on Ubuntu.
Make sure to also install `pulseaudio-alsa` if you're using pulseaudio. Make sure to also install `pulseaudio-alsa` if you're using PulseAudio.
### Cargo ### Cargo
@ -66,8 +65,6 @@ precompiled binaries from the [latest release](https://github.com/talwat/lowfi/r
### AUR ### AUR
If you're on Arch, you can also use the AUR:
```sh ```sh
yay -S lowfi yay -S lowfi
``` ```
@ -78,6 +75,27 @@ yay -S lowfi
zypper install lowfi zypper install lowfi
``` ```
### Debian
> [!NOTE]
> This uses an unofficial Debian repository maintained by [Dario Griffo](https://github.com/dariogriffo).
```sh
curl -sS https://debian.griffo.io/3B9335DF576D3D58059C6AA50B56A1A69762E9FF.asc | gpg --dearmor --yes -o /etc/apt/trusted.gpg.d/debian.griffo.io.gpg
echo "deb https://debian.griffo.io//apt $(lsb_release -sc 2>/dev/null) main" | sudo tee /etc/apt/sources.list.d/debian.griffo.io.list
sudo apt install -y lowfi
```
### Fedora (COPR)
> [!NOTE]
> This uses an unofficial COPR repository by [FurqanHun](https://github.com/FurqanHun).
```sh
sudo dnf copr enable furqanhun/lowfi
sudo dnf install lowfi
```
### Manual ### Manual
This is good for debugging, especially in issues. This is good for debugging, especially in issues.
@ -102,17 +120,39 @@ Yeah, that's it.
### Controls ### Controls
| Key | Function | | Key | Function |
|-------|----------------| | ------------------ | --------------- |
| `s` | Skip song | | `s`, `n`, `l` | Skip Song |
| `p` | Play/Pause | | `p`, Space | Play/Pause |
| `+/-` | Volume Up/Down | | `+`, `=`, `k`, `↑` | Volume Up 10% |
| `q` | Quit | | `→` | Volume Up 1% |
| `-`, `_`, `j`, `↓` | Volume Down 10% |
| `←` | Volume Down 1% |
| `q`, CTRL+C | Quit |
> [!NOTE]
> Besides its regular controls, lowfi offers compatibility with Media Keys
> and [MPRIS](https://wiki.archlinux.org/title/MPRIS) (with tools like `playerctl`).
>
> MPRIS is currently optional feature in cargo (enabled with `--features mpris`)
> due to it being only for Linux, as well as the fact that the main point of
> lowfi is it's unique & minimal interface.
### Extra Flags ### Extra Flags
If you have something you'd like to tweak about lowfi, you can run `lowfi help` If you have something you'd like to tweak about lowfi, you use additional flags which
to view the available options. slightly tweak the UI or behaviour of the menu. The flags can be viewed with `lowfi help`.
| Flag | Function |
| ----------------------------------- | ---------------------------------------------- |
| `-a`, `--alternate` | Use an alternate terminal screen |
| `-m`, `--minimalist` | Hide the bottom control bar |
| `-b`, `--borderless` | Exclude borders in UI |
| `-p`, `--paused` | Start lowfi paused |
| `-d`, `--debug` | Include ALSA & other logs |
| `-w`, `--width <WIDTH>` | Width of the player, from 0 to 32 [default: 3] |
| `-t`, `--track-list <TRACK_LIST>` | Use a [custom track list](#custom-track-lists) |
| `-s`, `--buffer-size <BUFFER_SIZE>` | Internal song buffer size [default: 5] |
### Scraping ### Scraping
@ -145,19 +185,21 @@ or it could also be the name of a file (without the `.txt` extension) in the dat
directory, so on Linux it's `~/.local/share/lowfi`. directory, so on Linux it's `~/.local/share/lowfi`.
For example, `lowfi --tracks minipop` would load `~/.local/share/lowfi/minipop.txt`. For example, `lowfi --tracks minipop` would load `~/.local/share/lowfi/minipop.txt`.
Whereas if you did `lowfi --tracks /home/user/Music/minipop.txt` it would load from that Whereas if you did `lowfi --tracks ~/Music/minipop.txt` it would load from that
specified directory. specified directory.
#### The Format #### The Format
In Lists, the first line should be the base URL, followed by the rest of the tracks. In lists, the first line should be the base URL, followed by the rest of the tracks.
This is also known as the "header", because it comes first.
Each track will be first appended to the base URL, and then the result use to download Each track will be first appended to the base URL, and then the result use to download
the track. All tracks should end in `.mp3` and as such must be in the MP3 format. the track. All tracks must be in the MP3 format, as lowfi doesn't support any others currently.
lowfi won't put a `/` between the base & track for added flexibility, so for most cases you Additionally, lowfi _won't_ put a `/` between the base & track for added flexibility,
should have a trailing `/` in your base url. The exception to this is if the track name begins so for most cases you should have a trailing `/` in your base url.
with something like `https://`, where in that case the base will not be prepended to it. The exception to this is if the track name begins with something like `https://`,
where in that case the base will not be prepended to it.
For example, in this list: For example, in this list:
@ -173,3 +215,14 @@ lowfi would download these three URLs:
- `https://lofigirl.com/wp-content/uploads/2023/06/Foudroie-Finding-The-Edge-V2.mp3` - `https://lofigirl.com/wp-content/uploads/2023/06/Foudroie-Finding-The-Edge-V2.mp3`
- `https://file-examples.com/storage/fea570b16e6703ef79e65b4/2017/11/file_example_MP3_5MG.mp3` - `https://file-examples.com/storage/fea570b16e6703ef79e65b4/2017/11/file_example_MP3_5MG.mp3`
- `https://lofigirl.com/wp-content/uploads/2023/04/2-In-Front-Of-Me.mp3` - `https://lofigirl.com/wp-content/uploads/2023/04/2-In-Front-Of-Me.mp3`
Additionally, you may also specify a custom display name for the track which is indicated by a `!`.
For example, if you had an entry like this:
```txt
2023/04/2-In-Front-Of-Me.mp3!custom name
```
Then lowfi would download from the first section, and display the second as the track name.
Further examples can be found in the [data](https://github.com/talwat/lowfi/tree/main/data) folder.

1140
data/chillhop.txt Normal file

File diff suppressed because it is too large Load Diff

2
data/file.txt Normal file
View File

@ -0,0 +1,2 @@
file:///home/user/Music/
Anomaly.mp3

View File

@ -1,45 +1,13 @@
//! An extremely simple lofi player. //! An extremely simple lofi player.
#![warn(clippy::all, clippy::restriction, clippy::pedantic, clippy::nursery)] #![warn(clippy::all, clippy::pedantic, clippy::nursery)]
#![allow(
clippy::single_call_fn, use std::path::PathBuf;
clippy::struct_excessive_bools,
clippy::implicit_return,
clippy::question_mark_used,
clippy::shadow_reuse,
clippy::indexing_slicing,
clippy::arithmetic_side_effects,
clippy::std_instead_of_core,
clippy::print_stdout,
clippy::float_arithmetic,
clippy::integer_division_remainder_used,
clippy::used_underscore_binding,
clippy::print_stderr,
clippy::semicolon_outside_block,
clippy::non_send_fields_in_send_ty,
clippy::non_ascii_literal,
clippy::let_underscore_untyped,
clippy::let_underscore_must_use,
clippy::shadow_unrelated,
clippy::std_instead_of_alloc,
clippy::partial_pub_fields,
clippy::unseparated_literal_suffix,
clippy::self_named_module_files,
// TODO: Disallow these lints later.
clippy::unwrap_used,
clippy::pattern_type_mismatch,
clippy::tuple_array_conversions,
clippy::as_conversions,
clippy::cast_possible_truncation,
clippy::cast_precision_loss,
clippy::wildcard_enum_match_arm,
clippy::integer_division,
clippy::cast_sign_loss,
clippy::cast_lossless,
)]
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use eyre::OptionExt;
mod messages;
mod play; mod play;
mod player; mod player;
mod tracks; mod tracks;
@ -48,32 +16,44 @@ mod tracks;
mod scrape; mod scrape;
/// An extremely simple lofi player. /// An extremely simple lofi player.
#[derive(Parser)] #[derive(Parser, Clone)]
#[command(about, version)] #[command(about, version)]
#[allow(
clippy::struct_excessive_bools,
reason = "señor clippy, i assure you this is not a state machine"
)]
struct Args { struct Args {
/// Whether to use an alternate terminal screen. /// Use an alternate terminal screen.
#[clap(long, short)] #[clap(long, short)]
alternate: bool, alternate: bool,
/// Whether to hide the bottom control bar. /// Hide the bottom control bar.
#[clap(long, short)] #[clap(long, short)]
minimalist: bool, minimalist: bool,
/// Whether to start lowfi paused. /// Exclude borders in UI.
#[clap(long, short)]
borderless: bool,
/// Start lowfi paused.
#[clap(long, short)] #[clap(long, short)]
paused: bool, paused: bool,
/// Whether to include ALSA & other logs. /// Include ALSA & other logs.
#[clap(long, short)] #[clap(long, short)]
debug: bool, debug: bool,
/// The width of the player, from 0 to 32. /// Width of the player, from 0 to 32.
#[clap(long, short, default_value_t = 3)] #[clap(long, short, default_value_t = 3)]
width: usize, width: usize,
/// This is either a path, or a name of a file in the data directory (eg. ~/.local/share/lowfi). /// Use a custom track list
#[clap(long, short, alias = "list", short_alias = 'l')] #[clap(long, short, alias = "list", short_alias = 'l')]
tracks: Option<String>, track_list: Option<String>,
/// Internal song buffer size.
#[clap(long, short = 's', alias = "buffer", default_value_t = 5)]
buffer_size: usize,
/// The command that was ran. /// The command that was ran.
/// This is [None] if no command was specified. /// This is [None] if no command was specified.
@ -82,7 +62,7 @@ struct Args {
} }
/// Defines all of the extra commands lowfi can run. /// Defines all of the extra commands lowfi can run.
#[derive(Subcommand)] #[derive(Subcommand, Clone)]
enum Commands { enum Commands {
/// Scrapes the lofi girl website file server for files. /// Scrapes the lofi girl website file server for files.
Scrape { Scrape {
@ -96,8 +76,20 @@ enum Commands {
}, },
} }
/// Gets lowfi's data directory.
pub fn data_dir() -> eyre::Result<PathBuf> {
let dir = dirs::data_dir()
.ok_or_eyre("data directory not found, are you *really* running this on wasm?")?
.join("lowfi");
Ok(dir)
}
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
#[cfg(target_os = "android")]
compile_error!("Android Audio API not supported due to threading shenanigans");
let cli = Args::parse(); let cli = Args::parse();
if let Some(command) = cli.command { if let Some(command) = cli.command {

37
src/messages.rs Normal file
View File

@ -0,0 +1,37 @@
/// Handles communication between the frontend & audio player.
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum Messages {
/// Notifies the audio server that it should update the track.
Next,
/// Special in that this isn't sent in a "client to server" sort of way,
/// but rather is sent by a child of the server when a song has not only
/// been requested but also downloaded aswell.
NewSong,
/// This signal is only sent if a track timed out. In that case,
/// lowfi will try again and again to retrieve the track.
TryAgain,
/// Similar to Next, but specific to the first track.
Init,
/// Unpause the [Sink].
#[allow(dead_code, reason = "this code may not be dead depending on features")]
Play,
/// Pauses the [Sink].
Pause,
/// Pauses the [Sink]. This will also unpause it if it is paused.
PlayPause,
/// Change the volume of playback.
ChangeVolume(f32),
/// Bookmark the current track.
Bookmark,
/// Quits gracefully.
Quit,
}

View File

@ -1,5 +1,6 @@
//! Responsible for the basic initialization & shutdown of the audio server & frontend. //! Responsible for the basic initialization & shutdown of the audio server & frontend.
use std::io::{stdout, IsTerminal};
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
@ -7,8 +8,9 @@ use eyre::eyre;
use tokio::fs; use tokio::fs;
use tokio::{sync::mpsc, task}; use tokio::{sync::mpsc, task};
use crate::messages::Messages;
use crate::player::ui;
use crate::player::Player; use crate::player::Player;
use crate::player::{ui, Messages};
use crate::Args; use crate::Args;
/// This is the representation of the persistent volume, /// This is the representation of the persistent volume,
@ -23,7 +25,7 @@ impl PersistentVolume {
/// Retrieves the config directory. /// Retrieves the config directory.
async fn config() -> eyre::Result<PathBuf> { async fn config() -> eyre::Result<PathBuf> {
let config = dirs::config_dir() let config = dirs::config_dir()
.ok_or(eyre!("Couldn't find config directory"))? .ok_or_else(|| eyre!("Couldn't find config directory"))?
.join(PathBuf::from("lowfi")); .join(PathBuf::from("lowfi"));
if !config.exists() { if !config.exists() {
@ -35,7 +37,7 @@ impl PersistentVolume {
/// Returns the volume as a float from 0 to 1. /// Returns the volume as a float from 0 to 1.
pub fn float(self) -> f32 { pub fn float(self) -> f32 {
self.inner as f32 / 100.0 f32::from(self.inner) / 100.0
} }
/// Loads the [`PersistentVolume`] from [`dirs::config_dir()`]. /// Loads the [`PersistentVolume`] from [`dirs::config_dir()`].
@ -64,31 +66,65 @@ impl PersistentVolume {
let config = Self::config().await?; let config = Self::config().await?;
let path = config.join(PathBuf::from("volume.txt")); let path = config.join(PathBuf::from("volume.txt"));
fs::write(path, ((volume * 100.0).abs().round() as u16).to_string()).await?; #[expect(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation,
reason = "already rounded & absolute, therefore this should be safe"
)]
let percentage = (volume * 100.0).abs().round() as u16;
fs::write(path, percentage.to_string()).await?;
Ok(()) Ok(())
} }
} }
/// Wrapper around [`rodio::OutputStream`] to implement [Send], currently unsafely.
///
/// This is more of a temporary solution until cpal implements [Send] on it's output stream.
pub struct SendableOutputStream(pub rodio::OutputStream);
// SAFETY: This is necessary because [OutputStream] does not implement [Send],
// due to some limitation with Android's Audio API.
// I'm pretty sure nobody will use lowfi with android, so this is safe.
#[expect(
clippy::non_send_fields_in_send_ty,
reason = "this is expected because of the nature of the struct"
)]
unsafe impl Send for SendableOutputStream {}
/// Initializes the audio server, and then safely stops /// Initializes the audio server, and then safely stops
/// it when the frontend quits. /// it when the frontend quits.
pub async fn play(args: Args) -> eyre::Result<()> { pub async fn play(args: Args) -> eyre::Result<()> {
// Actually initializes the player. // Actually initializes the player.
let player = Arc::new(Player::new(&args).await?); // Stream kept here in the master thread to keep it alive.
let (player, stream) = Player::new(&args).await?;
let player = Arc::new(player);
// Initialize the UI, as well as the internal communication channel.
let (tx, rx) = mpsc::channel(8); let (tx, rx) = mpsc::channel(8);
let ui = task::spawn(ui::start(Arc::clone(&player), tx.clone(), args)); let ui = if stdout().is_terminal() {
Some(task::spawn(ui::start(
Arc::clone(&player),
tx.clone(),
args.clone(),
)))
} else {
None
};
// Sends the player an "init" signal telling it to start playing a song straight away. // Sends the player an "init" signal telling it to start playing a song straight away.
tx.send(Messages::Init).await?; tx.send(Messages::Init).await?;
// Actually starts the player. // Actually starts the player.
Player::play(Arc::clone(&player), tx.clone(), rx).await?; Player::play(Arc::clone(&player), tx.clone(), rx, args.buffer_size).await?;
// Save the volume.txt file for the next session. // Save the volume.txt file for the next session.
PersistentVolume::save(player.sink.volume()).await?; PersistentVolume::save(player.sink.volume()).await?;
drop(stream.0);
player.sink.stop(); player.sink.stop();
ui.abort(); ui.and_then(|x| Some(x.abort()));
Ok(()) Ok(())
} }

View File

@ -2,11 +2,17 @@
//! This also has the code for the underlying //! This also has the code for the underlying
//! audio server which adds new tracks. //! audio server which adds new tracks.
use std::{collections::VecDeque, ffi::CString, sync::Arc, time::Duration}; use std::{
collections::VecDeque,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::Duration,
};
use arc_swap::ArcSwapOption; use arc_swap::ArcSwapOption;
use downloader::Downloader; use downloader::Downloader;
use libc::freopen;
use reqwest::Client; use reqwest::Client;
use rodio::{OutputStream, OutputStreamHandle, Sink}; use rodio::{OutputStream, OutputStreamHandle, Sink};
use tokio::{ use tokio::{
@ -23,8 +29,9 @@ use tokio::{
use mpris_server::{PlaybackStatus, PlayerInterface, Property}; use mpris_server::{PlaybackStatus, PlayerInterface, Property};
use crate::{ use crate::{
play::PersistentVolume, messages::Messages,
tracks::{self, list::List}, play::{PersistentVolume, SendableOutputStream},
tracks::{self, bookmark, list::List},
Args, Args,
}; };
@ -34,50 +41,12 @@ pub mod ui;
#[cfg(feature = "mpris")] #[cfg(feature = "mpris")]
pub mod mpris; pub mod mpris;
/// Handles communication between the frontend & audio player.
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum Messages {
/// Notifies the audio server that it should update the track.
Next,
/// Special in that this isn't sent in a "client to server" sort of way,
/// but rather is sent by a child of the server when a song has not only
/// been requested but also downloaded aswell.
NewSong,
/// This signal is only sent if a track timed out. In that case,
/// lowfi will try again and again to retrieve the track.
TryAgain,
/// Similar to Next, but specific to the first track.
Init,
/// Unpause the [Sink].
Play,
/// Pauses the [Sink].
Pause,
/// Pauses the [Sink]. This will also unpause it if it is paused.
PlayPause,
/// Change the volume of playback.
ChangeVolume(f32),
/// Quits gracefully.
Quit,
}
/// The time to wait in between errors. /// The time to wait in between errors.
const TIMEOUT: Duration = Duration::from_secs(5); const TIMEOUT: Duration = Duration::from_secs(3);
/// The amount of songs to buffer up.
const BUFFER_SIZE: usize = 5;
/// Main struct responsible for queuing up & playing tracks. /// Main struct responsible for queuing up & playing tracks.
// TODO: Consider refactoring [Player] from being stored in an [Arc], // TODO: Consider refactoring [Player] from being stored in an [Arc], into containing many smaller [Arc]s.
// TODO: so `Arc<Player>` into containing many smaller [Arc]s, being just // TODO: In other words, this would change the type from `Arc<Player>` to just `Player`.
// TODO: `Player` as the type.
// TODO: // TODO:
// TODO: This is conflicting, since then it'd clone ~10 smaller [Arc]s // TODO: This is conflicting, since then it'd clone ~10 smaller [Arc]s
// TODO: every single time, which could be even worse than having an // TODO: every single time, which could be even worse than having an
@ -86,6 +55,9 @@ pub struct Player {
/// [rodio]'s [`Sink`] which can control playback. /// [rodio]'s [`Sink`] which can control playback.
pub sink: Sink, pub sink: Sink,
/// Whether the current track has been bookmarked.
bookmarked: AtomicBool,
/// The [`TrackInfo`] of the current track. /// The [`TrackInfo`] of the current track.
/// This is [`None`] when lowfi is buffering/loading. /// This is [`None`] when lowfi is buffering/loading.
current: ArcSwapOption<tracks::Info>, current: ArcSwapOption<tracks::Info>,
@ -110,23 +82,16 @@ pub struct Player {
/// playback, is for now unused and is here just to keep it /// playback, is for now unused and is here just to keep it
/// alive so the playback can function properly. /// alive so the playback can function properly.
_handle: OutputStreamHandle, _handle: OutputStreamHandle,
/// The [`OutputStream`], which is just here to keep the playback
/// alive and functioning.
_stream: OutputStream,
} }
// SAFETY: This is necessary because [OutputStream] does not implement [Send],
// due to some limitation with Android's Audio API.
// I'm pretty sure nobody will use lowfi with android, so this is safe.
unsafe impl Send for Player {}
// SAFETY: See implementation for [Send].
unsafe impl Sync for Player {}
impl Player { impl Player {
/// This gets the output stream while also shutting up alsa with [libc]. /// This gets the output stream while also shutting up alsa with [libc].
/// Uses raw libc calls, and therefore is functional only on Linux.
#[cfg(target_os = "linux")]
fn silent_get_output_stream() -> eyre::Result<(OutputStream, OutputStreamHandle)> { fn silent_get_output_stream() -> eyre::Result<(OutputStream, OutputStreamHandle)> {
use libc::freopen;
use std::ffi::CString;
// Get the file descriptor to stderr from libc. // Get the file descriptor to stderr from libc.
extern "C" { extern "C" {
static stderr: *mut libc::FILE; static stderr: *mut libc::FILE;
@ -136,23 +101,25 @@ impl Player {
// output to `/dev/null` so that it wont be shoved down our throats. // output to `/dev/null` so that it wont be shoved down our throats.
// The mode which to redirect terminal output with. // The mode which to redirect terminal output with.
let mode = CString::new("w")?.as_ptr(); let mode = CString::new("w")?;
// First redirect to /dev/null, which basically silences alsa. // First redirect to /dev/null, which basically silences alsa.
let null = CString::new("/dev/null")?.as_ptr(); let null = CString::new("/dev/null")?;
// SAFETY: Simple enough to be impossible to fail. Hopefully. // SAFETY: Simple enough to be impossible to fail. Hopefully.
unsafe { unsafe {
freopen(null, mode, stderr); freopen(null.as_ptr(), mode.as_ptr(), stderr);
} }
// Make the OutputStream while stderr is still redirected to /dev/null. // Make the OutputStream while stderr is still redirected to /dev/null.
let (stream, handle) = OutputStream::try_default()?; let (stream, handle) = OutputStream::try_default()?;
// Redirect back to the current terminal, so that other output isn't silenced. // Redirect back to the current terminal, so that other output isn't silenced.
let tty = CString::new("/dev/tty")?.as_ptr(); let tty = CString::new("/dev/tty")?;
// SAFETY: See the first call to `freopen`. // SAFETY: See the first call to `freopen`.
unsafe { unsafe {
freopen(tty, mode, stderr); freopen(tty.as_ptr(), mode.as_ptr(), stderr);
} }
Ok((stream, handle)) Ok((stream, handle))
@ -176,20 +143,25 @@ impl Player {
/// Initializes the entire player, including audio devices & sink. /// Initializes the entire player, including audio devices & sink.
/// ///
/// This also will load the track list & persistent volume. /// This also will load the track list & persistent volume.
pub async fn new(args: &Args) -> eyre::Result<Self> { pub async fn new(args: &Args) -> eyre::Result<(Self, SendableOutputStream)> {
// Load the volume file. // Load the volume file.
let volume = PersistentVolume::load().await?; let volume = PersistentVolume::load().await?;
// Load the track list. // Load the track list.
let list = List::load(&args.tracks).await?; let list = List::load(args.track_list.as_ref()).await?;
// We should only shut up alsa forcefully if we really have to. // We should only shut up alsa forcefully on Linux if we really have to.
let (_stream, handle) = if cfg!(target_os = "linux") && !args.alternate && !args.debug { #[cfg(target_os = "linux")]
let (stream, handle) = if !args.alternate && !args.debug {
Self::silent_get_output_stream()? Self::silent_get_output_stream()?
} else { } else {
OutputStream::try_default()? OutputStream::try_default()?
}; };
// If we're not on Linux, then there's no problem.
#[cfg(not(target_os = "linux"))]
let (stream, handle) = OutputStream::try_default()?;
let sink = Sink::try_new(&handle)?; let sink = Sink::try_new(&handle)?;
if args.paused { if args.paused {
sink.pause(); sink.pause();
@ -205,24 +177,26 @@ impl Player {
.build()?; .build()?;
let player = Self { let player = Self {
tracks: RwLock::new(VecDeque::with_capacity(5)), tracks: RwLock::new(VecDeque::with_capacity(args.buffer_size)),
current: ArcSwapOption::new(None), current: ArcSwapOption::new(None),
client, client,
sink, sink,
volume, volume,
list, list,
_handle: handle, _handle: handle,
_stream, bookmarked: AtomicBool::new(false),
}; };
Ok(player) Ok((player, SendableOutputStream(stream)))
} }
/// This will play the next track, as well as refilling the buffer in the background. /// This will play the next track, as well as refilling the buffer in the background.
/// ///
/// This will also set `current` to the newly loaded song. /// This will also set `current` to the newly loaded song.
pub async fn next(&self) -> eyre::Result<tracks::Decoded> { pub async fn next(&self) -> Result<tracks::Decoded, bool> {
let track = if let Some(track) = self.tracks.write().await.pop_front() { // TODO: Consider replacing this with `unwrap_or_else` when async closures are stablized.
let track = self.tracks.write().await.pop_front();
let track = if let Some(track) = track {
track track
} else { } else {
// If the queue is completely empty, then fallback to simply getting a new track. // If the queue is completely empty, then fallback to simply getting a new track.
@ -232,11 +206,10 @@ impl Player {
// We're doing it here so that we don't get the "loading" display // We're doing it here so that we don't get the "loading" display
// for only a frame in the other case that the buffer is not empty. // for only a frame in the other case that the buffer is not empty.
self.current.store(None); self.current.store(None);
self.list.random(&self.client).await? self.list.random(&self.client).await?
}; };
let decoded = track.decode()?; let decoded = track.decode().map_err(|_| false)?;
// Set the current track. // Set the current track.
self.set_current(decoded.info.clone()); self.set_current(decoded.info.clone());
@ -274,8 +247,8 @@ impl Player {
// Notify the audio server that the next song has actually been downloaded. // Notify the audio server that the next song has actually been downloaded.
tx.send(Messages::NewSong).await?; tx.send(Messages::NewSong).await?;
} }
Err(error) => { Err(timeout) => {
if !error.downcast::<reqwest::Error>()?.is_timeout() { if !timeout {
sleep(TIMEOUT).await; sleep(TIMEOUT).await;
} }
@ -292,10 +265,12 @@ impl Player {
/// skip tracks or pause. /// skip tracks or pause.
/// ///
/// This will also initialize a [Downloader] as well as an MPRIS server if enabled. /// This will also initialize a [Downloader] as well as an MPRIS server if enabled.
/// The [Downloader]s internal buffer size is determined by `buf_size`.
pub async fn play( pub async fn play(
player: Arc<Self>, player: Arc<Self>,
tx: Sender<Messages>, tx: Sender<Messages>,
mut rx: Receiver<Messages>, mut rx: Receiver<Messages>,
buf_size: usize,
) -> eyre::Result<()> { ) -> eyre::Result<()> {
// Initialize the mpris player. // Initialize the mpris player.
// //
@ -311,7 +286,7 @@ impl Player {
})?; })?;
// `itx` is used to notify the `Downloader` when it needs to download new tracks. // `itx` is used to notify the `Downloader` when it needs to download new tracks.
let downloader = Downloader::new(Arc::clone(&player)); let downloader = Downloader::new(Arc::clone(&player), buf_size);
let (itx, downloader) = downloader.start(); let (itx, downloader) = downloader.start();
// Start buffering tracks immediately. // Start buffering tracks immediately.
@ -418,6 +393,25 @@ impl Player {
continue; continue;
} }
Messages::Bookmark => {
if player.bookmarked.load(Ordering::Relaxed) {
continue;
}
player.bookmarked.swap(true, Ordering::Relaxed);
let current = player.current.load();
let current = current.as_ref().unwrap();
bookmark::bookmark(
current.full_path.clone(),
if current.custom_name {
Some(current.display_name.clone())
} else {
None
},
)
.await?;
}
Messages::Quit => break, Messages::Quit => break,
} }
} }

View File

@ -8,7 +8,7 @@ use tokio::{
time::sleep, time::sleep,
}; };
use super::{Player, BUFFER_SIZE, TIMEOUT}; use super::{Player, TIMEOUT};
/// This struct is responsible for downloading tracks in the background. /// This struct is responsible for downloading tracks in the background.
/// ///
@ -24,6 +24,9 @@ pub struct Downloader {
/// A copy of the internal sender, which can be useful for keeping /// A copy of the internal sender, which can be useful for keeping
/// track of it. /// track of it.
tx: Sender<()>, tx: Sender<()>,
/// The size of the internal download buffer.
buf_size: usize,
} }
impl Downloader { impl Downloader {
@ -37,9 +40,14 @@ impl Downloader {
/// ///
/// This also sends a [`Sender`] which can be used to notify /// This also sends a [`Sender`] which can be used to notify
/// when the downloader needs to begin downloading more tracks. /// when the downloader needs to begin downloading more tracks.
pub fn new(player: Arc<Player>) -> Self { pub fn new(player: Arc<Player>, buf_size: usize) -> Self {
let (tx, rx) = mpsc::channel(8); let (tx, rx) = mpsc::channel(8);
Self { player, rx, tx } Self {
player,
rx,
tx,
buf_size,
}
} }
/// Actually starts & consumes the [Downloader]. /// Actually starts & consumes the [Downloader].
@ -50,11 +58,12 @@ impl Downloader {
// Loop through each update notification. // Loop through each update notification.
while self.rx.recv().await == Some(()) { while self.rx.recv().await == Some(()) {
// For each update notification, we'll push tracks until the buffer is completely full. // For each update notification, we'll push tracks until the buffer is completely full.
while self.player.tracks.read().await.len() < BUFFER_SIZE { while self.player.tracks.read().await.len() < self.buf_size {
match self.player.list.random(&self.player.client).await { let data = self.player.list.random(&self.player.client).await;
match data {
Ok(track) => self.player.tracks.write().await.push_back(track), Ok(track) => self.player.tracks.write().await.push_back(track),
Err(error) => { Err(timeout) => {
if !error.is_timeout() { if !timeout {
sleep(TIMEOUT).await; sleep(TIMEOUT).await;
} }
} }

View File

@ -1,6 +1,6 @@
//! Contains the code for the MPRIS server & other helper functions. //! Contains the code for the MPRIS server & other helper functions.
use std::{process, sync::Arc}; use std::{env, process, sync::Arc};
use mpris_server::{ use mpris_server::{
zbus::{self, fdo, Result}, zbus::{self, fdo, Result},
@ -9,6 +9,7 @@ use mpris_server::{
}; };
use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::Sender;
use super::ui;
use super::Messages; use super::Messages;
const ERROR: fdo::Error = fdo::Error::Failed(String::new()); const ERROR: fdo::Error = fdo::Error::Failed(String::new());
@ -167,7 +168,10 @@ impl PlayerInterface for Player {
.load() .load()
.as_ref() .as_ref()
.map_or_else(Metadata::new, |track| { .map_or_else(Metadata::new, |track| {
let mut metadata = Metadata::builder().title(track.name.clone()).build(); let mut metadata = Metadata::builder()
.title(track.display_name.clone())
.album(self.player.list.name.clone())
.build();
metadata.set_length( metadata.set_length(
track track
@ -187,6 +191,7 @@ impl PlayerInterface for Player {
async fn set_volume(&self, volume: Volume) -> Result<()> { async fn set_volume(&self, volume: Volume) -> Result<()> {
self.player.set_volume(volume as f32); self.player.set_volume(volume as f32);
ui::flash_audio();
Ok(()) Ok(())
} }
@ -262,7 +267,11 @@ impl Server {
/// Creates a new MPRIS server. /// Creates a new MPRIS server.
pub async fn new(player: Arc<super::Player>, sender: Sender<Messages>) -> eyre::Result<Self> { pub async fn new(player: Arc<super::Player>, sender: Sender<Messages>) -> eyre::Result<Self> {
let suffix = format!("lowfi.{}.instance{}", player.list.name, process::id()); let suffix = if env::var("LOWFI_FIXED_MPRIS_NAME").is_ok_and(|x| x == "1") {
String::from("lowfi")
} else {
format!("lowfi.{}.instance{}", player.list.name, process::id())
};
let server = mpris_server::Server::new(&suffix, Player { player, sender }).await?; let server = mpris_server::Server::new(&suffix, Player { player, sender }).await?;

View File

@ -1,7 +1,15 @@
//! The module which manages all user interface, including inputs. //! The module which manages all user interface, including inputs.
#![allow(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
reason = "the ui is full of these because of various layout & positioning aspects, and for a simple music player making all casts safe is not worth the effort"
)]
use std::{ use std::{
fmt::Write, fmt::Write as _,
io::{stdout, Stdout}, io::{stdout, Stdout},
sync::{ sync::{
atomic::{AtomicUsize, Ordering}, atomic::{AtomicUsize, Ordering},
@ -15,12 +23,13 @@ use crate::Args;
use crossterm::{ use crossterm::{
cursor::{Hide, MoveTo, MoveToColumn, MoveUp, Show}, cursor::{Hide, MoveTo, MoveToColumn, MoveUp, Show},
event::{KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags}, event::{KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags},
style::{Print, Stylize}, style::{Print, Stylize as _},
terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen}, terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen},
}; };
use lazy_static::lazy_static; use lazy_static::lazy_static;
use tokio::{sync::mpsc::Sender, task, time::sleep}; use tokio::{sync::mpsc::Sender, task, time::sleep};
use unicode_segmentation::UnicodeSegmentation;
use super::{Messages, Player}; use super::{Messages, Player};
@ -48,57 +57,83 @@ lazy_static! {
static ref VOLUME_TIMER: AtomicUsize = AtomicUsize::new(0); static ref VOLUME_TIMER: AtomicUsize = AtomicUsize::new(0);
} }
/// Sets the volume timer to one, effectively flashing the audio display in lowfi's UI.
///
/// The amount of frames the audio display is visible for is determined by [`AUDIO_BAR_DURATION`].
pub fn flash_audio() {
VOLUME_TIMER.store(1, Ordering::Relaxed);
}
/// Represents an abstraction for drawing the actual lowfi window itself. /// Represents an abstraction for drawing the actual lowfi window itself.
/// ///
/// The main purpose of this struct is just to add the fancy border, /// The main purpose of this struct is just to add the fancy border,
/// as well as clear the screen before drawing. /// as well as clear the screen before drawing.
pub struct Window { pub struct Window {
/// Whether or not to include borders in the output.
borderless: bool,
/// The top & bottom borders, which are here since they can be /// The top & bottom borders, which are here since they can be
/// prerendered, as they don't change from window to window. /// prerendered, as they don't change from window to window.
///
/// If the option to not include borders is set, these will just be empty [String]s.
borders: [String; 2], borders: [String; 2],
/// The width of the window.
width: usize,
/// The output, currently just an [`Stdout`]. /// The output, currently just an [`Stdout`].
out: Stdout, out: Stdout,
} }
impl Window { impl Window {
/// Initializes a new [Window]. /// Initializes a new [Window].
pub fn new(width: usize) -> Self { ///
/// * `width` - Width of the windows.
/// * `borderless` - Whether to include borders in the window, or not.
pub fn new(width: usize, borderless: bool) -> Self {
let borders = if borderless {
[String::new(), String::new()]
} else {
let middle = "".repeat(width + 2);
[format!("{middle}"), format!("{middle}")]
};
Self { Self {
borders: [ borders,
format!("{}\r\n", "".repeat(width + 2)), borderless,
// This one doesn't have a leading \r\n to avoid extra space under the window. width,
format!("{}", "".repeat(width + 2)),
],
out: stdout(), out: stdout(),
} }
} }
/// Actually draws the window, with each element in `content` being on a new line. /// Actually draws the window, with each element in `content` being on a new line.
pub fn draw(&mut self, content: Vec<String>) -> eyre::Result<()> { pub fn draw(&mut self, content: Vec<String>, space: bool) -> eyre::Result<()> {
let len = content.len() as u16; let len: u16 = content.len().try_into()?;
// Note that this will have a trailing newline, which we use later.
let menu: String = content.into_iter().fold(String::new(), |mut output, x| { let menu: String = content.into_iter().fold(String::new(), |mut output, x| {
write!(output, "│ {} │\r\n", x.reset()).unwrap(); // Horizontal Padding & Border
let padding = if self.borderless { " " } else { "" };
let space = if space {
" ".repeat(self.width.saturating_sub(x.graphemes(true).count()))
} else {
String::new()
};
write!(output, "{padding} {}{space} {padding}\r\n", x.reset()).unwrap();
output output
}); });
// We're doing this because Windows is stupid and can't stand // We're doing this because Windows is stupid and can't stand
// writing to the last line repeatedly. Again, it's stupid. // writing to the last line repeatedly.
#[cfg(windows)] #[cfg(windows)]
let (rendered, height) = ( let (height, suffix) = (len + 2, "\r\n");
format!("{}{}{}\r\n", self.borders[0], menu, self.borders[1]),
len + 2,
);
// Unix has no such ridiculous limitations, so we calculate
// the height of the window accurately.
#[cfg(not(windows))] #[cfg(not(windows))]
let (rendered, height) = ( let (height, suffix) = (len + 1, "");
format!("{}{}{}", self.borders[0], menu, self.borders[1]),
len + 1, // There's no need for another newline after the main menu content, because it already has one.
); let rendered = format!("{}\r\n{menu}{}{suffix}", self.borders[0], self.borders[1]);
crossterm::execute!( crossterm::execute!(
self.out, self.out,
@ -116,9 +151,15 @@ impl Window {
/// The code for the terminal interface itself. /// The code for the terminal interface itself.
/// ///
/// * `minimalist` - All this does is hide the bottom control bar. /// * `minimalist` - All this does is hide the bottom control bar.
/// * `borderless` - Whether to include borders or not.
/// * `width` - The width of player /// * `width` - The width of player
async fn interface(player: Arc<Player>, minimalist: bool, width: usize) -> eyre::Result<()> { async fn interface(
let mut window = Window::new(width); player: Arc<Player>,
minimalist: bool,
borderless: bool,
width: usize,
) -> eyre::Result<()> {
let mut window = Window::new(width, borderless);
loop { loop {
// Load `current` once so that it doesn't have to be loaded over and over // Load `current` once so that it doesn't have to be loaded over and over
@ -140,7 +181,7 @@ async fn interface(player: Arc<Player>, minimalist: bool, width: usize) -> eyre:
if timer > 0 && timer <= AUDIO_BAR_DURATION { if timer > 0 && timer <= AUDIO_BAR_DURATION {
// We'll keep increasing the timer until it eventually hits `AUDIO_BAR_DURATION`. // We'll keep increasing the timer until it eventually hits `AUDIO_BAR_DURATION`.
VOLUME_TIMER.fetch_add(1, Ordering::Relaxed); VOLUME_TIMER.fetch_add(1, Ordering::Relaxed);
} else if timer > AUDIO_BAR_DURATION { } else {
// If enough time has passed, we'll reset it back to 0. // If enough time has passed, we'll reset it back to 0.
VOLUME_TIMER.store(0, Ordering::Relaxed); VOLUME_TIMER.store(0, Ordering::Relaxed);
} }
@ -153,7 +194,7 @@ async fn interface(player: Arc<Player>, minimalist: bool, width: usize) -> eyre:
vec![action, middle, controls] vec![action, middle, controls]
}; };
window.draw(menu)?; window.draw(menu, false)?;
sleep(Duration::from_secs_f32(FRAME_DELTA)).await; sleep(Duration::from_secs_f32(FRAME_DELTA)).await;
} }
@ -237,6 +278,7 @@ pub async fn start(player: Arc<Player>, sender: Sender<Messages>, args: Args) ->
let interface = task::spawn(interface( let interface = task::spawn(interface(
Arc::clone(&player), Arc::clone(&player),
args.minimalist, args.minimalist,
args.borderless,
21 + args.width.min(32) * 2, 21 + args.width.min(32) * 2,
)); ));

View File

@ -1,10 +1,14 @@
//! Various different individual components that //! Various different individual components that
//! appear in lowfi's UI, like the progress bar. //! appear in lowfi's UI, like the progress bar.
use std::{ops::Deref, sync::Arc, time::Duration}; use std::{
ops::Deref as _,
sync::{atomic::Ordering, Arc},
time::Duration,
};
use crossterm::style::Stylize; use crossterm::style::Stylize as _;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation as _;
use crate::{player::Player, tracks::Info}; use crate::{player::Player, tracks::Info};
@ -72,16 +76,21 @@ enum ActionBar {
impl ActionBar { impl ActionBar {
/// Formats the action bar to be displayed. /// Formats the action bar to be displayed.
/// The second value is the character length of the result. /// The second value is the character length of the result.
fn format(&self) -> (String, usize) { fn format(&self, star: bool) -> (String, usize) {
let (word, subject) = match self { let (word, subject) = match self {
Self::Playing(x) => ("playing", Some((x.name.clone(), x.width))), Self::Playing(x) => ("playing", Some((x.display_name.clone(), x.width))),
Self::Paused(x) => ("paused", Some((x.name.clone(), x.width))), Self::Paused(x) => ("paused", Some((x.display_name.clone(), x.width))),
Self::Loading => ("loading", None), Self::Loading => ("loading", None),
}; };
subject.map_or_else( subject.map_or_else(
|| (word.to_owned(), word.len()), || (word.to_owned(), word.len()),
|(subject, len)| (format!("{} {}", word, subject.bold()), word.len() + 1 + len), |(subject, len)| {
(
format!("{} {}{}", word, if star { "*" } else { "" }, subject.bold()),
word.len() + 1 + len + if star { 1 } else { 0 },
)
},
) )
} }
} }
@ -99,12 +108,12 @@ pub fn action(player: &Player, current: Option<&Arc<Info>>, width: usize) -> Str
ActionBar::Playing(info) ActionBar::Playing(info)
} }
}) })
.format(); .format(player.bookmarked.load(Ordering::Relaxed));
if len > width { if len > width {
let chopped: String = main.graphemes(true).take(width + 1).collect(); let chopped: String = main.graphemes(true).take(width + 1).collect();
format!("{}...", chopped) format!("{chopped}...")
} else { } else {
format!("{}{}", main, " ".repeat(width - len)) format!("{}{}", main, " ".repeat(width - len))
} }

View File

@ -1,15 +1,11 @@
//! Responsible for specifically recieving terminal input //! Responsible for specifically recieving terminal input
//! using [`crossterm`]. //! using [`crossterm`].
use std::sync::atomic::Ordering;
use crossterm::event::{self, EventStream, KeyCode, KeyEventKind, KeyModifiers}; use crossterm::event::{self, EventStream, KeyCode, KeyEventKind, KeyModifiers};
use futures::{FutureExt, StreamExt}; use futures::{FutureExt as _, StreamExt as _};
use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::Sender;
use crate::player::Messages; use crate::player::{ui, Messages};
use super::VOLUME_TIMER;
/// Starts the listener to recieve input from the terminal for various events. /// Starts the listener to recieve input from the terminal for various events.
pub async fn listen(sender: Sender<Messages>) -> eyre::Result<()> { pub async fn listen(sender: Sender<Messages>) -> eyre::Result<()> {
@ -38,14 +34,17 @@ pub async fn listen(sender: Sender<Messages>) -> eyre::Result<()> {
'q' => Messages::Quit, 'q' => Messages::Quit,
// Skip/Next // Skip/Next
's' | 'n' => Messages::Next, 's' | 'n' | 'l' => Messages::Next,
// Pause // Pause
'p' => Messages::PlayPause, 'p' | ' ' => Messages::PlayPause,
// Volume up & down // Volume up & down
'+' | '=' => Messages::ChangeVolume(0.1), '+' | '=' | 'k' => Messages::ChangeVolume(0.1),
'-' | '_' => Messages::ChangeVolume(-0.1), '-' | '_' | 'j' => Messages::ChangeVolume(-0.1),
// Bookmark
'b' => Messages::Bookmark,
_ => continue, _ => continue,
}, },
@ -64,10 +63,8 @@ pub async fn listen(sender: Sender<Messages>) -> eyre::Result<()> {
_ => continue, _ => continue,
}; };
// If it's modifying the volume, then we'll set the `VOLUME_TIMER` to 1
// so that the UI thread will know that it should show the audio bar.
if let Messages::ChangeVolume(_) = messages { if let Messages::ChangeVolume(_) = messages {
VOLUME_TIMER.store(1, Ordering::Relaxed); ui::flash_audio();
} }
sender.send(messages).await?; sender.send(messages).await?;

View File

@ -1,28 +1,85 @@
//! Has all of the structs for managing the state //! Has all of the structs for managing the state
//! of tracks, as well as downloading them & //! of tracks, as well as downloading them & finding new ones.
//! finding new ones. //!
//! There are several structs which represent the different stages
//! that go on in downloading and playing tracks. The proccess for fetching tracks,
//! and what structs are relevant in each step, are as follows.
//!
//! First Stage, when a track is initially fetched.
//! 1. Raw entry selected from track list.
//! 2. Raw entry split into path & display name.
//! 3. Track data fetched, and [`Track`] is created which includes a [`TrackName`] that may be raw.
//!
//! Second Stage, when a track is played.
//! 1. Track data is decoded.
//! 2. [`Info`] created from decoded data.
//! 3. [`Decoded`] made from [`Info`] and the original decoded data.
use std::{io::Cursor, time::Duration}; use std::{io::Cursor, time::Duration};
use bytes::Bytes; use bytes::Bytes;
use inflector::Inflector; use eyre::OptionExt as _;
use rodio::{Decoder, Source}; use inflector::Inflector as _;
use unicode_width::UnicodeWidthStr; use rodio::{Decoder, Source as _};
use unicode_segmentation::UnicodeSegmentation;
use url::form_urlencoded; use url::form_urlencoded;
pub mod bookmark;
pub mod list; pub mod list;
/// Just a shorthand for a decoded [Bytes]. /// Just a shorthand for a decoded [Bytes].
pub type DecodedData = Decoder<Cursor<Bytes>>; pub type DecodedData = Decoder<Cursor<Bytes>>;
/// Specifies a track's name, and specifically,
/// whether it has already been formatted or if it
/// is still in it's raw path form.
#[derive(Debug, Clone)]
pub enum TrackName {
/// Pulled straight from the list,
/// with no splitting done at all.
Raw(String),
/// If a track has a custom specified name
/// in the list, then it should be defined with this variant.
Formatted(String),
}
/// The main track struct, which only includes data & the track name.
pub struct Track {
/// Name of the track, which may be raw.
pub name: TrackName,
/// Full downloadable path/url of the track.
pub full_path: String,
/// The raw data of the track, which is not decoded and
/// therefore much more memory efficient.
pub data: Bytes,
}
impl Track {
/// This will actually decode and format the track,
/// returning a [`DecodedTrack`] which can be played
/// and also has a duration & formatted name.
pub fn decode(self) -> eyre::Result<Decoded> {
Decoded::new(self)
}
}
/// The [`Info`] struct, which has the name and duration of a track. /// The [`Info`] struct, which has the name and duration of a track.
/// ///
/// This is not included in [Track] as the duration has to be acquired /// This is not included in [Track] as the duration has to be acquired
/// from the decoded data and not from the raw data. /// from the decoded data and not from the raw data.
#[derive(Debug, Eq, PartialEq, Clone)] #[derive(Debug, Eq, PartialEq, Clone)]
pub struct Info { pub struct Info {
/// The full downloadable path/url of the track.
pub full_path: String,
/// Whether the track entry included a custom name, or not.
pub custom_name: bool,
/// This is a formatted name, so it doesn't include the full path. /// This is a formatted name, so it doesn't include the full path.
pub name: String, pub display_name: String,
/// This is the *actual* terminal width of the track name, used to make /// This is the *actual* terminal width of the track name, used to make
/// the UI consistent. /// the UI consistent.
@ -36,6 +93,10 @@ pub struct Info {
impl Info { impl Info {
/// Decodes a URL string into normal UTF-8. /// Decodes a URL string into normal UTF-8.
fn decode_url(text: &str) -> String { fn decode_url(text: &str) -> String {
#[expect(
clippy::tuple_array_conversions,
reason = "the tuple contains smart pointers, so it's not really practical to use `into()`"
)]
form_urlencoded::parse(text.as_bytes()) form_urlencoded::parse(text.as_bytes())
.map(|(key, val)| [key, val].concat()) .map(|(key, val)| [key, val].concat())
.collect() .collect()
@ -44,26 +105,26 @@ impl Info {
/// Formats a name with [Inflector]. /// Formats a name with [Inflector].
/// This will also strip the first few numbers that are /// This will also strip the first few numbers that are
/// usually present on most lofi tracks. /// usually present on most lofi tracks.
fn format_name(name: &str) -> String { fn format_name(name: &str) -> eyre::Result<String> {
let formatted = Self::decode_url( let split = name
name.split('/') .split('/')
.last() .last()
.unwrap() .ok_or_eyre("split is never supposed to return nothing")?;
.strip_suffix(".mp3")
.unwrap(), let stripped = split.strip_suffix(".mp3").unwrap_or(split);
) let formatted = Self::decode_url(stripped)
.to_lowercase() .to_lowercase()
.to_title_case() .to_title_case()
// Inflector doesn't like contractions... // Inflector doesn't like contractions...
// Replaces a few very common ones. // Replaces a few very common ones.
// TODO: Properly handle these. // TODO: Properly handle these.
.replace(" S ", "'s ") .replace(" S ", "'s ")
.replace(" T ", "'t ") .replace(" T ", "'t ")
.replace(" D ", "'d ") .replace(" D ", "'d ")
.replace(" Ve ", "'ve ") .replace(" Ve ", "'ve ")
.replace(" Ll ", "'ll ") .replace(" Ll ", "'ll ")
.replace(" Re ", "'re ") .replace(" Re ", "'re ")
.replace(" M ", "'m "); .replace(" M ", "'m ");
// This is incremented for each digit in front of the song name. // This is incremented for each digit in front of the song name.
let mut skip = 0; let mut skip = 0;
@ -76,19 +137,32 @@ impl Info {
} }
} }
#[allow(clippy::string_slice, /* We've already checked before that the bound is at an ASCII digit. */)] // If the entire name of the track is a number, then just return it.
String::from(&formatted[skip..]) if skip == formatted.len() {
Ok(formatted)
} else {
#[expect(
clippy::string_slice,
reason = "We've already checked before that the bound is at an ASCII digit."
)]
Ok(String::from(&formatted[skip..]))
}
} }
/// Creates a new [`TrackInfo`] from a raw name & decoded track data. /// Creates a new [`TrackInfo`] from a possibly raw name & decoded data.
pub fn new(name: &str, decoded: &DecodedData) -> Self { pub fn new(name: TrackName, full_path: String, decoded: &DecodedData) -> eyre::Result<Self> {
let name = Self::format_name(name); let (display_name, custom_name) = match name {
TrackName::Raw(raw) => (Self::format_name(&raw)?, false),
TrackName::Formatted(custom) => (custom, true),
};
Self { Ok(Self {
duration: decoded.total_duration(), duration: decoded.total_duration(),
width: name.width(), width: display_name.graphemes(true).count(),
name, full_path,
} custom_name,
display_name,
})
} }
} }
@ -107,27 +181,8 @@ impl Decoded {
/// This is equivalent to [`Track::decode`]. /// This is equivalent to [`Track::decode`].
pub fn new(track: Track) -> eyre::Result<Self> { pub fn new(track: Track) -> eyre::Result<Self> {
let data = Decoder::new(Cursor::new(track.data))?; let data = Decoder::new(Cursor::new(track.data))?;
let info = Info::new(&track.name, &data); let info = Info::new(track.name, track.full_path, &data)?;
Ok(Self { info, data }) Ok(Self { info, data })
} }
} }
/// The main track struct, which only includes data & the track name.
pub struct Track {
/// This name is not formatted, and also includes the month & year of the track.
pub name: String,
/// The raw data of the track, which is not decoded and
/// therefore much more memory efficient.
pub data: Bytes,
}
impl Track {
/// This will actually decode and format the track,
/// returning a [`DecodedTrack`] which can be played
/// and also has a duration & formatted name.
pub fn decode(self) -> eyre::Result<Decoded> {
Decoded::new(self)
}
}

27
src/tracks/bookmark.rs Normal file
View File

@ -0,0 +1,27 @@
use tokio::fs::{create_dir_all, OpenOptions};
use tokio::io::AsyncWriteExt;
use crate::data_dir;
pub async fn bookmark(path: String, custom: Option<String>) -> eyre::Result<()> {
let mut entry = format!("\n{path}");
if let Some(custom) = custom {
entry.push('!');
entry.push_str(&custom);
}
let data_dir = data_dir()?;
create_dir_all(data_dir.clone()).await?;
let mut file = OpenOptions::new()
.create(true)
.write(true)
.append(true)
.open(data_dir.join("bookmarks.txt"))
.await?;
file.write_all(entry.as_bytes()).await?;
Ok(())
}

View File

@ -2,11 +2,13 @@
//! as well as obtaining track names & downloading the raw mp3 data. //! as well as obtaining track names & downloading the raw mp3 data.
use bytes::Bytes; use bytes::Bytes;
use eyre::OptionExt; use eyre::OptionExt as _;
use rand::Rng; use rand::Rng as _;
use reqwest::Client; use reqwest::Client;
use tokio::fs; use tokio::fs;
use crate::data_dir;
use super::Track; use super::Track;
/// Represents a list of tracks that can be played. /// Represents a list of tracks that can be played.
@ -15,6 +17,7 @@ use super::Track;
#[derive(Clone)] #[derive(Clone)]
pub struct List { pub struct List {
/// The "name" of the list, usually derived from a filename. /// The "name" of the list, usually derived from a filename.
#[allow(dead_code, reason = "this code may not be dead depending on features")]
pub name: String, pub name: String,
/// Just the raw file, but seperated by `/n` (newlines). /// Just the raw file, but seperated by `/n` (newlines).
@ -28,45 +31,84 @@ impl List {
self.lines[0].trim() self.lines[0].trim()
} }
/// Gets the name of a random track. /// Gets the path of a random track.
fn random_name(&self) -> String { ///
/// The second value in the tuple specifies whether the
/// track has a custom display name.
fn random_path(&self) -> (String, Option<String>) {
// We're getting from 1 here, since the base is at `self.lines[0]`. // We're getting from 1 here, since the base is at `self.lines[0]`.
// //
// We're also not pre-trimming `self.lines` into `base` & `tracks` due to // We're also not pre-trimming `self.lines` into `base` & `tracks` due to
// how rust vectors work, sinceslow to drain only a single element from // how rust vectors work, since it is slower to drain only a single element from
// the start, so it's faster to just keep it in & work around it. // the start, so it's faster to just keep it in & work around it.
let random = rand::thread_rng().gen_range(1..self.lines.len()); let random = rand::thread_rng().gen_range(1..self.lines.len());
self.lines[random].clone() let line = self.lines[random].clone();
if let Some((first, second)) = line.split_once('!') {
(first.to_owned(), Some(second.to_owned()))
} else {
(line, None)
}
} }
/// Downloads a raw track, but doesn't decode it. /// Downloads a raw track, but doesn't decode it.
async fn download(&self, track: &str, client: &Client) -> reqwest::Result<Bytes> { async fn download(&self, track: &str, client: &Client) -> Result<(Bytes, String), bool> {
// If the track has a protocol, then we should ignore the base for it. // If the track has a protocol, then we should ignore the base for it.
let url = if track.contains("://") { let full_path = if track.contains("://") {
track.to_owned() track.to_owned()
} else { } else {
format!("{}{}", self.base(), track) format!("{}{}", self.base(), track)
}; };
let response = client.get(url).send().await?; let data: Bytes = if let Some(x) = full_path.strip_prefix("file://") {
let data = response.bytes().await?; let path = if x.starts_with("~") {
let home_path = dirs::home_dir().ok_or(false)?;
let home = home_path.to_str().ok_or(false)?;
Ok(data) x.replace("~", home)
} else {
x.to_owned()
};
let result = tokio::fs::read(path).await.map_err(|_| false)?;
result.into()
} else {
let response = client
.get(full_path.clone())
.send()
.await
.map_err(|x| x.is_timeout())?;
response.bytes().await.map_err(|_| false)?
};
Ok((data, full_path))
} }
/// Fetches and downloads a random track from the [List]. /// Fetches and downloads a random track from the [List].
pub async fn random(&self, client: &Client) -> reqwest::Result<Track> { ///
let name = self.random_name(); /// The Result's error is a bool, which is true if a timeout error occured,
let data = self.download(&name, client).await?; /// and false otherwise. This tells lowfi if it shouldn't wait to try again.
pub async fn random(&self, client: &Client) -> Result<Track, bool> {
let (path, custom_name) = self.random_path();
let (data, full_path) = self.download(&path, client).await?;
Ok(Track { name, data }) let name = custom_name.map_or(super::TrackName::Raw(path.clone()), |formatted| {
super::TrackName::Formatted(formatted)
});
Ok(Track {
name,
data,
full_path,
})
} }
/// Parses text into a [List]. /// Parses text into a [List].
pub fn new(name: &str, text: &str) -> Self { pub fn new(name: &str, text: &str) -> Self {
let lines: Vec<String> = text let lines: Vec<String> = text
.split_ascii_whitespace() .trim()
.map(ToOwned::to_owned) .lines()
.map(|x| x.trim_end().to_owned())
.collect(); .collect();
Self { Self {
@ -76,13 +118,10 @@ impl List {
} }
/// Reads a [List] from the filesystem using the CLI argument provided. /// Reads a [List] from the filesystem using the CLI argument provided.
pub async fn load(tracks: &Option<String>) -> eyre::Result<Self> { pub async fn load(tracks: Option<&String>) -> eyre::Result<Self> {
if let Some(arg) = tracks { if let Some(arg) = tracks {
// Check if the track is in ~/.local/share/lowfi, in which case we'll load that. // Check if the track is in ~/.local/share/lowfi, in which case we'll load that.
let name = dirs::data_dir() let name = data_dir()?.join(format!("{arg}.txt"));
.unwrap()
.join("lowfi")
.join(format!("{}.txt", arg));
let name = if name.exists() { name } else { arg.into() }; let name = if name.exists() { name } else { arg.into() };