Compare commits

...

No commits in common. "rewrite" and "main" have entirely different histories.

116 changed files with 4463 additions and 7793 deletions

View File

@ -1,8 +1,2 @@
[target.aarch64-unknown-linux-gnu]
linker="aarch64-linux-gnu-gcc"
[env]
XMPD_MANIFEST_PATH="./manifest.json"
XMPD_SETTINGS_PATH="./settings.toml"
XMPD_CACHE_PATH="./cache"

37
.gitea/workflows/ci.yml Normal file
View File

@ -0,0 +1,37 @@
on: [push, pull_request]
name: Continuous integration
jobs:
#check:
# name: Check
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions-rust-lang/setup-rust-toolchain@v1
# - run: cargo check
#test:
# name: Test Suite
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions-rust-lang/setup-rust-toolchain@v1
# - run: cargo test
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: rustup component add clippy
- run: cargo clippy
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo build

8
.gitignore vendored
View File

@ -1,4 +1,4 @@
/target/
/cache/
settings.toml
valgrind.log
/out
/target
/config.json
/manifest.json

2092
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,50 +1,32 @@
[workspace]
resolver="2"
members=[
"xmpd-core",
"xmpd-manifest",
"xmpd-gui",
"xmpd-cliargs",
"xmpd-cache",
"xmpd-settings",
"xmpd-tooling",
"xmpd-player",
# "xmpd-tui"
]
[package]
name = "xmpd"
version = "0.1.0"
edition = "2021"
[workspace.package]
version="2.0.0"
repository="https://git.mcorangehq.xyz/XOR64/xmpd/"
license="GPL-3.0"
authors=[
"MCorange <mcorange@mcorangehq.xyz>",
"xomf <xomf@the-atf-shot-my.dog>"
]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace.dependencies]
[dependencies]
anstyle = "1.0.6"
anyhow = "1.0.81"
camino = { version="1.1.6", features = ["serde1"] }
camino = "1.1.6"
clap = { version = "4.5.4", features = ["derive"] }
eframe = "0.27.2"
egui = { version = "0.27.2", features = ["color-hex", "serde"] }
egui = { version = "0.27.2", features = ["color-hex"] }
egui_extras = { version = "0.27.2", features = ["all_loaders"] }
env_logger = "0.11.3"
futures = "0.3.30"
html-escape = "0.2.13"
lazy_static = "1.4.0"
libc = "0.2.153"
log = "0.4.21"
# notify-rust = "4.11.3"
# open = "5.3.0"
notify-rust = "4.11.3"
open = "5.3.0"
regex = "1.11.0"
reqwest = { version = "0.12.3", features = ["blocking", "h2", "http2", "rustls-tls"], default-features = false }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
url = { version = "2.5.0", features = ["serde"] }
uuid = { version = "1.11.0", features = ["serde", "v4"] }
# serde_traitobject = "0.2.8"
tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread", "process", "sync"] }
url = "2.5.0"
windows = { version = "0.56.0", features = ["Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_Console"] }
# zip-extensions = "0.6.20"
dirs="5.0.1"
winresource = "0.1.17"
toml = "0.8.19"
rfd = "0.15.1"
rodio = { version = "0.20.1", features = ["symphonia-all"] }
image = "0.25.5"
zip-extensions = "0.6.2"

88
DEV.md
View File

@ -1,5 +1,85 @@
[ ] listen along feature using ws and or p2p, downloading music when connectedd if you dont have it, matched by either the url, or a global id set by server
[ ] Internationalisation
[ ] Music Player
[ ] Playlist exporting to folder, zip, tar balls, etc
# Developer notes
## TODO'S
Todo types:
[FEAT] \[loc\](/src/...) - Feature, mandatory location
[BUG] \[loc\](/src/...) - Bugfix, mandatory location
[GIT] \[loc\](/src/...) - Git related feature, optional location
Todos that have been merged have to add `**DONE**` prefix to the type
### #0
**DONE** ~~[FEAT] - [side_nav](/src/ui/gui/components/mod.rs)
Add dropdown menu for `side_nav` playlist~~
### #1
[FEAT] - [gui](/src/ui/gui/)
Move theme selection to a settings panel
### #2
[FEAT] - [gui](/src/ui/gui/)
Better styling
### #3
[FEAT] - [gui](/src/ui/gui/)
Add music player footer
### #4
[FEAT] - [gui](/src/ui/gui/components/song_list/mod.rs)
Add numbers to `song_list` table
### #5
[FEAT] - [NEW](/src/)
Add music player logic
### #6
[FEAT] - [manifest](/src/manifest/mod.rs)
Add support for images by possibly storing the images in json or custom format
### #7
[FEAT] - [*global*](/src/)
Transition application into a globally installed application by default from a
standalone one, moving default paths and using [#10](#10):
| Type | Unix path | Windows path |
|--------------|--------------------------------|--------------------------------|
| config | `~/.config/mcmg/config.json` | `%AppData%/mcmg/config.json` |
| manifest | `~/.config/mcmg/manifest.json` | `%AppData%/mcmg/manifest.json` |
| music-output | `~/Music/mcmg/*` | `%userprofile%/Music/mcmg/*` |
### #8
[FEAT] - [cli](/src/ui/cli/mod.rs)
add missing commands that are available via gui
- Downloading single songs, from the manifest and standalone as an utility
- removing playlists, single songs
### #9
[BUG] - [utils](/src/util.rs)
Fix `isatty` not working correctly on windows
### #10
[FEAT] - [utils](/src/util.rs)
Add an utility to detect if this is ran as a standalone application
### #11
[FEAT] - [downloader](/src/downloader.rs)
Refractor downloader for better readability and usage
### #12
[GIT]
Add ci that runs clippy and builds in release mode
### #13
[FEAT] - [assets](/assets/)
Make new icons for the app, preferably svg, except the app icon must be both svg and png
### #14
[FEAT] - [manifest](/src/manifest/) [downloader](/src/downloader.rs)
Add custom type for downloading, one for simple http downloads, and archived ones (zip, 7z, etc)
### #15
[FEAT] - [dependencies](/Cargo.toml)
Clean up dependencies, remove unneeded features for executable size
### #16
[FEAT] - [song_list](/src/ui/gui/components/song_list/mod.rs)
Add a checkmark or an X depending on if the song is downloaded to disk

675
LICENSE.md Normal file
View File

@ -0,0 +1,675 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path shape-rendering="crispEdges" d="M120-240v-80h720v80H120Zm0-200v-80h720v80H120Zm0-200v-80h720v80H120Z"/></svg>

Before

Width:  |  Height:  |  Size: 223 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z"/></svg>

Before

Width:  |  Height:  |  Size: 179 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M256-213.85 213.85-256l224-224-224-224L256-746.15l224 224 224-224L746.15-704l-224 224 224 224L704-213.85l-224-224-224 224Z"/></svg>

Before

Width:  |  Height:  |  Size: 247 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M480-320 280-520l56-58 104 104v-326h80v326l104-104 56 58-200 200ZM240-160q-33 0-56.5-23.5T160-240v-120h80v120h480v-120h80v120q0 33-23.5 56.5T720-160H240Z"/></svg>

Before

Width:  |  Height:  |  Size: 279 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm-40-160h80v-240h-80v240Zm40 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>

Before

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 -960 960 960" width="16px" fill="#FFFFFF"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>

Before

Width:  |  Height:  |  Size: 536 B

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4 15H2V1H4L10 7V1H14V15H10V9L4 15Z" fill="#FFFFFF"/>
</svg>

Before

Width:  |  Height:  |  Size: 295 B

View File

@ -1,56 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="32"
height="32"
viewBox="0 0 32 32"
version="1.1"
id="svg1"
sodipodi:docname="pause2.svg"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#ffffff"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
inkscape:zoom="18.296388"
inkscape:cx="20.222571"
inkscape:cy="14.046488"
inkscape:window-width="1898"
inkscape:window-height="1037"
inkscape:window-x="10"
inkscape:window-y="10"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#ffffff;stroke-width:1.35128"
id="rect1"
width="9.1821404"
height="31.973524"
x="0.054655612"
y="0.1093111" />
<rect
style="fill:#ffffff;stroke-width:1.35128"
id="rect1-5"
width="9.1821404"
height="31.973524"
x="22.809692"
y="0.091137752" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -1,59 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="32"
height="32"
viewBox="0 0 32 32"
version="1.1"
id="svg1"
sodipodi:docname="play2.svg"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#ffffff"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#FFFFFF"
inkscape:document-units="px"
inkscape:zoom="18.296388"
inkscape:cx="20.222571"
inkscape:cy="14.046488"
inkscape:window-width="1898"
inkscape:window-height="1037"
inkscape:window-x="10"
inkscape:window-y="10"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
sodipodi:type="star"
style="fill:#ffffff"
id="path1"
inkscape:flatsided="false"
sodipodi:sides="3"
sodipodi:cx="1.004831"
sodipodi:cy="6.8019323"
sodipodi:r1="22.598255"
sodipodi:r2="11.299128"
sodipodi:arg1="1.0471976"
sodipodi:arg2="2.0943951"
inkscape:rounded="0"
inkscape:randomized="0"
d="M 12.303958,26.372596 -4.6447328,16.587264 -21.593424,6.8019312 -4.6447329,-2.9833992 12.303959,-12.76873 l 0,19.5706623 z"
inkscape:transform-center-x="-5.3338952"
transform="matrix(-0.94412506,0,0,0.81752476,11.623548,10.454857)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
height="24px"
viewBox="0 -960 960 960"
width="24px"
fill="#FFFFFF"
version="1.1"
id="svg1"
sodipodi:docname="plus.svg"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1" />
<sodipodi:namedview
id="namedview1"
pagecolor="#000000"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:zoom="45.254834"
inkscape:cx="7.4025241"
inkscape:cy="12.396466"
inkscape:window-width="1898"
inkscape:window-height="1037"
inkscape:window-x="10"
inkscape:window-y="10"
inkscape:window-maximized="1"
inkscape:current-layer="svg1" />
<path
shape-rendering="crispEdges"
d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z"
id="path1" />
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 1H6V7L12 1H14V15H12L6 9V15H2V1Z" fill="#FFFFFF"/>
</svg>

Before

Width:  |  Height:  |  Size: 294 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M320-320h320v-320H320v320ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>

Before

Width:  |  Height:  |  Size: 436 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="m40-120 440-760 440 760H40Zm138-80h604L480-720 178-200Zm302-40q17 0 28.5-11.5T520-280q0-17-11.5-28.5T480-320q-17 0-28.5 11.5T440-280q0 17 11.5 28.5T480-240Zm-40-120h80v-200h-80v200Zm40-100Z"/></svg>

Before

Width:  |  Height:  |  Size: 315 B

4
manifest.default.json Normal file
View File

@ -0,0 +1,4 @@
{
"format": "m4a",
"genres": {}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,2 @@
[toolchain]
channel="nightly"

18
scripts/build-release.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/bash
if [[ -z "$1" ]]; then
echo "Please supply a version: 0.0.0[a | b | rc-0]"
exit
fi
set -e
cargo build --release --target x86_64-pc-windows-gnu
cargo build --release --target x86_64-unknown-linux-gnu
cargo build --release --target aarch64-unknown-linux-gnu
strip --strip-unneeded ./target/x86_64-pc-windows-gnu/release/xmpd.exe -o ./target/xmpd_win32.exe
strip --strip-unneeded ./target/x86_64-unknown-linux-gnu/release/xmpd -o ./target/xmpd_linux_x86_64
aarch64-linux-gnu-strip --strip-unneeded ./target/aarch64-unknown-linux-gnu/release/xmpd -o ./target/xmpd_linux_aarch64
cp ./scripts/setup-template.sh "./target/xmpd-setup-$1.sh"
cp ./scripts/setup-template.ps1 "./target/xmpd-setup-$1.ps1"

View File

@ -1,52 +0,0 @@
"""
Converts legacy manifest to v1 json
"""
import uuid
import json
import sys
def main(inp: str, out: str):
manifest = {
"songs": {},
"playlists": {}
}
with open(inp, "r", encoding="utf-8") as f:
data = json.load(f)
_format = data["format"] # unused
for pname in data["playlists"]:
pid = str(uuid.uuid4())
manifest["playlists"][pid] = {
"name": pname,
"author": "Unknown",
"songs": []
}
for sname in data["playlists"][pname]["songs"]:
asn = sname.split(" - ", 2)
author = None
name = None
if len(asn) < 2:
author = "Unknown"
name = sname
else:
author = asn[0]
name = asn[1]
song = data["playlists"][pname]["songs"][sname]
sid = str(uuid.uuid4())
manifest["playlists"][pid]["songs"].append(sid)
manifest["songs"][sid] = {
"name": name,
"author": author,
"url": song["url"],
"source_type": song["typ"]
}
converted = json.dumps(manifest)
with open(out, "w", encoding="utf-8") as f:
f.write(converted)
if __name__ == "__main__":
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} [in] [out]")
sys.exit(1)
main(sys.argv[1], sys.argv[2])

View File

@ -0,0 +1,23 @@
$MyInvocation.MyCommand.Name -match '([0-9]+\.[0-9]+\.[0-9]+([ab]|(rc[-]*[0-9]*)))'
$Ver = $Matches[1]
if (-not (Get-Command ffmpeg -ErrorAction SilentlyContinue)) {
winget install Gyan.FFmpeg
}
if (-not (Get-Command "yt-dlp" -ErrorAction SilentlyContinue)) {
winget install "yt-dlp.yt-dlp"
}
if (-not (Get-Command spotdl -ErrorAction SilentlyContinue)) {
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
winget install "Python.Python.3.12"
}
python -m pip install spotdl
}
$url = "https://git.mcorangehq.xyz/XOR64/music/releases/download/$Ver/mcmg_win32.exe"
Invoke-WebRequest -Uri $url -OutFile "mcmg.exe"

42
scripts/setup-template.sh Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/bash
set -e
PROG_VER=$(echo $0 | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+([ab]|(rc[-]*[0-9]*))")
echo $PROG_VER
function cmd_exists() {
if ! command -v $1 &> /dev/null
then
return 1
else
return 0
fi
}
if cmd_exists "pacman"; then
if cmd_exists "yay"; then
yay -Sy --needed ffmpeg yt-dlp spotdl curl
else
sudo pacman -Sy --needed ffmpeg yt-dlp python python-pip python-pipx curl
pipx install spotdl
fi
fi
if cmd_exists "apt"; then
sudo apt-get update
sudo apt-get install python3 python3-pip ffmpeg curl
# updates all python packages, uncomment if you get errors for packages
# pip3 freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U
python3 -m pip install --upgrade pip
python3 -m pip install spotdl
python3 -m pip install yt-dlp
fi
curl "https://git.mcorangehq.xyz/XOR64/music/releases/download/${PROG_VER}/mcmg_linux_x86_64" -o mcmg

48
src/config/cli.rs Normal file
View File

@ -0,0 +1,48 @@
use camino::Utf8PathBuf;
use clap::{Parser, Subcommand};
#[allow(clippy::pedantic)]
#[derive(Debug, Parser, Default, Clone)]
pub struct CliArgs {
/// Show more info
#[arg(long, short)]
pub debug: bool,
/// Path to manifest
#[arg(long, short, default_value_t=Utf8PathBuf::from("./manifest.json"))]
pub manifest: Utf8PathBuf,
/// Output directory
#[arg(long, short, default_value_t=Utf8PathBuf::from("./out"))]
pub output: Utf8PathBuf,
/// Config path
#[arg(long, short, default_value_t=Utf8PathBuf::from("./config.json"))]
pub config: Utf8PathBuf,
#[command(subcommand)]
pub command: Option<CliCommand>,
}
#[allow(clippy::pedantic)]
#[derive(Debug, Subcommand, Clone)]
pub enum CliCommand {
Download,
Add {
#[arg(long, short)]
url: String,
#[arg(long, short)]
name: String,
#[arg(long, short)]
playlist: String
},
AddPlaylist {
#[arg(long, short)]
url: String,
#[arg(long, short)]
name: String
},
Gui
}

125
src/config/mod.rs Normal file
View File

@ -0,0 +1,125 @@
pub mod cli;
use std::path::PathBuf;
use clap::Parser;
use serde::{Deserialize, Serialize};
use anyhow::Result;
use crate::util::{self, isatty};
use self::cli::CliArgs;
// const YTDLP_DL_URL: &'static str = "https://github.com/yt-dlp/yt-dlp/archive/refs/heads/master.zip";
// const SPOTDL_DL_URL: &'static str = "https://github.com/spotDL/spotify-downloader/archive/refs/heads/master.zip";
#[allow(clippy::pedantic)]
#[derive(Debug, Default, Clone)]
pub struct ConfigWrapper {
pub cfg: Config,
pub cli: cli::CliArgs,
pub isatty: bool
}
#[allow(clippy::pedantic)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct Config {
pub ytdlp: ConfigYtdlp,
pub spotdl: ConfigSpotdl,
}
#[allow(clippy::pedantic)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct ConfigYtdlp {
pub path: PathBuf,
}
#[allow(clippy::pedantic)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct ConfigSpotdl {
pub path: PathBuf,
}
impl ConfigWrapper {
#[allow(clippy::field_reassign_with_default)]
pub fn parse() -> Result<Self> {
let mut s = Self::default();
s.cli = cli::CliArgs::parse();
crate::logger::init(s.cli.debug);
s.cfg = Config::parse(&s.cli)?;
s.isatty = isatty();
Ok(s)
}
}
impl Config {
pub fn parse(cli: &CliArgs) -> Result<Self> {
if !cli.config.exists() {
log::info!("Config doesnt exist");
return Self::setup_config(cli);
}
let data = std::fs::read_to_string(&cli.config)?;
let data: Self = serde_json::from_str(&data)?;
Ok(data)
}
fn setup_config(cli: &CliArgs) -> Result<Self> {
let mut s = Self::default();
let mut error = false;
if let Some(p) = util::is_program_in_path("yt-dlp") {
s.ytdlp.path = p;
} else {
error = true;
log::error!("could not find yt-dlp, please install it.");
log::info!(" - With winget (Windows only) (recommended):");
log::info!(" - Most new windows versions have winget installed, if not, instructions here: https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget");
log::info!(" - run `winget install yt-dlp`");
log::info!(" - With chocolatey (Windows only):");
log::info!(" - Make sure you have chocolatey installed - https://chocolatey.org/install");
log::info!(" - run `choco install yt-dlp` as Admin");
log::info!(" - With pip (from python) (Cross platform)");
log::info!(" - Make sure you have python installed");
log::info!(" - pip install yt-dlp");
log::info!(" - Using your distro's package manager (Unix/BSD only) (Not recommended)");
}
if let Some(p) = util::is_program_in_path("spotdl") {
s.spotdl.path = p;
} else {
let res = crate::prompt::yes_no("Spotdl is not installed but if you dont need to download music from spotify you dont need it, skip it?", None);
if res {
s.spotdl.path = PathBuf::from("UNUSED");
} else {
error = true;
log::error!("could not find spotdl, please install it. ");
log::info!(" - With pip (from python) (Cross platform) (recommended)");
log::info!(" - Make sure you have python installed - https://www.python.org/downloads/");
log::info!(" - pip install spotdl");
}
}
if util::is_program_in_path("ffmpeg").is_none() {
error = true;
log::error!("could not find ffmpeg, please install it.");
log::info!(" - With winget (Windows only) (recommended):");
log::info!(" - Most new windows versions have winget installed, if not, instructions here: https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget");
log::info!(" - run `winget install --id=Gyan.FFmpeg -e`");
log::info!(" - With chocolatey (Windows only):");
log::info!(" - Make sure you have chocolatey installed - https://chocolatey.org/install");
log::info!(" - run `choco install ffmpeg` as Admin");
}
if !error {
s.save(cli.config.clone().into_std_path_buf())?;
}
Ok(s)
}
fn save(&self, path: PathBuf) -> anyhow::Result<()> {
let data = serde_json::to_string_pretty(self)?;
std::fs::write(path, data)?;
Ok(())
}
}

15
src/constants.rs Normal file
View File

@ -0,0 +1,15 @@
#[cfg(target_family="windows")]
mod _m {
pub const PATH_VAR_SEP: &str = ";";
pub const EXEC_EXT: &str = "exe";
}
#[cfg(target_family="unix")]
mod _m {
pub const PATH_VAR_SEP: &str = ":";
pub const EXEC_EXT: &str = "";
}
pub use _m::*;

5
src/data.rs Normal file
View File

@ -0,0 +1,5 @@
// pub const APP_ICON: egui::ImageSource = egui::include_image!("../assets/app_icon.png");
pub const APP_ICON_BYTES: &[u8] = include_bytes!("../assets/app_icon.png");
pub const NOTE_ICON: egui::ImageSource = egui::include_image!("../assets/note.svg");
pub const SEARCH_ICON: egui::ImageSource = egui::include_image!("../assets/search.svg");

180
src/downloader.rs Normal file
View File

@ -0,0 +1,180 @@
use std::{collections::HashMap, path::PathBuf, process::Stdio};
use lazy_static::lazy_static;
use log::Level;
use tokio::sync::{Mutex, RwLock};
use crate::{config::ConfigWrapper, manifest::{song::{Song, SongType}, Format, Manifest}};
#[allow(dead_code)]
#[derive(Debug, Clone)]
struct Proc {
url: String,
path: String,
finished: bool
}
lazy_static!(
static ref PROCESSES: Mutex<RwLock<HashMap<usize, Proc>>> = Mutex::new(RwLock::new(HashMap::new()));
);
#[derive(Debug, Default, Clone)]
pub struct Downloader {
count: usize,
nb_initial_song_count: usize,
nb_cache: Vec<(String, String, Song, Format)>
}
impl Downloader {
pub fn new() -> Self {
Self {
..Default::default()
}
}
pub fn get_initial_song_count_nb(&self) -> usize {
self.nb_initial_song_count
}
pub fn get_songs_left_nb(&self) -> usize {
self.nb_cache.len() + crate::process_manager::proc_count()
}
pub fn download_song_nb(&mut self, cfg: &ConfigWrapper, pname: &str, sname: &str, song: &Song, format: &Format) -> anyhow::Result<()> {
self.nb_cache.push((pname.to_string(), sname.to_string(), song.clone(), format.clone()));
self.nb_initial_song_count += 1;
self.download_all_nb_poll(cfg)?;
Ok(())
}
pub fn download_all_nb(&mut self, manifest: &Manifest, cfg: &ConfigWrapper) -> anyhow::Result<Option<usize>> {
for (pname, playlist) in manifest.get_playlists() {
for (sname, song) in playlist.get_songs() {
self.nb_cache.push((pname.clone(), sname.clone(), song.clone(), manifest.get_format().clone()));
}
}
self.nb_initial_song_count = self.nb_cache.len();
self.download_all_nb_poll(cfg)
}
pub fn download_all_nb_poll(&mut self, cfg: &ConfigWrapper) -> anyhow::Result<Option<usize>> {
if !crate::process_manager::is_proc_queue_full(10) {
if let Some((pname, sname, song, format)) = self.nb_cache.pop() {
self.download_song(cfg, &sname, &song, &pname, &format)?;
}
}
if self.get_songs_left_nb() == 0 {
self.nb_initial_song_count = 0;
}
if crate::process_manager::proc_count() == 0 && self.nb_cache.is_empty() {
Ok(None)
} else {
Ok(Some(crate::process_manager::purge_done_procs()))
}
}
pub fn download_all(&mut self, manifest: &Manifest, cfg: &ConfigWrapper) -> anyhow::Result<usize> {
let format = manifest.get_format();
for (name, playlist) in manifest.get_playlists() {
for (song_name, song) in playlist.get_songs() {
self.download_song(cfg, song_name, song, name, format)?;
self.count += crate::process_manager::wait_for_procs_until(10)?;
}
}
self.count += crate::process_manager::wait_for_procs_until(0)?;
Ok(self.count)
}
#[allow(dead_code)]
pub fn download_playlist(&mut self, cfg: &ConfigWrapper, url: &str, pname: &str, format: &Format) -> anyhow::Result<usize> {
self.download_playlist_nb(cfg, url, pname, format)?;
let mut count = 0;
while let Some(c) = self.download_all_nb_poll(cfg)? {
count += c;
}
Ok(count)
}
pub fn download_playlist_nb(&mut self, cfg: &ConfigWrapper, url: &str, pname: &str, format: &Format) -> anyhow::Result<HashMap<String, Song>> {
log::warn!("This automatically assumes its a youtube link as it is currently the only supported playlist source");
let mut cmd = tokio::process::Command::new(&cfg.cfg.ytdlp.path);
cmd.args([
"--flat-playlist",
"--simulate",
"-O", "%(url)s|%(title)s",
url
]);
cmd
.stderr(Stdio::null())
.stdout(Stdio::piped());
let ftr = cmd.output();
let mut ret = HashMap::new();
let out = futures::executor::block_on(ftr)?.stdout;
let out = String::from_utf8(out)?;
for line in out.lines() {
let mut split_text = line.split('|').collect::<Vec<&str>>();
let url = split_text.swap_remove(0).to_string();
let sname = split_text.join("|");
let song = Song::from_url_str(url)?.set_type(SongType::Youtube).clone();
self.nb_cache.push((pname.to_string(), sname.clone(), song.clone(), format.clone()));
ret.insert(sname, song.clone());
}
self.nb_initial_song_count += out.lines().count();
self.download_all_nb_poll(cfg)?;
Ok(ret)
}
pub fn download_song(&self, cfg: &ConfigWrapper, name: &String, song: &Song, playlist: &String, format: &Format) -> anyhow::Result<()> {
let dl_dir = format!("{}/{playlist}", cfg.cli.output);
let dl_file = format!("{dl_dir}/{}.{}", name, &format);
log::debug!("Checking: {dl_file}");
if PathBuf::from(&dl_file).exists() {
log::debug!("File {dl_file} exists, skipping");
return Ok(())
}
log::debug!("File {dl_file} doesnt exist, downloading");
let mut cmd = match song.get_type() {
SongType::Youtube | SongType::Soundcloud=> {
log::debug!("Song {} is from youtube or sondclound", song.get_url_str());
let mut cmd = tokio::process::Command::new(&cfg.cfg.ytdlp.path);
cmd.args([
"-x",
"--audio-format",
&format.to_string(),
"-o",
dl_file.as_str(),
song.get_url_str().as_str()
]);
cmd
}
SongType::Spotify => {
let mut cmd = tokio::process::Command::new(&cfg.cfg.spotdl.path);
cmd.args([
"--format",
&format.to_string(),
"--output",
dl_dir.as_str(),
song.get_url_str().as_str()
]);
cmd
}
};
if log::max_level() < Level::Debug {
cmd.stdout(Stdio::null()).stderr(Stdio::null());
};
crate::process_manager::add_proc(cmd, format!("Downloaded {dl_file}"))?;
Ok(())
}
}

14
src/logger.rs Normal file
View File

@ -0,0 +1,14 @@
use log::LevelFilter;
pub fn init(debug: bool) {
let level = if debug {
LevelFilter::Debug
} else {
LevelFilter::Info
};
env_logger::builder()
.format_timestamp(None)
.filter_level(level)
.init();
}

35
src/main.rs Normal file
View File

@ -0,0 +1,35 @@
#![feature(downcast_unchecked)]
#![feature(async_closure)]
use config::ConfigWrapper;
mod manifest;
mod logger;
mod downloader;
mod util;
mod config;
mod constants;
mod process_manager;
mod ui;
mod prompt;
mod data;
#[tokio::main]
async fn main() {
let Ok(cfg) = ConfigWrapper::parse() else {
return;
};
let mut manifest = match manifest::Manifest::load_new(&cfg.cli.manifest.clone().into_std_path_buf()) {
Ok(m) => m,
Err(e) => {
log::error!("Failed to parse manifest file {}: {e}", cfg.cli.manifest);
return;
}
};
let _ = ui::cli::command_run(&cfg, &mut manifest);
}

144
src/manifest/mod.rs Normal file
View File

@ -0,0 +1,144 @@
// pub mod v1;
pub mod song;
pub mod playlist;
use playlist::Playlist;
use song::Song;
use std::{collections::HashMap, fmt::{Debug, Display}, path::PathBuf};
use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
const DEFAULT_MANIFEST: &str = include_str!("../../manifest.default.json");
#[allow(non_camel_case_types)]
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub enum Format {
#[default]
m4a,
aac,
flac,
mp3,
vaw,
}
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Manifest {
#[serde(skip)]
path: PathBuf,
format: Format,
playlists: HashMap<String, playlist::Playlist>,
}
#[allow(dead_code)]
impl Manifest {
pub fn get_format(&self) -> &Format {
&self.format
}
pub fn add_song(&mut self, playlist_name: &String, name: String, song: Song) -> Option<Song> {
self.get_playlist_mut(playlist_name)?.add_song(name, song)
}
pub fn get_song(&self, playlist_name: &String, name: &String) -> Option<&Song> {
self.get_playlist(playlist_name)?.get_song(name)
}
pub fn get_song_mut(&mut self, playlist_name: &String, name: &String) -> Option<&mut Song> {
self.get_playlist_mut(playlist_name)?.get_song_mut(name)
}
pub fn add_playlist(&mut self, playlist_name: String) {
self.playlists.insert(playlist_name, Playlist::default());
}
pub fn get_playlist(&self, playlist_name: &String) -> Option<&playlist::Playlist> {
self.playlists.get(playlist_name)
}
pub fn get_playlist_mut(&mut self, playlist_name: &String) -> Option<&mut playlist::Playlist> {
self.playlists.get_mut(playlist_name)
}
pub fn get_playlists(&self) -> &HashMap<String, playlist::Playlist> {
&self.playlists
}
pub fn get_playlists_mut(&mut self) -> &mut HashMap<String, playlist::Playlist> {
&mut self.playlists
}
pub fn remove_playlist(&mut self, playlist_name: &String) -> Option<playlist::Playlist> {
self.playlists.remove(playlist_name)
}
pub fn remove_song(&mut self, playlist_name: &String, song_name: &String) -> Option<Song> {
self.get_playlist_mut(playlist_name)?.remove_song(song_name)
}
pub fn get_song_count(&self) -> usize {
let mut count = 0;
for v in self.playlists.values() {
count += v.len();
}
count
}
pub fn load(&mut self, p: Option<&PathBuf>) -> Result<()> {
let path = p.unwrap_or(&self.path);
log::debug!("Path: {path:?}");
let data = std::fs::read_to_string(path)?;
let s: Self = serde_json::from_str(data.as_str())?;
self.playlists = s.playlists;
self.format = s.format;
Ok(())
}
pub fn save(&self, p: Option<&PathBuf>) -> Result<()> {
let path = p.unwrap_or(&self.path);
log::debug!("Path: {path:?}");
let data = serde_json::to_string_pretty(self)?;
std::fs::write(path, data)?;
Ok(())
}
pub fn load_new(p: &PathBuf) -> Result<Self> {
if !p.exists() {
std::fs::write(p, DEFAULT_MANIFEST)?;
}
let mut s = Self::default();
log::debug!("Path: {p:?}");
s.path.clone_from(p);
s.load(Some(p))?;
Ok(s)
}
}
impl TryFrom<String> for Format {
type Error = anyhow::Error;
fn try_from(value: String) -> std::prelude::v1::Result<Self, Self::Error> {
match value.as_str() {
"m4a" => Ok(Self::m4a),
"aac" => Ok(Self::aac),
"flac" => Ok(Self::flac),
"mp3" => Ok(Self::mp3),
"vaw" => Ok(Self::vaw),
v => bail!("Unknown format {v}")
}
}
}
impl Display for Format {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Format::m4a => write!(f, "m4a")?,
Format::aac => write!(f, "aac")?,
Format::flac => write!(f, "flac")?,
Format::mp3 => write!(f, "mp3")?,
Format::vaw => write!(f, "vaw")?,
}
Ok(())
}
}

54
src/manifest/playlist.rs Normal file
View File

@ -0,0 +1,54 @@
use egui::ahash::HashMap;
use serde::{Deserialize, Serialize};
use super::song::Song;
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Playlist {
songs: HashMap<String, Song>
}
impl Playlist {
pub fn add_song(&mut self, name: String, song: Song) -> Option<Song> {
self.songs.insert(name, song)
}
pub fn remove_song(&mut self, name: &String) -> Option<Song> {
self.songs.remove(name)
}
pub fn get_song(&self, name: &String) -> Option<&Song> {
self.songs.get(name)
}
pub fn get_songs(&self) -> &HashMap<String, Song> {
&self.songs
}
#[allow(dead_code)]
pub fn get_songs_mut(&mut self) -> &mut HashMap<String, Song> {
&mut self.songs
}
pub fn get_song_mut(&mut self, name: &String) -> Option<&mut Song> {
self.songs.get_mut(name)
}
pub fn len(&self) -> usize {
self.songs.len()
}
}
impl IntoIterator for Playlist {
type Item = (String, Song);
type IntoIter = std::collections::hash_map::IntoIter<String, Song>;
fn into_iter(self) -> Self::IntoIter {
self.songs.into_iter()
}
}

84
src/manifest/song.rs Normal file
View File

@ -0,0 +1,84 @@
use std::{fmt::Display, str::FromStr};
use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
#[allow(clippy::pedantic)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Default)]
pub enum SongType {
#[default]
Youtube,
Spotify,
Soundcloud,
}
impl Display for SongType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Soundcloud => write!(f, "SoundCloud")?,
Self::Spotify => write!(f, "Spotify")?,
Self::Youtube => write!(f, "YouTube")?,
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Song {
url: String,
typ: SongType
}
#[allow(dead_code)]
impl Song {
#[allow(clippy::needless_pass_by_value)]
pub fn from_url_str<S: ToString>(url: S) -> Result<Self> {
Self::from_url(url::Url::from_str(&url.to_string())?)
}
pub fn from_url(url: url::Url) -> Result<Self> {
Ok(Self {
url: url.to_string(),
typ: url.try_into()?,
})
}
pub fn set_type(&mut self, typ: SongType) -> &mut Self {
self.typ = typ;
self
}
pub fn get_url(&self) -> Result<url::Url> {
Ok(url::Url::from_str(&self.url)?)
}
pub fn get_url_str(&self) -> &String {
&self.url
}
pub fn get_url_str_mut(&mut self) -> &mut String {
&mut self.url
}
pub fn get_type(&self) -> &SongType {
&self.typ
}
pub fn get_type_mut(&mut self) -> &mut SongType {
&mut self.typ
}
}
impl TryFrom<url::Url> for SongType {
type Error = anyhow::Error;
fn try_from(url: url::Url) -> std::prelude::v1::Result<Self, Self::Error> {
let Some(host) = url.host_str() else {
bail!("{url} does not have a host");
};
match host {
"youtube.com" | "youtu.be" | "www.youtube.com" => Ok(Self::Youtube),
"open.spotify.com" => Ok(Self::Spotify),
"SOUNDCLOUD" => Ok(Self::Soundcloud), // TODO: Fix this
_ => bail!("Unknwon host {url}")
}
}
}

78
src/process_manager.rs Normal file
View File

@ -0,0 +1,78 @@
use std::{collections::HashMap, sync::{atomic::{AtomicUsize, Ordering}, Mutex, RwLock}};
use tokio::process::Command;
#[allow(dead_code)]
#[derive(Debug, Clone)]
struct Proc {
msg: String,
finished: bool
}
lazy_static::lazy_static!(
static ref PROCESSES: Mutex<RwLock<HashMap<usize, Proc>>> = Mutex::new(RwLock::new(HashMap::new()));
);
static PROC_INC: AtomicUsize = AtomicUsize::new(0);
pub fn add_proc(mut cmd: Command, msg: String) -> anyhow::Result<()> {
let mut proc = cmd.spawn()?;
let id = PROC_INC.fetch_add(1, Ordering::AcqRel);
tokio::spawn(async move {
let id = id;
proc.wait().await
.expect("child process encountered an error");
PROCESSES.lock().unwrap().write().unwrap().get_mut(&id).unwrap().finished = true;
});
PROCESSES.lock().unwrap().write().unwrap().insert(id, Proc {
finished: false,
msg,
});
Ok(())
}
pub fn proc_count() -> usize {
PROCESSES.lock().unwrap().read().unwrap().len()
}
pub fn is_proc_queue_full(max: usize) -> bool {
let proc_cnt = PROCESSES.lock().unwrap().read().unwrap().len();
proc_cnt >= max
}
pub fn purge_done_procs() -> usize {
let mut finish_count = 0;
let procs = {
PROCESSES.lock().unwrap().read().unwrap().clone()
};
for (idx, proc) in procs {
if proc.finished {
{
PROCESSES.lock().unwrap().write().unwrap().remove(&idx);
}
log::info!("{}", proc.msg);
finish_count += 1;
}
}
finish_count
}
/// Waits for processes to finish until the proc count is lower or equal to `max`
pub fn wait_for_procs_until(max: usize) -> anyhow::Result<usize> {
// NOTE: This looks really fucked because i dont want to deadlock the processes so i lock PROCESSES for as little as possible
// NOTE: So its also kinda really slow
let mut finish_count = 0;
loop {
if !is_proc_queue_full(max) {
return Ok(finish_count);
}
finish_count += purge_done_procs();
}
}

47
src/prompt.rs Normal file
View File

@ -0,0 +1,47 @@
use std::io::Write;
pub fn yes_no(p: &str, default: Option<bool>) -> bool {
if default == Some(true) {
println!("{c}prompt{r}: {p} (Y/n)",
c=anstyle::AnsiColor::Cyan.render_fg(),
r=anstyle::Reset.render()
);
} else if default == Some(false) {
println!("{c}prompt{r}: {p} (y/N)",
c=anstyle::AnsiColor::Cyan.render_fg(),
r=anstyle::Reset.render()
);
} else {
println!("{c}prompt{r}: {p} (y/n)",
c=anstyle::AnsiColor::Cyan.render_fg(),
r=anstyle::Reset.render()
);
}
print!("> ");
// I dont care if it fails
let _ = std::io::stdout().flush();
let mut buf = String::new();
let _ = std::io::stdin().read_line(&mut buf);
if buf.trim().is_empty() {
match default {
Some(true) => return true,
Some(false) => return false,
None => {
return yes_no(p, default);
}
}
}
match buf.to_lowercase().trim() {
"y" => true,
"n" => false,
c => {
log::error!("'{c}' is invalid, type y (yes) or n (no)");
yes_no(p, default)
}
}
}

55
src/ui/cli/add.rs Normal file
View File

@ -0,0 +1,55 @@
use std::str::FromStr;
use anyhow::bail;
use crate::{config::ConfigWrapper, downloader::Downloader, manifest::{song::Song, Manifest}, util::is_supported_host};
pub fn song(cfg: &ConfigWrapper, manifest: &mut Manifest, downloader: &mut Downloader, url: &str, name: &String, playlist: &String) -> anyhow::Result<()> {
let mut playlists = manifest.get_playlists().keys().cloned().collect::<Vec<String>>();
playlists.sort();
if !is_supported_host(&url::Url::from_str(url)?) {
log::error!("Invalid or unsupported host name");
return Ok(());
}
let song = Song::from_url_str(url.to_string())?;
manifest.add_song(playlist, name.clone(), song.clone());
manifest.save(None)?;
let should_download = crate::prompt::yes_no("Download song now?", Some(false));
if should_download {
downloader.download_song(cfg, name, &song, playlist, manifest.get_format())?;
crate::process_manager::wait_for_procs_until(0)?;
}
Ok(())
}
pub fn playlist(cfg: &ConfigWrapper, manifest: &mut Manifest, downloader: &mut Downloader, url: &str, name: &String) -> anyhow::Result<()> {
let songs = downloader.download_playlist_nb(cfg, url, name, manifest.get_format())?;
if manifest.get_playlist(name).is_some() {
log::error!("Playlist {name} already exists");
bail!("")
}
manifest.add_playlist(name.clone());
let playlist = manifest.get_playlist_mut(name).expect("Unreachable");
for (sname, song) in songs {
playlist.add_song(sname, song);
}
manifest.save(None)?;
while downloader.download_all_nb_poll(cfg)?.is_some() {};
Ok(())
}

46
src/ui/cli/mod.rs Normal file
View File

@ -0,0 +1,46 @@
mod add;
use crate::{config::{cli::CliCommand, ConfigWrapper}, downloader::Downloader, manifest::Manifest, ui::gui};
pub fn command_run(cfg: &ConfigWrapper, manifest: &mut Manifest) -> anyhow::Result<()> {
log::info!("Is in term: {}", cfg.isatty);
//std::fs::write("./isatty", format!("{}\n", cfg.isatty))?;
let mut downloader = Downloader::new();
match (&cfg.cli.command, cfg.isatty) {
(None | Some(CliCommand::Download), true) => {
match downloader.download_all(manifest, cfg) {
Ok(count) => log::info!("Downloaded {count} songs"),
Err(e) => {
log::error!("Failed to download songs: {e}");
return Ok(());
}
}
},
(Some(c), _) => {
match c {
CliCommand::Download => unreachable!(),
CliCommand::AddPlaylist { url, name } => {
if let Err(e) = add::playlist(cfg, manifest, &mut downloader, url, name) {
log::error!("Failed to run 'add-playlist' commmand: {e}");
}
}
CliCommand::Add { url, name, playlist } => {
if let Err(e) = add::song(cfg, manifest, &mut downloader, url, name, playlist) {
log::error!("Failed to run 'add' command: {e}");
}
}
CliCommand::Gui => {
gui::Gui::start(manifest.clone(), downloader, cfg.clone())?;
},
}
}
(None, false) => {
gui::Gui::start(manifest.clone(), downloader, cfg.clone())?;
},
}
Ok(())
}

View File

@ -0,0 +1,24 @@
use super::Gui;
pub mod nav;
pub mod song_list;
pub mod side_nav;
pub mod search_bar;
pub trait Component {
fn ui(gui: &mut Gui, ctx: &egui::Context);
}
pub trait ComponentUi {
fn ui(gui: &mut Gui, ui: &mut egui::Ui);
}
pub trait ComponentUiMut {
fn ui(&mut self, gui: &mut Gui, ui: &mut egui::Ui);
}
pub trait ComponentContextMenu {
type Data;
fn ui(gui: &mut Gui, ui: &mut egui::Ui, data: &Self::Data);
}

View File

@ -0,0 +1,66 @@
use crate::ui::gui::{windows::WindowIndex, Gui};
use super::Component;
pub struct NavBar;
impl Component for NavBar {
fn ui(gui: &mut Gui, ctx: &egui::Context) {
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
// The top panel is often a good place for a menu bar:
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
if ui.button("Source").clicked() {
ctx.open_url(egui::OpenUrl::new_tab("https://git.mcorangehq.xyz/XOR64/music"));
}
if ui.button("Save").clicked() {
if let Err(e) = gui.manifest.save(None) {
log::error!("Failed to save manifest: {e}");
}
}
if ui.button("Quit").clicked() {
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
}
});
ui.menu_button("Song", |ui| {
if ui.button("Add New").clicked() {
gui.windows.open(WindowIndex::SongNew, true);
}
});
ui.menu_button("Playlist", |ui| {
if ui.button("Import").clicked() {
gui.windows.open(WindowIndex::ImportPlaylist, true);
}
});
ui.menu_button("Downloader", |ui| {
if ui.button("Download All").clicked() {
if let Err(e) = gui.downloader.download_all_nb(&gui.manifest, &gui.cfg) {
log::error!("Err: {e}");
}
}
});
ui.add_space(16.0);
ui.with_layout(egui::Layout::bottom_up(egui::Align::RIGHT), |ui| {
ui.horizontal(|ui| {
if gui.downloader.get_songs_left_nb() > 0 {
gui.downloading = true;
ui.label(format!("Downloading: {}/{}", gui.downloader.get_songs_left_nb(), gui.downloader.get_initial_song_count_nb()));
} else if gui.downloading {
let _ = notify_rust::Notification::new()
.summary("Done downloading")
.body("Your music has been downloaded")
.show();
gui.downloading = false;
}
let _ = gui.downloader.download_all_nb_poll(&gui.cfg);
egui::widgets::global_dark_light_mode_buttons(ui);
});
});
});
});
}
}

View File

@ -0,0 +1,53 @@
use egui::Color32;
use super::ComponentUiMut;
#[derive(Debug, Default, Clone)]
pub struct SearchBar {
text: String
}
pub enum SearchType {
Generic,
Song,
Url,
Source,
}
impl SearchBar {
pub fn get_search(&self) -> (SearchType, String) {
if self.text.starts_with("source:") {
(
SearchType::Source,
self.text.strip_prefix("source:").unwrap_or("").to_string().to_lowercase()
)
} else if self.text.starts_with("song:") {
(
SearchType::Song,
self.text.strip_prefix("song:").unwrap_or("").to_string().to_lowercase()
)
} else if self.text.starts_with("url:") {
(
SearchType::Url,
self.text.strip_prefix("url:").unwrap_or("").to_string().to_lowercase()
)
} else {
(
SearchType::Generic,
self.text.clone()
)
}
}
}
impl ComponentUiMut for SearchBar {
fn ui(&mut self, _: &mut crate::ui::gui::Gui, ui: &mut egui::Ui) {
ui.vertical(|ui| {
ui.horizontal(|ui| {
let tint = Color32::from_hex("#333377").unwrap();
ui.add(egui::Image::new(crate::data::SEARCH_ICON).tint(tint));
ui.text_edit_singleline(&mut self.text);
});
});
}
}

View File

@ -0,0 +1,55 @@
use egui::{Color32, RichText};
use crate::ui::gui::{components::ComponentContextMenu, windows::{self, WindowIndex}};
#[derive(Debug)]
pub struct ContextMenu;
impl ComponentContextMenu for ContextMenu {
type Data = String; // Playlist name
fn ui(gui: &mut crate::ui::gui::Gui, ui: &mut egui::Ui, playlist_name: &Self::Data) {
if ui.button("Edit").clicked() {
ui.close_menu();
}
if ui.button("Download all").clicked() {
let Some(playlist) = gui.manifest.get_playlist(playlist_name) else {
gui.throw_error(format!("Playlist not found: {}", playlist_name));
ui.close_menu();
return;
};
for (song_name, song) in playlist.get_songs() {
if let Err(e) = gui.downloader.download_song_nb(&gui.cfg, playlist_name, song_name, song, gui.manifest.get_format()) {
gui.throw_error(format!("Could not download song: {e}"));
ui.close_menu();
return;
}
}
ui.close_menu();
}
if ui.button("Delete from disk").clicked() {
let p = crate::util::get_playlist_path(playlist_name);
if p.exists() {
if let Err(e) = std::fs::remove_dir_all(p) {
gui.throw_error(format!("Failed to delete directory: {e}"));
}
}
ui.close_menu();
}
if ui.button(RichText::new("Delete").color(Color32::RED)).clicked() {
let w = gui.windows.get_window::<windows::confirm::ConfirmW>(WindowIndex::Confirm);
w.set_message(
"side_nav_playlist_manifest_delete",
"This will delete the playlist from the manifest file. This is NOT reversible",
&[playlist_name.clone()]
);
gui.windows.open(WindowIndex::Confirm, true);
ui.close_menu();
}
}
}

View File

@ -0,0 +1,72 @@
use egui::{Color32, Label, RichText, Sense};
use crate::ui::gui::windows::{self, WindowIndex};
use super::{ComponentContextMenu, ComponentUi};
mod context_menu;
pub struct SideNav;
impl ComponentUi for SideNav {
fn ui(gui: &mut crate::ui::gui::Gui, ui: &mut egui::Ui) {
let mut playlist_names = gui.manifest
.get_playlists()
.keys().cloned().collect::<Vec<String>>();
playlist_names.sort_by_key(|name| name.to_lowercase());
ui.with_layout(egui::Layout::top_down(egui::Align::TOP), |ui| {
for pname in playlist_names {
if gui.current_playlist.is_empty() {
gui.current_playlist = pname.to_string();
}
ui.horizontal(|ui| {
let tint = Color32::from_hex("#333377").unwrap();
ui.add(egui::Image::new(crate::data::NOTE_ICON).tint(tint))
.context_menu(|ui| context_menu::ContextMenu::ui(gui, ui, &pname));
ui.horizontal(|ui| {
let text = if gui.current_playlist == *pname {
RichText::new(&pname).color(tint)
} else {
RichText::new(&pname)
};
let button = Label::new(text).sense(Sense::click()).selectable(false);
let button = ui.add(button);
if button.clicked() {
gui.current_playlist = pname.to_string();
}
button.context_menu(|ui| context_menu::ContextMenu::ui(gui, ui, &pname));
});
});
}
});
check_if_needs_delete(gui);
}
// #333377
}
fn check_if_needs_delete(gui: &mut crate::ui::gui::Gui) {
// Check for items that need to be deleted
let (id, resp, data) = gui.windows.get_window::<windows::confirm::ConfirmW>(WindowIndex::Confirm).get_response();
match (id.as_str(), resp) {
("side_nav_playlist_manifest_delete", Some(true)) => {
gui.manifest.remove_playlist(&data[0]);
let _ = gui.manifest.save(None);
gui.windows.get_window::<windows::confirm::ConfirmW>(WindowIndex::Confirm).reset();
}
("side_nav_playlist_manifest_delete", Some(false)) => {
log::debug!("FALSE");
gui.windows.get_window::<windows::confirm::ConfirmW>(WindowIndex::Confirm).reset();
}
_ => ()
}
}

View File

@ -0,0 +1,96 @@
use egui::{Color32, RichText};
use crate::{manifest::song::{Song, SongType}, ui::gui::windows::{self, song_edit::GuiSongEditor, WindowIndex}};
use super::ComponentContextMenu;
pub struct ContextMenu;
pub struct SongInfo {
pname: String,
sname: String,
song: Song,
}
impl SongInfo {
pub fn new(pname: &str, sname: &str, song: &Song) -> Self {
Self {
pname: pname.to_string(),
sname: sname.to_string(),
song: song.clone()
}
}
pub fn playlist_name(&self) -> &String {
&self.pname
}
pub fn song_name(&self) -> &String {
&self.sname
}
pub fn song_url(&self) -> &String {
self.song.get_url_str()
}
pub fn song_type(&self) -> &SongType {
self.song.get_type()
}
pub fn song(&self) -> &Song {
&self.song
}
}
impl ComponentContextMenu for ContextMenu {
type Data = SongInfo;
fn ui(gui: &mut crate::ui::gui::Gui, ui: &mut egui::Ui, data: &Self::Data) {
if ui.button("Edit").clicked() {
let w = gui.windows.get_window::<GuiSongEditor>(WindowIndex::SongEdit);
w.set_active_song(data.playlist_name(), data.song_name(), data.song_url(), data.song_type());
gui.windows.open(WindowIndex::SongEdit, true);
ui.close_menu();
}
if ui.button("Download").clicked() {
if let Err(e) = gui.downloader.download_song_nb(&gui.cfg, data.playlist_name(), data.song_name(), data.song(), gui.manifest.get_format()) {
log::error!("{e}");
gui.throw_error(format!("Failed to download song {}: {e}", data.song_name()));
}
ui.close_menu();
}
if ui.button("Open Source").clicked() {
if let Err(e) = open::that(data.song_url()) {
log::error!("{e}");
gui.throw_error(format!("Failed to open song source: {e}"));
}
ui.close_menu();
}
if ui.button("Play").clicked() {
let p = crate::util::get_song_path(data.playlist_name(), data.song_name(), gui.manifest.get_format());
if !p.exists() {
gui.throw_error("Song does not exist on disk".to_string());
} else if let Err(e) = open::that(p) {
log::error!("{e}");
gui.throw_error(format!("Failed to play song: {e}"));
}
ui.close_menu();
}
if ui.button("Delete from disk").clicked() {
let p = crate::util::get_song_path(data.playlist_name(), data.song_name(), gui.manifest.get_format());
if p.exists() {
if let Err(e) = std::fs::remove_file(p) {
gui.throw_error(format!("Failed to delete file: {e}"));
}
}
ui.close_menu();
}
if ui.button(RichText::new("Delete").color(Color32::RED)).clicked() {
let w = gui.windows.get_window::<windows::confirm::ConfirmW>(WindowIndex::Confirm);
w.set_message(
"song_list_song_manifest_delete",
"This will delete the song from the manifest file. This is NOT reversible",
&[data.playlist_name().clone(), data.song_name().clone()]
);
gui.windows.open(WindowIndex::Confirm, true);
ui.close_menu();
ui.close_menu();
}
}
}

View File

@ -0,0 +1,136 @@
use egui::Color32;
use egui_extras::{Column, TableBuilder};
use crate::{manifest::song::SongType, ui::gui::windows::{self, WindowIndex}};
use super::{search_bar::SearchType, ComponentContextMenu, ComponentUi};
mod context_menu;
#[derive(Debug, Default)]
pub struct SongList;
impl ComponentUi for SongList {
fn ui(gui: &mut crate::ui::gui::Gui, ui: &mut egui::Ui) {
ui.vertical(|ui| {
{
use crate::ui::gui::components::ComponentUiMut;
let mut search = gui.search.clone();
search.ui(gui, ui);
gui.search = search;
}
ui.vertical(|ui| {
let available_height = ui.available_height();
let table = TableBuilder::new(ui)
.striped(true)
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
.resizable(true)
.column(Column::auto())
.column(Column::remainder())
.min_scrolled_height(0.0)
.max_scroll_height(available_height)
.sense(egui::Sense::click());
let playlists = gui.manifest.get_playlists().clone();
let songs = {
let mut songs = Vec::new();
for (pname, p) in playlists {
for (sname, s) in p {
songs.push((pname.clone(), sname, s));
}
}
songs.sort_by_key(|song| song.1.to_lowercase());
songs
};
table.header(20.0, |mut header| {
header.col(|ui| {
ui.strong("Source");
});
header.col(|ui| {
ui.strong("Name");
});
}).body(|mut body| {
for (pname, sname, s) in songs {
if pname != gui.current_playlist {
continue;
}
match gui.search.get_search() {
(SearchType::Generic, filter) if !filter.is_empty() => {
if !pname.to_lowercase().contains(&filter) {
continue;
}
}
(SearchType::Song, filter) if !filter.is_empty() => {
if !sname.to_lowercase().contains(&filter) {
continue;
}
}
(SearchType::Source, filter) if !filter.is_empty() => {
if !s.get_type().to_string().to_lowercase().contains(&filter) {
continue;
}
}
(SearchType::Url, filter) if !filter.is_empty() => {
if !s.get_url_str().contains(&filter) {
continue;
}
}
(SearchType::Source, _) => (),
(SearchType::Song, _) => (),
(SearchType::Generic, _) => (),
(SearchType::Url, _) => (),
}
body.row(18.0, |mut row| {
let song_info = context_menu::SongInfo::new(&pname, &sname, &s);
row.col(|ui| {
let color =
match s.get_type() {
SongType::Youtube => Color32::from_hex("#FF0000").unwrap(),
SongType::Spotify => Color32::from_hex("#1db954").unwrap(),
SongType::Soundcloud => Color32::from_hex("#F26F23").unwrap()
};
ui.colored_label(color, s.get_type().to_string())
.context_menu(|ui| context_menu::ContextMenu::ui(gui, ui, &song_info));
});
row.col(|ui| {
ui.hyperlink_to(sname.clone(), s.get_url_str())
.context_menu(|ui| context_menu::ContextMenu::ui(gui, ui, &song_info));
});
row.response()
.context_menu(|ui| context_menu::ContextMenu::ui(gui, ui, &song_info));
});
}
});
});
});
check_if_needs_delete(gui);
}
}
fn check_if_needs_delete(gui: &mut crate::ui::gui::Gui) {
// Check for items that need to be deleted
let (id, resp, data) = gui.windows.get_window::<windows::confirm::ConfirmW>(WindowIndex::Confirm).get_response();
match (id.as_str(), resp) {
("song_list_song_manifest_delete", Some(true)) => {
gui.manifest.remove_song(&data[0], &data[1]);
let _ = gui.manifest.save(None);
gui.windows.get_window::<windows::confirm::ConfirmW>(WindowIndex::Confirm).reset();
}
("song_list_song_manifest_delete", Some(false)) => {
log::debug!("FALSE");
gui.windows.get_window::<windows::confirm::ConfirmW>(WindowIndex::Confirm).reset();
}
_ => ()
}
}

99
src/ui/gui/mod.rs Normal file
View File

@ -0,0 +1,99 @@
mod windows;
mod components;
use components::{Component, ComponentUi};
use egui_extras::install_image_loaders;
use windows::{State, WindowIndex, WindowManager};
use crate::{config::ConfigWrapper, downloader::Downloader, manifest::Manifest};
#[derive(Debug, Default)]
pub struct Gui {
windows: WindowManager,
manifest: Manifest,
downloader: Downloader,
cfg: ConfigWrapper,
downloading: bool,
search: components::search_bar::SearchBar,
current_playlist: String,
}
impl Gui {
fn new(_: &eframe::CreationContext<'_>, manifest: Manifest, downloader: Downloader, cfg: ConfigWrapper) -> Self {
Self {
manifest,
downloader,
cfg,
windows: windows::WindowManager::new(),
..Default::default()
}
}
pub fn start(manifest: Manifest, downloader: Downloader, cfg: ConfigWrapper) -> anyhow::Result<()> {
let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([400.0, 300.0])
.with_min_inner_size([300.0, 220.0])
.with_icon(
eframe::icon_data::from_png_bytes(crate::data::APP_ICON_BYTES)?,
),
..Default::default()
};
if let Err(e) = eframe::run_native(
"McMG",
native_options,
Box::new(|cc| Box::new(Gui::new(cc, manifest, downloader, cfg))),
) {
log::error!("Failed to create window: {e}");
};
Ok(())
}
pub fn throw_error<S: ToString>(&mut self, text: S) {
let w = self.windows.get_window::<windows::error::GuiError>(WindowIndex::Error);
w.set_error_message(text);
self.windows.open(WindowIndex::Error, true);
}
}
impl eframe::App for Gui {
fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
install_image_loaders(ctx);
{
let mut state = State {
cfg: self.cfg.clone(),
downloader: self.downloader.clone(),
manifest: self.manifest.clone(),
};
self.windows.ui(&mut state, ctx);
self.cfg = state.cfg;
self.downloader = state.downloader;
self.manifest = state.manifest;
}
components::nav::NavBar::ui(self, ctx);
egui::CentralPanel::default().show(ctx, |ui| {
let avail_height = ui.available_height();
// The central panel the region left after adding TopPanel's and SidePanel's
//ui.heading(format!("Songs ({})", self.manifest.get_song_count()));
ui.vertical_centered_justified(|ui| {
ui.with_layout(egui::Layout::top_down_justified(egui::Align::TOP), |ui| {
ui.horizontal(|ui| {
ui.set_height(avail_height);
components::side_nav::SideNav::ui(self, ui);
components::song_list::SongList::ui(self, ui);
});
ui.separator();
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
egui::warn_if_debug_build(ui);
});
});
});
});
// Make sure we dont wait for any updates cause we depend on the gui code for downloads
ctx.request_repaint();
}
}

View File

@ -0,0 +1,57 @@
use egui::{Color32, Label, RichText};
use super::{State, Window};
#[allow(clippy::pedantic)]
#[derive(Debug, Default)]
pub struct ConfirmW {
id: String,
text: String,
response: Option<bool>,
data: Vec<String>
}
impl Window for ConfirmW {
fn ui(&mut self, _: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()> {
let mut should_close = false;
egui::Window::new("Are you sure?").open(open).show(ctx, |ui| {
ui.vertical(|ui| {
ui.label(RichText::new("Are you sure you want to do this?").size(15.0).color(Color32::BLUE));
ui.horizontal(|ui| {
ui.add(Label::new(self.text.clone()).wrap(true));
});
ui.horizontal(|ui| {
if ui.button("Cancel").clicked() {
self.response = Some(false);
should_close = true;
} else if ui.button("Continue").clicked() {
self.response = Some(true);
should_close = true;
}
})
})
});
if should_close {
*open = false;
}
Ok(())
}
}
impl ConfirmW {
pub fn set_message<S: ToString>(&mut self, new_id: S, text: S, data: &[String]) {
self.text = text.to_string();
self.id = new_id.to_string();
self.data = data.to_vec();
}
pub fn get_response(&self) -> (&String, &Option<bool>, &Vec<String>) {
(&self.id, &self.response, &self.data)
}
pub fn reset(&mut self) {
self.id.clear();
self.text.clear();
self.response = None;
}
}

View File

@ -0,0 +1,33 @@
use egui::{Color32, Label, RichText};
use super::{State, Window};
#[allow(clippy::pedantic)]
#[derive(Debug, Default)]
pub struct GuiError {
text: String,
}
impl Window for GuiError {
fn ui(&mut self, _: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()> {
egui::Window::new("ERROR!!!! D:")
.open(open)
.show(ctx, |ui| {
ui.vertical(|ui| {
ui.label(RichText::new("Error:").size(15.0).color(Color32::RED));
ui.horizontal(|ui| {
ui.add(Label::new(self.text.clone()).wrap(true));
})
})
});
Ok(())
}
}
impl GuiError {
pub fn set_error_message<S: ToString>(&mut self, text: S) {
self.text = text.to_string();
}
}

View File

@ -0,0 +1,93 @@
use crate::manifest::song::SongType;
use super::{State, Window};
#[allow(clippy::pedantic)]
#[derive(Debug, Default)]
pub struct GuiImportPlaylist {
ed_type: SongType,
ed_name: String,
ed_url: String,
//urls_to_add: Vec<String>,
// playlist_name: String,
}
impl Window for GuiImportPlaylist {
fn ui(&mut self, state: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()> {
let mut save = false;
egui::Window::new("Import Playlist")
.open(open)
.show(ctx, |ui| {
ui.horizontal(|ui| {
ui.label("Type: ");
egui::ComboBox::from_id_source("new_playlist_window_type")
.selected_text(format!("{:?}", self.ed_type))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.ed_type, SongType::Youtube, "Youtube");
ui.selectable_value(&mut self.ed_type, SongType::Spotify, "Spotify");
// ui.selectable_value(&mut self.ed_type, SongType::Soundcloud, "Soundcloud");
}
);
});
ui.horizontal(|ui| {
ui.label("Name: ");
ui.text_edit_singleline(&mut self.ed_name);
});
ui.horizontal(|ui| {
ui.label("Url: ");
ui.text_edit_singleline(&mut self.ed_url);
});
if ui.button("Import").clicked() {
save = true;
}
});
//if let Some(_) = self.urls_to_add.pop() {
// todo!();
//let client = reqwest::blocking::Client::new();
// let song_name = crate::crawler::spotify::get_song_name(&client, url.clone())?;
//if let Some(playlist) = state.manifest.get_playlist_mut(&self.playlist_name) {
// let mut song = Song::from_url_str(url)?;
// song.set_type(SongType::Spotify);
// playlist.add_song(song_name, song);
//}
//let _ = state.manifest.save(None);
//}
if save {
let name = self.ed_name.clone();
let url = self.ed_url.clone();
if state.manifest.get_playlist(&name).is_some() {
log::error!("Playlist {name} already exists");
}
if self.ed_type == SongType::Spotify {
todo!()
//let client = reqwest::blocking::Client::new();
//self.urls_to_add = crate::crawler::spotify::get_playlist_song_urls(&client, self.ed_url.clone())?;
//self.playlist_name = self.ed_name.clone();
//state.manifest.add_playlist(name.clone());
} else if self.ed_type == SongType::Youtube {
let songs = state.downloader.download_playlist_nb(&state.cfg, &url, &name, state.manifest.get_format()).unwrap();
state.manifest.add_playlist(name.clone());
let playlist = state.manifest.get_playlist_mut(&name).expect("Unreachable");
for (sname, song) in songs {
log::info!("Added: {sname}");
playlist.add_song(sname, song);
}
}
let _ = state.manifest.save(None);
*open = false;
}
Ok(())
}
}

77
src/ui/gui/windows/mod.rs Normal file
View File

@ -0,0 +1,77 @@
use std::collections::HashMap;
use crate::{config::ConfigWrapper, downloader::Downloader, manifest::Manifest};
pub mod song_edit;
pub mod error;
pub mod import_playlist;
pub mod song_new;
pub mod confirm;
pub trait Window: std::fmt::Debug {
fn ui(&mut self, state: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()>;
}
#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
pub enum WindowIndex {
Error,
ImportPlaylist,
SongEdit,
SongNew,
Confirm
}
#[derive(Debug,Default)]
pub struct WindowManager {
opened: HashMap<WindowIndex, bool>,
windows: HashMap<WindowIndex, Box<dyn Window>>
}
pub struct State {
pub downloader: Downloader,
pub manifest: Manifest,
pub cfg: ConfigWrapper,
}
impl WindowManager {
pub fn new() -> Self {
let mut windows: HashMap<WindowIndex, Box<dyn Window>> = HashMap::new();
windows.insert(WindowIndex::Error, Box::<error::GuiError>::default());
windows.insert(WindowIndex::ImportPlaylist, Box::<import_playlist::GuiImportPlaylist>::default());
windows.insert(WindowIndex::SongEdit, Box::<song_edit::GuiSongEditor>::default());
windows.insert(WindowIndex::SongNew, Box::<song_new::GuiNewSong>::default());
windows.insert(WindowIndex::Confirm, Box::<confirm::ConfirmW>::default());
Self {
windows,
..Default::default()
}
}
#[allow(dead_code)]
pub fn is_open(&self, id: WindowIndex) -> bool {
*self.opened.get(&id).unwrap()
}
pub fn open(&mut self, id: WindowIndex, open: bool) {
self.opened.insert(id, open);
}
pub fn ui(&mut self, state: &mut State, ctx: &egui::Context) {
for (id, window) in &mut self.windows {
if !self.opened.contains_key(id) {
self.opened.insert(*id, false);
}
let open = self.opened.get_mut(id).unwrap();
if let Err(e) = window.ui(state, ctx, open) {
log::error!("Window {id:?} errored: {e}");
}
}
}
pub fn get_window<T: Window + 'static>(&mut self, id: WindowIndex) -> &mut Box<T> {
let w = self.windows.get_mut(&id).unwrap();
unsafe {
crate::util::as_any_mut(w).downcast_mut_unchecked()
}
}
}

View File

@ -0,0 +1,108 @@
use anyhow::bail;
use egui::Color32;
use crate::manifest::song::SongType;
use super::{State, Window};
#[derive(Debug, Default)]
pub struct GuiSongEditor {
song: (String, String),
ed_url: String,
ed_name: String,
ed_type: SongType
}
impl Window for GuiSongEditor {
fn ui(&mut self, state: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()> {
let mut save = false;
let (playlist_name, song_name) = self.song.clone();
if playlist_name.is_empty() {
return Ok(());
}
let Some(song) = state.manifest.get_song(&playlist_name, &song_name) else {
bail!("Failed to get song (1)");
};
let song = song.clone();
egui::Window::new("Song editor")
.open(open)
.show(ctx,
|ui| {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.label("[");
ui.hyperlink_to("link", song.get_url().unwrap());
ui.label("] ");
ui.colored_label(Color32::LIGHT_BLUE, &playlist_name);
ui.label(": ");
ui.label(&song_name)
});
ui.horizontal(|ui| {
ui.label("Type: ");
ui.label(song.get_type().to_string());
egui::ComboBox::from_id_source("song_edit_window_type")
.selected_text(format!("{:?}", self.ed_type))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.ed_type, SongType::Youtube, "Youtube");
ui.selectable_value(&mut self.ed_type, SongType::Spotify, "Spotify");
ui.selectable_value(&mut self.ed_type, SongType::Soundcloud, "Soundcloud");
}
);
});
ui.horizontal(|ui| {
ui.label("Name: ");
ui.text_edit_singleline(&mut self.ed_name);
});
ui.horizontal(|ui| {
ui.label("Url: ");
ui.text_edit_singleline(&mut self.ed_url);
});
if ui.button("Save").clicked() {
save = true;
}
});
if save {
let song = {
let Some(song) = state.manifest.get_song_mut(&playlist_name, &song_name) else {
bail!("Failed to get song (2)");
};
song.get_url_str_mut().clone_from(&self.ed_url);
song.get_type_mut().clone_from(&self.ed_type);
song.clone()
};
let Some(playlist) = state.manifest.get_playlist_mut(&playlist_name) else {
bail!("Failed to get playlist");
};
playlist.remove_song(&song_name);
playlist.add_song(self.ed_name.clone(), song.clone());
*open = false;
let _ = state.manifest.save(None);
}
Ok(())
}
}
impl GuiSongEditor {
pub fn set_active_song(&mut self, pname: &str, sname: &str, url: &str, typ: &SongType) {
self.song.0 = pname.to_string();
self.song.1 = sname.to_string();
self.ed_name = sname.to_string();
self.ed_url = url.to_string();
self.ed_type = typ.clone();
}
}

View File

@ -0,0 +1,72 @@
use crate::manifest::song::{Song, SongType};
use super::{State, Window};
#[derive(Debug, Default)]
pub struct GuiNewSong {
typ: SongType,
name: String,
playlist: Option<String>,
url: String,
}
impl Window for GuiNewSong {
fn ui(&mut self, state: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()> {
let mut save = false;
egui::Window::new("New song")
.open(open)
.show(ctx, |ui| {
ui.horizontal(|ui| {
ui.label("Type: ");
egui::ComboBox::from_id_source("new_song_window_type")
.selected_text(format!("{:?}", self.typ))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.typ, SongType::Youtube, "Youtube");
ui.selectable_value(&mut self.typ, SongType::Spotify, "Spotify");
ui.selectable_value(&mut self.typ, SongType::Soundcloud, "Soundcloud");
}
);
});
ui.horizontal(|ui| {
ui.label("Name: ");
ui.text_edit_singleline(&mut self.name);
});
ui.horizontal(|ui| {
ui.label("Playlist: ");
egui::ComboBox::from_id_source("new_song_window_playlist")
.selected_text(self.playlist.clone().unwrap_or_default())
.show_ui(ui, |ui| {
for p in state.manifest.get_playlists().keys() {
ui.selectable_value(&mut self.playlist, Option::Some(p.clone()), p.as_str());
}
}
);
});
ui.horizontal(|ui| {
ui.label("Url: ");
ui.text_edit_singleline(&mut self.url);
});
if ui.button("Save").clicked() {
save = true;
}
});
if save {
let Some(playlist) = state.manifest.get_playlist_mut(&self.playlist.clone().unwrap()) else {
panic!("couldnt find playlist from a preset playlist list????????????");
};
playlist.add_song(
self.name.clone(),
Song::from_url_str(self.url.clone()).unwrap().set_type(self.typ.clone()).clone()
);
let _ = state.manifest.save(None);
*open = false;
}
Ok(())
}
}

2
src/ui/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod gui;
pub mod cli;

81
src/util.rs Normal file
View File

@ -0,0 +1,81 @@
use std::{any::Any, path::PathBuf};
use crate::{constants, manifest::Format};
pub(crate) fn is_supported_host(url: &url::Url) -> bool {
let host = url.host_str();
if host.is_none() {
return false;
}
matches!(host.unwrap(), "youtube.com" | "youtu.be" | "open.spotify.com")
}
pub(crate) fn is_program_in_path(program: &str) -> Option<PathBuf> {
if let Ok(path) = std::env::var("PATH") {
for p in path.split(constants::PATH_VAR_SEP) {
let exec_path = PathBuf::from(p).join(program).with_extension(constants::EXEC_EXT);
if std::fs::metadata(&exec_path).is_ok() {
return Some(exec_path);
}
}
}
None
}
#[cfg(target_family="unix")]
pub(crate) fn isatty() -> bool {
use std::{ffi::c_int, os::fd::AsRawFd};
unsafe {
let fd = std::io::stdin().as_raw_fd();
libc::isatty(fd as c_int) == 1
}
}
#[cfg(target_family="windows")]
pub(crate) fn isatty() -> bool {
unsafe {
use windows::Win32::System::Console;
use Console::{CONSOLE_MODE, STD_OUTPUT_HANDLE};
let Ok(handle) = Console::GetStdHandle(STD_OUTPUT_HANDLE) else {
return false;
};
let mut out = CONSOLE_MODE(0);
let ret = Console::GetConsoleMode(handle, &mut out);
ret.is_ok()
}
}
#[allow(dead_code)]
pub fn as_any_mut<T: Any>(val: &mut T) -> &mut dyn Any {
val as &mut dyn Any
}
pub fn get_song_path/*<P: TryInto<PathBuf>>*/(/*basepath: Option<P>,*/ pname: &String, sname: &String, format: &Format) -> PathBuf {
// let mut path: PathBuf;
/*if let Some(bp) = basepath {
if let Ok(bp) = bp.try_into() {
path = bp;
} else {
path = std::env::current_dir().unwrap_or(PathBuf::new());
}
} else {*/
let mut path = std::env::current_dir().unwrap_or_default();
//}
// TODO: Get this from cfg
path.push("out");
path.push(pname);
path.push(sname);
path.set_extension(format.to_string());
path
}
pub fn get_playlist_path(pname: &String) -> PathBuf {
let mut path = std::env::current_dir().unwrap_or_default();
// TODO: Get this from cfg
path.push("out");
path.push(pname);
path
}

View File

@ -1,31 +0,0 @@
[package]
name = "xmpd-cache"
edition = "2021"
readme="README.md"
authors.workspace = true
version.workspace = true
repository.workspace = true
license.workspace = true
autobins = false
autotests = false
autoexamples = false
[features]
default = []
[lib]
crate-type = ["rlib"]
bench = false
[dependencies]
xmpd-settings.path = "../xmpd-settings"
xmpd-manifest.path = "../xmpd-manifest"
xmpd-cliargs.path = "../xmpd-cliargs"
anyhow.workspace = true
camino.workspace = true
lazy_static.workspace = true
log.workspace = true
uuid.workspace = true
reqwest.workspace = true
url.workspace = true
image.workspace = true

View File

View File

@ -1,133 +0,0 @@
use std::{collections::HashMap, ffi::OsStr, io::{BufReader, Cursor}, path::PathBuf, process::{Command, Stdio}, str::FromStr, sync::{Arc, Mutex, MutexGuard}};
use anyhow::anyhow;
use image::ImageReader;
use xmpd_manifest::song::{IconType, Song, SourceType};
use crate::{downloader::song::SongStatus, DlStatus};
lazy_static::lazy_static!(
static ref ICON_CACHE_DL: Arc<Mutex<IconCacheDl>> = Arc::default();
);
#[derive(Debug, Default, Clone)]
pub struct IconCacheDl {
pub jobs: HashMap<uuid::Uuid, DlStatus>,
pub current_jobs: usize,
}
impl IconCacheDl {
pub fn get() -> crate::Result<MutexGuard<'static, Self>> {
match ICON_CACHE_DL.lock() {
Ok(v) => Ok(v),
Err(e) => anyhow::bail!(format!("{e:?}"))
}
}
pub fn is_job_list_full(&self) -> bool {
self.current_jobs >= 5
}
pub fn download(&mut self, sid: uuid::Uuid, song: Song) -> crate::Result<()> {
match song.icon_type().clone() {
IconType::FromSource => {
let tooling = xmpd_settings::Settings::get()?.tooling.clone();
match song.source_type() {
SourceType::Youtube => {
self.jobs.insert(sid.clone(), DlStatus::Downloading);
let mut path = xmpd_cliargs::CLIARGS.cache_path();
path.push("icons");
path.push(sid.to_string());
let mut cmd = Command::new(tooling.ytdlp_path);
cmd.arg(song.url().to_string());
cmd.arg("-o");
cmd.arg(&path);
cmd.args(["--write-thumbnail", "--skip-download"]);
if xmpd_cliargs::CLIARGS.debug {
cmd.stdout(Stdio::piped());
cmd.stderr(Stdio::piped());
} else {
cmd.stdout(Stdio::null());
cmd.stderr(Stdio::null());
}
let child = cmd.spawn()?;
std::thread::spawn(move || {
if let Ok(output) = child.wait_with_output() {
for line in String::from_utf8(output.stdout).unwrap().lines() {
log::info!("CMD: {}", line);
}
for line in String::from_utf8(output.stderr).unwrap().lines() {
log::error!("CMD: {}", line);
}
}
let old_p = path.with_extension("webp"); // Default for yt-dlp
let new_p = path.with_extension("png"); // Default for all
let old_img = ImageReader::open(&old_p).unwrap().decode().unwrap();
old_img.save(&new_p).unwrap();
std::fs::remove_file(old_p).unwrap();
let mut cache = IconCacheDl::get().unwrap();
cache.jobs.insert(sid, DlStatus::Done(Some(new_p.into())));
});
}
SourceType::Spotify => {
todo!()
}
SourceType::Soundcloud => {
todo!()
}
_ => (),
}
}
IconType::CustomUrl(url) => self.download_custom_url_icon(&sid, &url)?,
IconType::None => ()
}
Ok(())
}
pub fn download_custom_url_icon(&mut self, sid: &uuid::Uuid, url: &url::Url) -> crate::Result<()> {
self.jobs.insert(sid.clone(), DlStatus::Downloading);
let url_p = PathBuf::from_str(url.path())?;
let Some(ext) = url_p.extension() else {
anyhow::bail!("Url without extension, cant continue");
};
let ext = ext.to_string_lossy().to_string();
let mut path = xmpd_cliargs::CLIARGS.cache_path();
path.push("icons");
path.push(sid.to_string());
path.set_extension(ext);
let sid = sid.clone();
let url = url.clone();
std::thread::spawn(move || {
match reqwest::blocking::get(url.clone()) {
Ok(v) => {
match v.bytes() {
Ok(bytes) => {
if let Err(e) = std::fs::write(path, bytes) {
if let Ok(mut cache) = IconCacheDl::get() {
if let Some(job) = cache.jobs.get_mut(&sid) {
*job = DlStatus::Error(file!(), line!() as usize, format!("{e:?}"));
}
}
}
}
Err(e) => {
if let Ok(mut cache) = IconCacheDl::get() {
if let Some(job) = cache.jobs.get_mut(&sid) {
*job = DlStatus::Error(file!(), line!() as usize, format!("{e:?}"));
}
}
}
}
}
Err(e) => {
if let Ok(mut cache) = IconCacheDl::get() {
if let Some(job) = cache.jobs.get_mut(&sid) {
*job = DlStatus::Error(file!(), line!() as usize, format!("{e:?}"));
}
}
}
}
});
Ok(())
}
}

View File

@ -1,4 +0,0 @@
pub mod song;
pub mod icon;
pub mod metadata;

View File

@ -1,137 +0,0 @@
use std::{collections::HashMap, ffi::OsStr, process::{Command, Stdio}, sync::{Arc, Mutex, MutexGuard}};
use xmpd_manifest::song::{Song, SourceType};
lazy_static::lazy_static!(
static ref SONG_CACHE_DL: Arc<Mutex<SongCacheDl>> = Arc::default();
);
#[derive(Debug, Clone, Hash, PartialEq, PartialOrd, Eq, Ord)]
pub enum SongStatus {
Downloading,
Converting,
Done
}
#[derive(Debug, Default, Clone)]
pub struct SongCacheDl {
pub jobs: HashMap<uuid::Uuid, SongStatus>,
pub current_jobs: usize,
}
impl SongCacheDl {
pub fn get() -> crate::Result<MutexGuard<'static, Self>> {
match SONG_CACHE_DL.lock() {
Ok(v) => Ok(v),
Err(e) => anyhow::bail!(format!("{e:?}"))
}
}
pub fn is_job_list_full(&self) -> bool {
self.current_jobs >= 5
}
pub fn download(&mut self, sid: uuid::Uuid, song: Song) -> crate::Result<()> {
self.current_jobs += 1;
let song_format = xmpd_settings::Settings::get().unwrap().tooling.song_format.clone();
let tooling = xmpd_settings::Settings::get()?.tooling.clone();
let mut song_cache_d = xmpd_cliargs::CLIARGS.cache_path();
song_cache_d.push("songs");
match song.source_type() {
SourceType::Youtube |
SourceType::Soundcloud => {
let mut song_p = song_cache_d.clone();
song_p.push(sid.to_string());
let song_p = song_p.with_extension(&song_format);
let mut dl_cmd = Command::new(&tooling.ytdlp_path);
dl_cmd.arg(song.url().as_str());
dl_cmd.args(["-x", "--audio-format", &song_format]);
dl_cmd.arg("-o");
dl_cmd.arg(&song_p);
if xmpd_cliargs::CLIARGS.debug {
dl_cmd.stdout(Stdio::piped());
dl_cmd.stderr(Stdio::piped());
} else {
dl_cmd.stdout(Stdio::null());
dl_cmd.stderr(Stdio::null());
}
let dl_child = dl_cmd.spawn()?;
self.jobs.insert(sid, SongStatus::Downloading);
std::thread::spawn(move || {
if let Ok(output) = dl_child.wait_with_output() {
for line in String::from_utf8(output.stdout).unwrap().lines() {
log::info!("CMD: {}", line);
}
for line in String::from_utf8(output.stderr).unwrap().lines() {
log::error!("CMD: {}", line);
}
}
let mut cache = SONG_CACHE_DL.lock().unwrap();
cache.jobs.insert(sid, SongStatus::Done);
cache.current_jobs -= 1;
});
}
SourceType::Spotify => {
// Spotdl doesnt have webm as a format so its fucking annoying, oh well
let mut song_p = song_cache_d.clone();
song_p.push(sid.to_string());
song_p.push("{output-ext}");
let mut dl_cmd = Command::new(&tooling.spotdl_path);
dl_cmd.arg(song.url().as_str());
dl_cmd.arg("--ffmpeg");
dl_cmd.arg(&tooling.ffmpeg_path);
dl_cmd.args(["--format", &song_format, "--output"]);
dl_cmd.arg(&song_p);
let arg_str = dl_cmd.get_args();
let arg_str: Vec<_> = arg_str.collect();
let arg_str = arg_str.join(OsStr::new(" ")).to_string_lossy().to_string();
log::debug!("spotify cli: {} {}", tooling.spotdl_path, arg_str);
if xmpd_cliargs::CLIARGS.debug {
dl_cmd.stdout(Stdio::piped());
dl_cmd.stderr(Stdio::piped());
} else {
dl_cmd.stdout(Stdio::null());
dl_cmd.stderr(Stdio::null());
}
let child = dl_cmd.spawn()?;
self.jobs.insert(sid, SongStatus::Downloading);
std::thread::spawn(move || {
if let Ok(output) = child.wait_with_output() {
for line in String::from_utf8(output.stdout).unwrap().lines() {
log::info!("CMD: {}", line);
}
for line in String::from_utf8(output.stderr).unwrap().lines() {
log::error!("CMD: {}", line);
}
}
let mut from = song_p.clone();
from.pop();
from.push(format!("{song_format}.{song_format}"));
let mut to = song_p.clone();
to.pop();
to.set_extension(&song_format);
log::debug!("from: {from:?} to: {to:?}");
std::fs::copy(&from, &to).unwrap();
from.pop();
std::fs::remove_dir_all(from).unwrap();
let mut cache = SONG_CACHE_DL.lock().unwrap();
cache.jobs.insert(sid, SongStatus::Done);
cache.current_jobs -= 1;
});
}
SourceType::HttpBare => {
todo!()
}
SourceType::Http7z => {
todo!()
}
SourceType::HttpZip => {
todo!()
}
}
Ok(())
}
}

View File

@ -1,176 +0,0 @@
use std::{collections::HashMap, path::PathBuf, str::FromStr, sync::{mpsc::{self, Receiver, Sender}, Arc, Mutex, MutexGuard}, time::Duration};
use downloader::song::SongStatus;
use xmpd_manifest::song::Song;
pub mod downloader;
type Result<T> = anyhow::Result<T>;
lazy_static::lazy_static!(
static ref CACHE: Arc<Mutex<Cache>> = Arc::new(Mutex::new(Cache::default()));
);
#[derive(Debug, Default)]
pub struct Cache {
cache_dir: camino::Utf8PathBuf,
song_cache: HashMap<uuid::Uuid, DlStatus>,
icon_cache: HashMap<uuid::Uuid, DlStatus>,
song_queue: Vec<(uuid::Uuid, Song)>,
icon_queue: Vec<(uuid::Uuid, Song)>,
//meta_queue: Vec<(uuid::Uuid, Song)>
// TODO: Add Icon, metadata cache
}
#[derive(Debug, Clone)]
pub enum DlStatus {
Done(Option<PathBuf>),
Downloading,
Error(&'static str, usize, String),
}
#[derive(Debug, Clone)]
pub enum Message {
DownloadDone(uuid::Uuid),
Error(&'static str, usize, String)
}
impl Cache {
pub fn get() -> crate::Result<MutexGuard<'static, Self>> {
match CACHE.lock() {
Ok(l) => Ok(l),
Err(e) => Err(anyhow::anyhow!(format!("{e:?}"))),
}
}
pub fn init(&mut self) -> Result<Receiver<Message>> {
let (internal_tx, cache_rx) = mpsc::channel::<Message>();
// let (internal_rx, cache_tx) = mpsc::channel::<Message>();
start_cache_mv_thread(internal_tx);
self.cache_dir = xmpd_cliargs::CLIARGS.cache_path();
{ // Get cached songs
let mut song_cache_dir = self.cache_dir.clone();
std::fs::create_dir_all(&song_cache_dir)?;
song_cache_dir.push("songs");
for file in song_cache_dir.read_dir_utf8()? {
if let Ok(file) = file {
if !file.file_type()?.is_file() {
log::warn!("Non song file in: {}", file.path());
continue;
}
let file_path = file.path();
let file2 = file_path.with_extension("");
if let Some(file_name) = file2.file_name() {
let id = uuid::Uuid::from_str(file_name)?;
log::debug!("Found song {id}");
// TODO: Check if id is in manifest
self.song_cache.insert(id, DlStatus::Done(Some(file_path.into())));
}
}
}
}
{ // Get cached icons
}
{ // Get Cached meta
}
Ok(cache_rx)
}
pub fn download_song_to_cache(&mut self, sid: uuid::Uuid, song: Song) {
self.song_queue.push((sid, song));
self.song_cache.insert(sid, DlStatus::Downloading);
}
pub fn download_icon_to_cache(&mut self, sid: uuid::Uuid, song: Song) {
self.icon_queue.push((sid, song));
self.icon_cache.insert(sid, DlStatus::Downloading);
}
pub fn get_cached_song_status(&mut self, sid: &uuid::Uuid) -> Option<DlStatus> {
let original = self.song_cache.get(sid)?.clone();
Some(original)
}
pub fn get_cached_icon_status(&mut self, sid: &uuid::Uuid) -> Option<DlStatus> {
let original = self.icon_cache.get(sid)?.clone();
Some(original)
}
}
macro_rules! he {
($tx:expr, $val:expr) => {
match $val {
Ok(v) => v,
Err(e) => {
let _ = $tx.send(Message::Error(std::file!(), std::line!() as usize, format!("{e:?}")));
continue;
}
}
};
}
fn start_cache_mv_thread(tx: Sender<Message>) {
std::thread::spawn(move || {
loop {
{
std::thread::sleep(Duration::from_millis(500));
let song_format = he!(tx, xmpd_settings::Settings::get()).tooling.song_format.clone();
let mut done_jobs = Vec::new();
let mut dlc = he!(tx, downloader::song::SongCacheDl::get());
for (sid, status) in &dlc.jobs {
if *status == SongStatus::Done {
let mut cache = he!(tx, CACHE.lock());
let mut song_p = xmpd_cliargs::CLIARGS.cache_path().clone();
song_p.push("songs");
song_p.push(sid.clone().to_string());
let song_p = song_p.with_extension(&song_format);
if song_p.exists() {
let _ = tx.send(Message::DownloadDone(sid.clone()));
cache.song_cache.insert(sid.clone(), DlStatus::Done(Some(song_p.into())));
done_jobs.push(sid.clone());
}
}
}
for sid in done_jobs {
dlc.jobs.remove(&sid);
}
{
let mut done_jobs = Vec::new();
let mut dlc = he!(tx, downloader::icon::IconCacheDl::get());
for (sid, status) in &dlc.jobs {
if let DlStatus::Done(path) = status {
let mut cache = he!(tx, CACHE.lock());
cache.icon_cache.insert(sid.clone(), DlStatus::Done(path.clone()));
done_jobs.push(sid.clone());
}
}
for sid in done_jobs {
dlc.jobs.remove(&sid);
}
}
}
{
let mut cache = he!(tx, Cache::get());
{
let mut dlc = he!(tx, downloader::song::SongCacheDl::get());
if !dlc.is_job_list_full() {
if let Some((sid, song)) = cache.song_queue.pop() {
he!(tx, dlc.download(sid, song));
}
}
}
{
let mut icnc = he!(tx, downloader::icon::IconCacheDl::get());
if !icnc.is_job_list_full() {
if let Some((sid, song)) = cache.icon_queue.pop() {
log::debug!("Downloading {sid:?}");
he!(tx, icnc.download(sid, song));
}
}
}
}
}
});
}

View File

@ -1,24 +0,0 @@
[package]
name = "xmpd-cliargs"
edition = "2021"
readme="README.md"
version.workspace = true
authors.workspace = true
repository.workspace = true
license.workspace = true
autobins = false
autotests = false
autoexamples = false
[features]
default = []
[lib]
crate-type = ["rlib"]
bench = false
[dependencies]
camino.workspace = true
clap.workspace = true
dirs.workspace = true
lazy_static.workspace = true

View File

View File

@ -1,81 +0,0 @@
use std::{path::PathBuf, str::FromStr, sync::Arc};
use camino::Utf8PathBuf;
use clap::Parser;
lazy_static::lazy_static!(
pub static ref CLIARGS: Arc<CliArgs> = Arc::new(CliArgs::parse());
);
#[derive(Debug, clap::Parser)]
pub struct CliArgs {
/// Manifest path
#[arg(long, short, default_value_t=get_default_manifest_path())]
manifest: camino::Utf8PathBuf,
/// settings file path
#[arg(long, short, default_value_t=get_default_settings_path())]
settings: camino::Utf8PathBuf,
/// Cache dir path
#[arg(long, short, default_value_t=get_default_cache_path())]
cache: camino::Utf8PathBuf,
/// Debug mode
#[arg(long, short)]
pub debug: bool,
}
impl CliArgs {
pub fn manifest_path(&self) -> PathBuf {
self.manifest.clone().into_std_path_buf()
}
pub fn settings_path(&self) -> PathBuf {
self.settings.clone().into_std_path_buf()
}
pub fn cache_path(&self) -> Utf8PathBuf {
self.cache.clone()
}
}
#[allow(irrefutable_let_patterns)] // Broken?
fn get_default_settings_path() -> camino::Utf8PathBuf {
if let Ok(p) = std::env::var("XMPD_SETTINGS_PATH") {
if let Ok(p) = camino::Utf8PathBuf::from_str(&p) {
return p;
}
}
if let Some(mut p) = dirs::config_dir() {
p.push("xmpd");
p.push("config.toml");
return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path");
}
unreachable!()
}
#[allow(irrefutable_let_patterns)] // Broken?
fn get_default_manifest_path() -> camino::Utf8PathBuf {
if let Ok(p) = std::env::var("XMPD_MANIFEST_PATH") {
if let Ok(p) = camino::Utf8PathBuf::from_str(&p) {
return p;
}
}
if let Some(mut p) = dirs::config_dir() {
p.push("xmpd");
p.push("manifest.json");
return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path");
}
unreachable!()
}
#[allow(irrefutable_let_patterns)] // Broken?
fn get_default_cache_path() -> camino::Utf8PathBuf {
if let Ok(p) = std::env::var("XMPD_CACHE_PATH") {
if let Ok(p) = camino::Utf8PathBuf::from_str(&p) {
return p;
}
}
if let Some(mut p) = dirs::cache_dir() {
p.push("xmpd");
return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path");
}
unreachable!()
}

View File

@ -1,35 +0,0 @@
[package]
name = "xmpd-core"
edition = "2021"
readme="README.md"
version.workspace = true
authors.workspace = true
repository.workspace = true
license.workspace = true
autobins = false
autotests = false
autoexamples = false
[features]
default=["cli", "gui"]
cli=[]
gui=[]
[[bin]]
name="xmpd"
path="src/main.rs"
[dependencies]
xmpd-cliargs.path="../xmpd-cliargs"
xmpd-gui.path="../xmpd-gui"
xmpd-manifest.path="../xmpd-manifest"
xmpd-settings.path = "../xmpd-settings"
clap.workspace=true
camino.workspace = true
anyhow.workspace = true
log.workspace = true
env_logger.workspace = true
[build-dependencies]
winresource.workspace = true

View File

View File

@ -1,11 +0,0 @@
use winresource::WindowsResource;
fn main() -> std::io::Result<()> {
if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
WindowsResource::new()
// This path can be absolute, or relative to your crate root.
.set_icon("../assets/icon.ico")
.compile()?;
}
Ok(())
}

View File

@ -1,16 +0,0 @@
use log::LevelFilter;
use xmpd_cliargs::CliArgs;
pub fn init(cliargs: &CliArgs) {
let level = if cliargs.debug { LevelFilter::Debug } else { LevelFilter::Info };
env_logger::builder()
.format_timestamp(None)
.filter(Some("xmpd"), level)
.filter(Some("xmpd_cli"), level)
.filter(Some("xmpd_gui"), level)
.filter(Some("xmpd_manifest"), level)
.filter(Some("xmpd_config"), level)
.filter(Some("xmpd_dl"), level)
.init();
}

View File

@ -1,18 +0,0 @@
use std::borrow::BorrowMut;
use clap::Parser;
mod logger;
type Result<T> = anyhow::Result<T>;
fn main() -> Result<()> {
// NOTE: Parses on first load
let cliargs = &xmpd_cliargs::CLIARGS;
logger::init(&cliargs);
log::debug!("Initialising settings");
xmpd_settings::Settings::get()?.load(Some(cliargs.settings_path()))?;
log::debug!("Starting gui");
xmpd_gui::start()?;
Ok(())
}

View File

@ -1,35 +0,0 @@
[package]
name = "xmpd-gui"
edition = "2021"
readme="README.md"
authors.workspace = true
version.workspace = true
repository.workspace = true
license.workspace = true
autobins = false
autotests = false
autoexamples = false
[features]
default = []
[lib]
crate-type = ["rlib"]
bench = false
[dependencies]
xmpd-manifest.path = "../xmpd-manifest"
xmpd-settings.path = "../xmpd-settings"
xmpd-cliargs.path = "../xmpd-cliargs"
xmpd-cache.path = "../xmpd-cache"
xmpd-player.path = "../xmpd-player"
egui.workspace = true
eframe.workspace = true
anyhow.workspace = true
lazy_static.workspace = true
log.workspace = true
egui_extras.workspace = true
uuid.workspace = true
camino.workspace = true
rfd.workspace = true
dirs.workspace = true

View File

View File

@ -1,41 +0,0 @@
use uuid::Uuid;
use crate::{components::{CompGetter, CompUi}, windows::WindowId};
#[derive(Debug, Default)]
pub struct Header {
pub search_text: String,
}
component_register!(Header);
impl CompUi for Header {
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
let theme = xmpd_settings::Settings::get()?.theme.clone();
ui.vertical(|ui| {
ui.horizontal(|ui| {
let search_icon = egui::Image::new(crate::data::SEARCH_ICON)
.fit_to_exact_size(egui::Vec2::new(16.0, 16.0))
.tint(theme.accent_color);
ui.add(search_icon);
{
ui.text_edit_singleline(&mut handle_error_ui!(Header::get()).search_text);
}
});
//ui.with_layout(egui::Layout::top_down(egui::Align::), add_contents)
ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
let add_song = ui.add(
egui::Image::new(crate::data::PLUS_ICON)
.tint(theme.accent_color)
.sense(egui::Sense::click())
.fit_to_exact_size(egui::Vec2::new(16.0, 16.0))
);
if add_song.clicked() {
state.windows.toggle(&WindowId::NewPlaylist, true);
}
});
});
Ok(())
}
}

View File

@ -1,110 +0,0 @@
use egui::{CursorIcon, RichText, Sense, TextBuffer};
use xmpd_manifest::store::BaseStore;
use crate::utils::SearchType;
use super::{CompGetter, CompUi};
pub mod header;
#[derive(Debug, Default)]
pub struct LeftNav {
pub selected_playlist_id: Option<uuid::Uuid>,
}
component_register!(LeftNav);
impl CompUi for LeftNav {
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
let w = ui.available_width();
egui::ScrollArea::vertical()
.id_source("left_nav")
.drag_to_scroll(false)
.show(ui, |ui| {
ui.vertical(|ui| {
let len = state.manifest.store().get_songs().len();
add_playlist_tab(ui, &None, "All Songs", None, len, w);
let mut playlists: Vec<_> = state.manifest.store().get_playlists().into_iter().collect();
playlists.sort_by(|a, b| {
let a = a.1.name().to_lowercase();
let b = b.1.name().to_lowercase();
a.cmp(&b)
});
let search_text = handle_error_ui!(header::Header::get()).search_text.clone();
let (qtyp, qtxt) = crate::utils::SearchType::from_str(&search_text);
for (pid, playlist) in playlists.iter() {
match qtyp {
_ if qtxt.is_empty() => (),
SearchType::Normal if playlist.name().to_lowercase().contains(&qtxt) => (),
SearchType::Author if playlist.author().to_lowercase().contains(&qtxt) => (),
_ => continue
}
add_playlist_tab(ui,
&Some(**pid),
playlist.name(),
Some(playlist.author()),
playlist.songs().len(),
w
);
}
});
});
Ok(())
}
}
fn add_playlist_tab(ui: &mut egui::Ui, pid: &Option<uuid::Uuid>, title: &str, author: Option<&str>, song_count: usize, width: f32) {
if pid.is_some() {
ui.separator();
}
let theme = &handle_error_ui!(xmpd_settings::Settings::get()).theme;
let wdg_rect = ui.horizontal(|ui| {
ui.set_width(width);
ui.add_space(5.0);
ui.add(
egui::Image::new(crate::data::NOTE_ICON)
.tint(theme.accent_color)
.sense(Sense::click())
.fit_to_exact_size(egui::Vec2::new(32.0, 32.0))
);
ui.vertical(|ui| {
{
if handle_error_ui!(LeftNav::get()).selected_playlist_id == *pid {
ui.label(
RichText::new(title)
.size(10.0)
.color(theme.accent_color)
);
} else {
ui.label(
RichText::new(title)
.color(theme.text_color)
.size(10.0)
);
}
}
if let Some(author) = author {
ui.monospace(
RichText::new(format!("By {author}"))
.color(theme.dim_text_color)
.size(8.0)
);
}
ui.monospace(
RichText::new(format!("{song_count} songs"))
.color(theme.dim_text_color)
.size(8.0)
);
});
}).response.rect;
let blob = ui.interact(wdg_rect, format!("left_nav_playlist_{pid:?}").into(), egui::Sense::click());
if blob.clicked() {
handle_error_ui!(LeftNav::get()).selected_playlist_id = pid.clone();
}
if blob.hovered() {
ui.output_mut(|o| o.cursor_icon = CursorIcon::PointingHand);
}
}

View File

@ -1,17 +0,0 @@
use std::sync::MutexGuard;
use crate::GuiState;
pub mod left_nav;
pub mod song_list;
pub mod top_nav;
pub mod player;
pub mod toast;
pub trait CompUi {
fn draw(ui: &mut egui::Ui, state: &mut GuiState) -> crate::Result<()>;
}
pub trait CompGetter {
fn get() -> crate::Result<MutexGuard<'static, Self>>;
}

View File

@ -1,159 +0,0 @@
use egui::{RichText, Sense, Stroke, Vec2};
use xmpd_manifest::store::BaseStore;
use super::{song_list::SongList, CompGetter, CompUi};
#[derive(Debug)]
pub struct Player {
slider_progress: usize,
old_slider_progress: usize,
volume_slider: f64,
}
impl Default for Player {
fn default() -> Self {
Self {
volume_slider: 1.0,
old_slider_progress: 0,
slider_progress: 0
}
}
}
component_register!(Player);
impl CompUi for Player {
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
let theme = xmpd_settings::Settings::get()?.theme.clone();
let full_avail = ui.available_size();
ui.horizontal_centered(|ui| {
ui.add_space(10.0);
let icon = egui::Image::new(crate::data::NOTE_ICON)
.tint(theme.accent_color)
.sense(Sense::click())
.fit_to_exact_size(Vec2::new(32.0, 32.0));
ui.add(icon);
ui.vertical(|ui| {
ui.add_space(5.0);
let sid = &handle_error_ui!(SongList::get()).selected_sid;
if let Some(song) = state.manifest.store().get_song(sid) {
let mut name = song.name().to_string();
if name.len() > 16 {
name = (&name)[..16].to_string();
name.push_str("...");
}
ui.label(
RichText::new(name)
.size(12.0)
);
ui.label(
RichText::new(song.author())
.size(8.0)
.monospace()
);
}
});
ui.vertical_centered_justified(|ui| {
let avail = ui.available_size();
let song_info_w = full_avail.x - avail.x;
ui.add_space(3.0);
ui.horizontal(|ui| {
{
let slider_width = full_avail.x * 0.60;
ui.add_space((((full_avail.x / 2.0) - song_info_w) - slider_width / 2.0).clamp(0.0, f32::MAX));
ui.style_mut().spacing.slider_width = avail.x * 0.75;
let s = Stroke {
color: theme.accent_color,
width: 2.0
};
ui.style_mut().visuals.widgets.inactive.fg_stroke = s;
ui.style_mut().visuals.widgets.active.fg_stroke = s;
ui.style_mut().visuals.widgets.hovered.fg_stroke = s;
let mut slf = handle_error_ui!(Player::get());
ui.add(
egui::Slider::new(&mut slf.slider_progress, 0..=100)
.show_value(false)
);
if slf.slider_progress == slf.old_slider_progress {
slf.slider_progress = (state.player.get_played_f() * 100.0) as usize;
slf.old_slider_progress = slf.slider_progress;
} else {
handle_error_ui!(state.player.seek_to_f(slf.slider_progress as f64 / 100.0 ));
slf.old_slider_progress = slf.slider_progress;
}
let secs_left = state.player.get_ms_left() as f64 / 1000.0;
let h = (secs_left/60.0/60.0).floor();
let m = ((secs_left - h * 60.0)/60.0).floor();
let s = (secs_left - m * 60.0).floor();
ui.label(format!("{h:02}:{m:02}:{s:02}"));
}
});
ui.horizontal(|ui| {
let icon_size = 16.0;
ui.add_space(((full_avail.x / 2.0) - song_info_w) - icon_size * 1.5 - ui.spacing().item_spacing.x);
let pp = if state.player.is_paused() {
crate::data::PLAY_ICON
} else {
crate::data::PAUSE_ICON
};
let prev = egui::Image::new(crate::data::PREV_ICON)
.tint(theme.accent_color)
.sense(Sense::click())
.max_size(Vec2::new(icon_size, icon_size));
let pp = egui::Image::new(pp)
.tint(theme.accent_color)
.sense(Sense::click())
.max_size(Vec2::new(icon_size, icon_size));
let next = egui::Image::new(crate::data::NEXT_ICON)
.tint(theme.accent_color)
.sense(Sense::click())
.max_size(Vec2::new(icon_size, icon_size));
if ui.add(prev).clicked() {
handle_error_ui!(handle_error_ui!(SongList::get()).play_prev(state));
}
if ui.add(pp).clicked() {
if state.player.is_paused() {
state.player.play();
} else {
state.player.pause();
}
}
if ui.add(next).clicked() || state.player.just_stopped() {
handle_error_ui!(handle_error_ui!(SongList::get()).play_next(state));
}
ui.add_space(15.0);
ui.style_mut().spacing.slider_width = avail.x * 0.15;
let s = Stroke {
color: theme.accent_color,
width: 1.0
};
ui.style_mut().visuals.widgets.inactive.fg_stroke = s;
ui.style_mut().visuals.widgets.active.fg_stroke = s;
ui.style_mut().visuals.widgets.hovered.fg_stroke = s;
let mut slf = handle_error_ui!(Player::get());
let slider =ui.add(
egui::Slider::new(&mut slf.volume_slider, 0.0..=1.0)
.show_value(false)
);
if slider.changed() {
state.player.set_volume(slf.volume_slider);
}
});
ui.add_space(3.0);
});
});
Ok(())
}
}

View File

@ -1,94 +0,0 @@
use uuid::Uuid;
use xmpd_cache::DlStatus;
use xmpd_manifest::{song::Song, store::BaseStore};
use crate::{components::{left_nav::LeftNav, toast::ToastType, CompGetter, CompUi}, windows::WindowId};
use super::SongList;
#[derive(Debug, Default)]
pub struct Header {
pub search_text: String,
}
component_register!(Header);
impl CompUi for Header {
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
let theme = xmpd_settings::Settings::get()?.theme.clone();
let pid = {LeftNav::get()?.selected_playlist_id.clone()};
ui.horizontal(|ui| {
let search_icon = egui::Image::new(crate::data::SEARCH_ICON)
.fit_to_exact_size(egui::Vec2::new(16.0, 16.0))
.tint(theme.accent_color);
ui.add(search_icon);
{
ui.text_edit_singleline(&mut handle_error_ui!(Header::get()).search_text);
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::RIGHT), |ui| {
let download_all = ui.add(
egui::Image::new(crate::data::DL_ICON)
.tint(theme.accent_color)
.sense(egui::Sense::click())
.fit_to_exact_size(egui::Vec2::new(16.0, 16.0))
);
let add_song = ui.add(
egui::Image::new(crate::data::PLUS_ICON)
.tint(theme.accent_color)
.sense(egui::Sense::click())
.fit_to_exact_size(egui::Vec2::new(16.0, 16.0))
);
if download_all.clicked() {
let songs: Vec<_>;
match pid {
Some(pid) => {
songs = state.manifest.store().get_playlist(&pid).unwrap().songs().to_vec();
}
None => {
songs = state.manifest.store().get_songs().keys().cloned().collect();
}
}
for sid in handle_error_ui!(Self::get_songs_to_download(&songs)) {
if let Some(song) = state.manifest.store().get_song(&sid) {
handle_error_ui!(xmpd_cache::Cache::get()).download_song_to_cache(sid.clone(), song.clone())
}
}
let mut toast = handle_error_ui!(crate::components::toast::Toast::get());
toast.show_toast(
"Downloading Songs",
&format!("Started downloading {} songs", songs.len()),
ToastType::Info
);
}
if add_song.clicked() {
state.windows.toggle(&WindowId::AddSongToPl, true);
}
});
});
Ok(())
}
}
impl Header {
fn get_songs_to_download(songs: &Vec<uuid::Uuid>) -> crate::Result<Vec<uuid::Uuid>> {
let mut songs2 = Vec::new();
for sid in songs {
if let None = xmpd_cache::Cache::get()?.get_cached_song_status(&sid) {
songs2.push(sid.clone());
}
}
Ok(songs2)
}
}

View File

@ -1,293 +0,0 @@
use egui::{Color32, CursorIcon, ImageSource, RichText, Sense, Vec2};
use xmpd_cache::DlStatus;
use xmpd_manifest::{query, song::Song, store::BaseStore};
use crate::utils::SearchType;
use super::{CompGetter, CompUi};
pub mod header;
#[derive(Debug, Default)]
pub struct SongList {
pub selected_sid: uuid::Uuid,
playable_songs: Vec<uuid::Uuid>,
}
component_register!(SongList);
impl CompUi for SongList {
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
let songs = Self::get_and_sort_songs(state)?;
let disp_songs = Self::get_songs_to_display(&songs)?;
{
let mut sl = SongList::get()?;
sl.playable_songs = Self::get_playable_songs(&songs)?;
if let Some((sid, _)) = songs.first() {
if sl.selected_sid == Default::default() {
sl.selected_sid = sid.clone();
}
}
}
egui::ScrollArea::vertical()
.id_source("song_list")
.drag_to_scroll(false)
.show(ui, |ui| {
ui.vertical(|ui| {
ui.add_space(3.0);
for (sid, song) in disp_songs {
handle_error_ui!(Self::display_song_tab(ui, state, &sid, &song));
}
});
});
Ok(())
}
}
impl SongList {
fn get_and_sort_songs(state: &mut crate::GuiState) -> crate::Result<Vec<(uuid::Uuid, Song)>> {
let pid = super::left_nav::LeftNav::get()?.selected_playlist_id.clone();
match pid {
None => {
let songs = state.manifest.store().get_songs().clone().into_iter();
let mut songs: Vec<_> = songs.collect();
songs.sort_by(|a, b| {
let a = a.1.name().to_lowercase();
let b = b.1.name().to_lowercase();
a.cmp(&b)
});
Ok(songs)
}
Some(pid) => {
let Some(playlist) = state.manifest.store().get_playlist(&pid) else {
anyhow::bail!("Couldnt find playlist (corruption?)");
};
let mut songs = Vec::new();
for sid in playlist.songs() {
if let Some(song) = state.manifest.store().get_song(&sid) {
songs.push((sid.clone(), song.clone()));
}
}
songs.sort_by(|a, b| {
let a = a.1.name().to_lowercase();
let b = b.1.name().to_lowercase();
a.cmp(&b)
});
Ok(songs)
}
}
}
fn get_songs_to_display(songs: &Vec<(uuid::Uuid, Song)>) -> crate::Result<Vec<(uuid::Uuid, Song)>>{
let mut to_display = Vec::new();
let query = {header::Header::get()?.search_text.clone()};
let (query_type, query_text) = crate::utils::SearchType::from_str(&query);
for (sid, song) in songs {
let should_display = match &query_type {
SearchType::Normal |
SearchType::Author |
SearchType::Source if query_text.is_empty() => true,
SearchType::Source => {
song.source_type().to_string()
.to_lowercase()
.contains(&query_text)
},
SearchType::Author => {
song.author()
.to_lowercase()
.contains(&query_text)
},
SearchType::Normal => {
song.name()
.to_lowercase()
.contains(&query_text)
},
};
if should_display {
to_display.push((sid.clone(), song.clone()));
}
}
Ok(to_display)
}
fn display_song_tab(ui: &mut egui::Ui, state: &mut crate::GuiState, sid: &uuid::Uuid, song: &Song) -> crate::Result<()> {
let mut clicked = false;
ui.horizontal(|ui| {
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
// let icon_status = handle_error_ui!(xmpd_cache::Cache::get()).get_cached_icon_status(&sid).clone();
let img = ui.add(
//if let Some(DlStatus::Done(Some(p))) = icon_status {
// let uri: Cow<str> = Cow::Owned(p.to_string_lossy().to_string());
// let bytes = handle_error_ui!(std::fs::read(p));
// ui.ctx().include_bytes(uri.clone(), bytes);
// egui::Image::new(ImageSource::Uri(uri))
// .sense(Sense::click())
// .fit_to_exact_size(Vec2::new(32.0, 32.0))
// } else {
egui::Image::new(crate::data::NOTE_ICON)
.tint(theme.accent_color)
.sense(Sense::click())
.fit_to_exact_size(Vec2::new(32.0, 32.0))
//}
);
let status = {
handle_error_ui!(xmpd_cache::Cache::get()).get_cached_song_status(&sid).clone()
};
if img.clicked() {
clicked = true;
}
if img.hovered() {
if matches!(status, Some(DlStatus::Done(_))) {
ui.output_mut(|o| o.cursor_icon = CursorIcon::PointingHand);
} else {
ui.output_mut(|o| o.cursor_icon = CursorIcon::Default);
}
}
// img.context_menu(|ui| handle_error_ui!(Self::show_context_menu(ui, sid, song)));
ui.vertical(|ui| {
let slf = handle_error_ui!(SongList::get());
let label = if slf.selected_sid == *sid {
RichText::new(song.name())
.color(theme.accent_color)
} else if matches!(status, Some(DlStatus::Done(_))) {
RichText::new(song.name())
.color(theme.text_color)
} else {
RichText::new(song.name())
.color(theme.dim_text_color)
};
let label = ui.label(label);
if label.clicked() {
clicked = true;
}
if label.hovered() {
if matches!(status, Some(DlStatus::Done(_))) {
ui.output_mut(|o| o.cursor_icon = CursorIcon::PointingHand);
} else {
ui.output_mut(|o| o.cursor_icon = CursorIcon::Default);
}
}
// label.context_menu(|ui| handle_error_ui!(Self::show_context_menu(ui, sid, song)));
ui.monospace(
RichText::new(format!("By {}", song.author()))
.color(theme.dim_text_color)
.size(10.0)
);
});
ui.with_layout(egui::Layout::right_to_left(egui::Align::RIGHT), |ui| {
ui.add_space(3.0);
match status {
Some(DlStatus::Done(_)) => {
//let img = egui::Image::new(crate::data::CHECK_ICON)
// .tint(Color32::LIGHT_GREEN)
// .sense(Sense::hover())
// .fit_to_exact_size(Vec2::new(16.0, 16.0));
//ui.add(img).on_hover_ui(|ui| {
// ui.label(format!("Path: {p}"));
//});
}
Some(DlStatus::Downloading) => {
let spinner = egui::Spinner::new()
.color(theme.accent_color)
.size(16.0);
ui.add(spinner);
}
Some(DlStatus::Error(e, ..)) => {
let img = egui::Image::new(crate::data::WARN_ICON)
.tint(Color32::LIGHT_YELLOW)
.sense(Sense::hover())
.fit_to_exact_size(Vec2::new(16.0, 16.0));
ui.add(img).on_hover_ui(|ui| {
ui.label(e);
});
}
None => {
let img = egui::Image::new(crate::data::DL_ICON)
.tint(theme.accent_color)
.sense(Sense::click())
.fit_to_exact_size(Vec2::new(16.0, 16.0));
if ui.add(img).clicked() {
handle_error_ui!(xmpd_cache::Cache::get()).download_song_to_cache(sid.clone(), song.clone());
let mut toast = handle_error_ui!(crate::components::toast::Toast::get());
toast.show_toast(
"Downloading Song",
&format!("Started downloading {} by {}", song.name(), song.author()),
super::toast::ToastType::Info
);
}
}
}
});
});
ui.separator();
if clicked {
let mut sl = SongList::get()?;
sl.play_song(sid.clone(), state)?;
}
Ok(())
}
pub fn play_song(&mut self, sid: uuid::Uuid, state: &mut crate::GuiState) -> crate::Result<()> {
if self.playable_songs.contains(&sid) {
self.selected_sid = sid.clone();
let path = state.manifest.get_song_as_path(sid)?;
state.player.play_song(&path)?;
}
Ok(())
}
pub fn play_prev(&mut self, state: &mut crate::GuiState) -> crate::Result<()> {
let Some(mut prev) = self.playable_songs.last().cloned() else {
anyhow::bail!("Trying to play a song in an empty playlist (impossible)")
};
for sid in self.playable_songs.clone() {
if sid == self.selected_sid {
self.play_song(prev, state)?;
}
prev = sid;
}
Ok(())
}
pub fn play_next(&mut self, state: &mut crate::GuiState) -> crate::Result<()> {
let Some(mut next) = self.playable_songs.first().cloned() else {
anyhow::bail!("Trying to play a song in an empty playlist (impossible)")
};
let mut found = false;
for sid in self.playable_songs.clone() {
if sid == self.selected_sid {
found = true;
} else if found {
next = sid;
break;
}
}
self.play_song(next, state)?;
Ok(())
}
fn get_playable_songs(songs: &Vec<(uuid::Uuid, Song)>) -> crate::Result<Vec<uuid::Uuid>> {
let mut playable_songs = Vec::new();
for (sid, _) in songs {
if let Some(DlStatus::Done(_)) = xmpd_cache::Cache::get()?.get_cached_song_status(&sid) {
playable_songs.push(sid.clone());
}
}
Ok(playable_songs)
}
//fn show_context_menu(ui: &mut egui::Ui, sid: &uuid::Uuid, song: &Song) -> crate::Result<()> {
// if ui.button("Download icon").clicked() {
// xmpd_cache::Cache::get()?.download_icon_to_cache(sid.clone(), song.clone());
// }
// Ok(())
//}
}

View File

@ -1,114 +0,0 @@
use std::{collections::VecDeque, time::SystemTime};
use egui::{epaint::Shadow, load::TexturePoll, Align2, Color32, Frame, Image, ImageSource, Margin, Pos2, Rect, RichText, Rounding, Stroke, Style, TextureFilter, TextureOptions, TextureWrapMode, Vec2};
use super::{CompGetter, CompUi};
#[derive(Debug, Default, PartialEq, Clone, Copy)]
pub enum ToastType {
#[default]
Info,
Warn,
Error,
}
#[derive(Debug, Default)]
pub struct Toast {
queue: VecDeque<(String, String, ToastType, SystemTime)>
}
component_register!(Toast);
impl CompUi for Toast {
fn draw(ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
let screen_size = ui.ctx().screen_rect().size();
let (w, h) = (300.0, 100.0);
let theme = &xmpd_settings::Settings::get()?.theme;
let mut toastw = Toast::get()?;
let mut height_iter = 6.0;
let mut to_remove = Vec::new();
for (i, (title, description, toast_type, shown_since)) in toastw.queue.iter().enumerate() {
let area = egui::Area::new(egui::Id::new(format!("toast_{i}")))
.fixed_pos(Pos2::new(screen_size.x - w, height_iter))
.pivot(Align2::LEFT_TOP)
.show(ui.ctx(), |ui| {
ui.set_width(w);
let img;
let color;
match toast_type {
ToastType::Info => {
color = theme.accent_color;
img = Image::new(crate::data::INFO_ICON)
.fit_to_exact_size(Vec2::new(16.0, 16.0))
.tint(color);
}
ToastType::Warn => {
color = crate::data::C_WARN;
img = Image::new(crate::data::WARN_ICON)
.fit_to_exact_size(Vec2::new(16.0, 16.0))
.texture_options(TextureOptions {
magnification: TextureFilter::Linear,
minification: TextureFilter::Linear,
wrap_mode: TextureWrapMode::ClampToEdge,
})
.tint(color);
}
ToastType::Error => {
color = Color32::LIGHT_RED;
img = Image::new(crate::data::ERROR_ICON)
.fit_to_exact_size(Vec2::new(16.0, 16.0))
.tint(color);
}
}
Frame::none()
.stroke(Stroke::new(1.0, color))
.fill(theme.primary_bg_color)
.rounding(Rounding::same(3.0))
.inner_margin(Margin::same(3.0))
.show(ui, |ui| {
ui.set_width(w-9.0);
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
ui.horizontal(|ui| {
ui.add(img);
ui.label(RichText::new(title));
});
ui.label(
RichText::new(description)
.size(10.0)
);
ui.shrink_height_to_current();
// height_iter += ui.available_height();
}
)
}
);
height_iter += area.response.rect.height() + 6.0;
// if shown for longer than 5 seconds remove it
if SystemTime::now().duration_since(*shown_since)?.as_secs() > 5 {
to_remove.push(i);
}
}
for idx in to_remove {
toastw.queue.remove(idx);
}
Ok(())
}
}
impl Toast {
pub fn show_toast<S>(&mut self, title: S, description: S, toast_type: ToastType)
where S: ToString
{
self.queue.push_front((title.to_string(), description.to_string(), toast_type, SystemTime::now()));
}
}

View File

@ -1,87 +0,0 @@
use std::path::PathBuf;
use egui::TextBuffer;
use xmpd_manifest::store::{JsonStore, TomlStore};
use crate::windows::WindowId;
use super::{CompGetter, CompUi};
#[derive(Debug, Default)]
pub struct TopNav {
// for dialog
manifest_path: Option<(PathBuf, String)>
}
component_register!(TopNav);
impl CompUi for TopNav {
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
ui.add_space(3.0);
ui.horizontal(|ui| {
ui.add_space(3.0);
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
if ui.button("Settings").clicked() {
state.windows.toggle(&WindowId::Settings, true);
ui.close_menu();
}
});
ui.menu_button("Manifest", |ui| {
if ui.button("Save").clicked() {
handle_error_ui!(state.manifest.save());
ui.close_menu();
}
if ui.button("Save As").clicked() {
std::thread::spawn(|| -> crate::Result<()> {
let mut dialog = rfd::FileDialog::new()
.add_filter("Json", &["json"])
.add_filter("Toml", &["toml"])
.set_title("Save Manifest As")
.set_can_create_directories(true)
.set_file_name("manifest");
if let Some(home_dir) = dirs::home_dir() {
dialog = dialog.set_directory(home_dir);
}
if let Some(path) = dialog.save_file() {
if let Some(ext) = path.extension() {
TopNav::get()?.manifest_path = Some((path.clone(), ext.to_string_lossy().to_string()))
}
}
Ok(())
});
}
});
ui.menu_button("Help", |ui| {
if ui.button("Source").clicked() {
ui.ctx().open_url(egui::OpenUrl::new_tab("https://git.mcorangehq.xyz/XOR64/music"));
ui.close_menu();
}
#[cfg(debug_assertions)]
if ui.button("Debug").clicked() {
state.windows.toggle(&WindowId::Debug, true);
ui.close_menu();
}
});
});
});
let mut used = false;
if let Some((path, ext)) = &TopNav::get()?.manifest_path {
match ext.as_str() {
"json" => state.manifest.convert_and_save_to::<JsonStore>(&path)?,
"toml" => state.manifest.convert_and_save_to::<TomlStore>(&path)?,
_ => ()
}
used = true;
}
if used {
TopNav::get()?.manifest_path = None;
}
Ok(())
}
}

View File

@ -1,19 +0,0 @@
// pub const APP_ICON: egui::ImageSource = egui::include_image!("../../assets/app_icon.png");
// pub const APP_ICON_BYTES: &[u8] = include_bytes!("../../assets/app_icon.png");
pub const NOTE_ICON: egui::ImageSource = egui::include_image!("../../assets/note.svg");
pub const SEARCH_ICON: egui::ImageSource = egui::include_image!("../../assets/search.svg");
pub const PREV_ICON: egui::ImageSource = egui::include_image!("../../assets/prev.svg");
pub const NEXT_ICON: egui::ImageSource = egui::include_image!("../../assets/next.svg");
pub const PLAY_ICON: egui::ImageSource = egui::include_image!("../../assets/play.svg");
pub const PAUSE_ICON: egui::ImageSource = egui::include_image!("../../assets/pause.svg");
pub const CHECK_ICON: egui::ImageSource = egui::include_image!("../../assets/check.svg");
pub const DL_ICON: egui::ImageSource = egui::include_image!("../../assets/download.svg");
pub const INFO_ICON: egui::ImageSource = egui::include_image!("../../assets/info.svg");
pub const WARN_ICON: egui::ImageSource = egui::include_image!("../../assets/warning.svg");
pub const ERROR_ICON: egui::ImageSource = egui::include_image!("../../assets/error.svg");
pub const PLUS_ICON: egui::ImageSource = egui::include_image!("../../assets/plus.svg");
pub const BURGER_ICON: egui::ImageSource = egui::include_image!("../../assets/burger_menu.svg");
pub const C_WARN: egui::Color32 = egui::Color32::from_rgb(255, 183, 0); // #ffb700

View File

@ -1,53 +0,0 @@
#![feature(async_closure)]
use std::time::Duration;
use xmpd_manifest::{store::JsonStore, Manifest};
#[macro_use]
mod macros;
mod main_window;
mod windows;
mod components;
mod data;
mod utils;
const W_NAME: &str = "xmpd v2.0.0a";
type Result<T> = anyhow::Result<T>;
pub fn start() -> Result<()> {
let cache_rx = xmpd_cache::Cache::get()?.init()?;
let options = eframe::NativeOptions::default();
let mut state = GuiState::new()?;
let res = eframe::run_simple_native(W_NAME, options, move |ctx, _frame| {
egui_extras::install_image_loaders(ctx);
state.windows.clone().draw_all(ctx, &mut state);
handle_error_ui!(main_window::draw(ctx, &mut state, &cache_rx));
ctx.request_repaint_after(Duration::from_millis(500));
});
if let Err(e) = res { // dumb err value by eframe
anyhow::bail!(e.to_string());
}
Ok(())
}
pub struct GuiState {
pub manifest: Manifest<JsonStore>,
pub windows: windows::Windows,
pub player: xmpd_player::Player,
}
impl GuiState {
pub fn new() -> Result<Self> {
Ok(Self {
player: xmpd_player::Player::new(),
manifest: Manifest::new(&xmpd_cliargs::CLIARGS.manifest_path())?,
windows: windows::Windows::new(),
})
}
}

View File

@ -1,48 +0,0 @@
macro_rules! component_register {
($comp:ident) => {
lazy_static::lazy_static! {
static ref __COMPONENT: std::sync::Arc<std::sync::Mutex<$comp>> =
std::sync::Arc::new(std::sync::Mutex::new($comp::default()));
}
impl crate::components::CompGetter for $comp {
fn get() -> crate::Result<std::sync::MutexGuard<'static, Self>> {
match __COMPONENT.lock() {
Ok(l) => Ok(l),
Err(e) => Err(anyhow::anyhow!(format!("{e:?}"))),
}
}
}
};
}
macro_rules! handle_error_ui {
($val:expr) => {
match $val {
Ok(v) => v,
Err(e) => {
use crate::components::CompGetter;
log::error!("Error in {}:{}: {e}", std::file!(), std::line!());
if let Ok(mut toast) = crate::components::toast::Toast::get() {
toast.show_toast(
&format!("Error in {}:{}", std::file!(), std::line!()),
&format!("{e}"),
crate::components::toast::ToastType::Error,
);
}
return;
}
}
};
}
macro_rules! handle_option {
($reason:expr, $val:expr) => {
if let Some(v) = $val {
v
} else {
handle_error_ui!(Err(anyhow::anyhow!($reason)));
return;
}
};
}

View File

@ -1,104 +0,0 @@
use std::sync::mpsc::Receiver;
use xmpd_cache::Message;
use xmpd_manifest::store::BaseStore;
use xmpd_settings::theme::Theme;
use crate::{components::{self, song_list, toast::ToastType, CompGetter, CompUi}, GuiState};
pub fn draw(ctx: &egui::Context, state: &mut GuiState, cache_rx: &Receiver<Message>) -> crate::Result<()> {
let theme = xmpd_settings::Settings::get()?.theme.clone();
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Top, "top_nav")
.frame(get_themed_frame(&theme))
.show(ctx, |ui| {
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
handle_error_ui!(crate::components::top_nav::TopNav::draw(ui, state));
}
);
egui::CentralPanel::default()
.frame(get_themed_frame(&theme))
.show(ctx, |ui| {
handle_error_ui!(components::toast::Toast::draw(ui, state));
let avail = ui.available_size();
ui.vertical(|ui| {
crate::utils::super_separator(ui, theme.accent_color, avail.x, 2.0);
let avail = ui.available_size();
let main_height = avail.y * 0.91;
let left_nav_width = (avail.x * 0.25).clamp(0.0, 200.0);
let song_list_width = avail.x - left_nav_width - 35.0;
ui.horizontal(|ui| {
ui.set_height(main_height);
ui.vertical(|ui| {
ui.group(|ui| {
//ui.set_height(main_height * 0.1);
ui.set_max_width(left_nav_width);
handle_error_ui!(crate::components::left_nav::header::Header::draw(ui, state));
});
ui.group(|ui| {
// ui.set_height(main_height * 0.9);
ui.set_max_width(left_nav_width);
handle_error_ui!(crate::components::left_nav::LeftNav::draw(ui, state));
});
});
ui.vertical(|ui| {
ui.group(|ui| {
ui.set_width(song_list_width);
handle_error_ui!(crate::components::song_list::header::Header::draw(ui, state));
});
ui.group(|ui| {
ui.set_width(song_list_width);
handle_error_ui!(crate::components::song_list::SongList::draw(ui, state));
});
});
});
});
}
);
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "player")
.frame(get_themed_frame(&theme))
.show(ctx, |ui| {
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
handle_error_ui!(crate::components::player::Player::draw(ui, state));
}
);
if let Ok(msg) = cache_rx.try_recv() {
match msg {
Message::DownloadDone(sid) => {
if let Some(song) = state.manifest.store().get_song(&sid) {
let mut toast = crate::components::toast::Toast::get()?;
toast.show_toast(
"Done downloading",
&format!("Downloaded {} by {}", song.name(), song.author()),
ToastType::Info
);
}
}
Message::Error(file, line, e) => {
if let Ok(mut toast) = crate::components::toast::Toast::get() {
toast.show_toast(
&format!("Error in {file}:{line}"),
&format!("{e}"),
crate::components::toast::ToastType::Error,
);
}
}
}
}
Ok(())
}
fn get_themed_frame(theme: &Theme) -> egui::Frame {
egui::Frame::none()
.fill(theme.primary_bg_color)
.stroke(egui::Stroke::new(
5.0,
theme.secondary_bg_color,
))
}

View File

@ -1,29 +0,0 @@
#[derive(Debug, Clone)]
pub enum SearchType {
Normal,
Author,
Source,
}
impl SearchType {
pub fn from_str(s: &str) -> (Self, String) {
match s {
i @ _ if i.starts_with("source:") =>
(Self::Source, i.strip_prefix("source:").unwrap_or("").to_string().to_lowercase()),
i @ _ if i.starts_with("author:") =>
(Self::Author, i.strip_prefix("author:").unwrap_or("").to_string().to_lowercase()),
i @ _ => (Self::Normal, i.to_string().to_lowercase())
}
}
}
pub fn super_separator(ui: &mut egui::Ui, color: egui::Color32, width: f32, height: f32) {
egui::Frame::none()
.fill(color)
.show(ui, |ui| {
ui.set_width(width);
ui.set_height(height);
});
}

View File

@ -1,20 +0,0 @@
use super::Window;
#[derive(Debug, Default)]
pub struct AddSongW {
}
impl Window for AddSongW {
fn id() -> super::WindowId where Self: Sized {
super::WindowId::AddSongToPl
}
fn default_title() -> &'static str where Self: Sized {
"Add Song to Playlist"
}
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
ui.label("Hello from other window!");
Ok(())
}
}

View File

@ -1,80 +0,0 @@
use egui::RichText;
use crate::components::{toast::{self, ToastType}, CompGetter};
use super::Window;
#[derive(Debug, Default)]
pub struct DebugW {
toast_title: String,
toast_descr: String,
toast_type: ToastType,
}
impl Window for DebugW {
fn id() -> super::WindowId where Self: Sized {
super::WindowId::Debug
}
fn default_title() -> &'static str where Self: Sized {
"DEBUG WINDOW"
}
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
ui.group(|ui| {
ui.vertical(|ui| {
ui.label(
RichText::new("DEBUG")
.heading()
);
ui.horizontal(|ui| {
{
ui.group(|ui| {
ui.vertical(|ui| {
ui.label(
RichText::new("Toast")
.heading()
);
Self::add_input_field(&mut self.toast_title, ui, "Title");
Self::add_input_field(&mut self.toast_descr, ui, "Description");
ui.horizontal(|ui| {
ui.label("Type:");
egui::ComboBox::from_id_source("debug_combo")
.selected_text(format!("{:?}", self.toast_type))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.toast_type, ToastType::Info, "Info");
ui.selectable_value(&mut self.toast_type, ToastType::Warn, "Warn");
ui.selectable_value(&mut self.toast_type, ToastType::Error, "Error");
}
);
});
if ui.button("Add").clicked() {
toast::Toast::get().unwrap().show_toast(&self.toast_title, &self.toast_descr, self.toast_type);
}
if ui.button("Throw Error").clicked() {
handle_error_ui!(Err(anyhow::anyhow!("{}: {}", self.toast_title, self.toast_descr)));
}
});
});
}
});
});
});
Ok(())
}
}
impl DebugW {
fn add_input_field(inp: &mut String, ui: &mut egui::Ui, name: &str) {
ui.horizontal(|ui|{
ui.label(format!("{name}: "));
ui.text_edit_singleline(inp);
});
}
fn add_input_field_ml(inp: &mut String, ui: &mut egui::Ui, name: &str) {
ui.horizontal(|ui|{
ui.label(format!("{name}: "));
ui.text_edit_multiline(inp);
});
}
}

View File

@ -1,20 +0,0 @@
use super::Window;
#[derive(Debug, Default)]
pub struct ErrorW {
}
impl Window for ErrorW {
fn id() -> super::WindowId where Self: Sized {
super::WindowId::Error
}
fn default_title() -> &'static str where Self: Sized {
"Error!"
}
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
ui.label("Hello from other window!");
Ok(())
}
}

View File

@ -1,107 +0,0 @@
use std::{collections::{HashMap, HashSet}, sync::{Arc, Mutex}};
use egui::{ViewportBuilder, ViewportId};
use crate::GuiState;
#[cfg(debug_assertions)]
mod debug;
mod error;
mod settings;
mod add_song;
mod new_song;
mod new_playlist;
lazy_static::lazy_static!(
static ref WINDOWS: Arc<Mutex<HashMap<WindowId, Box<dyn Window>>>> = Arc::new(Mutex::new(HashMap::new()));
static ref OPEN_WINDOWS: Arc<Mutex<HashSet<WindowId>>> = Arc::new(Mutex::new(HashSet::new()));
);
pub trait Window: std::fmt::Debug + Send {
fn draw(&mut self, ui: &mut egui::Ui, state: &mut GuiState) -> crate::Result<()>;
fn id() -> WindowId where Self: Sized;
fn default_title() -> &'static str where Self: Sized;
fn close(&self) where Self: Sized{
OPEN_WINDOWS.lock().unwrap().remove(&Self::id());
}
}
#[derive(Debug, Clone, Hash, PartialEq, PartialOrd, Ord, Eq)]
pub enum WindowId {
Settings,
Error,
#[cfg(debug_assertions)]
Debug,
NewPlaylist,
NewSong,
AddSongToPl,
}
#[derive(Debug, Clone)]
pub struct Windows {
windows: HashMap<WindowId, (ViewportId, ViewportBuilder)>,
}
impl Windows {
pub fn new() -> Self {
let mut s = Self {
windows: HashMap::new(),
};
s.add_all_windows();
s
}
pub fn add_all_windows(&mut self) {
#[cfg(debug_assertions)]
self.add_new_window::<debug::DebugW>();
self.add_new_window::<error::ErrorW>();
self.add_new_window::<settings::SettingsW>();
self.add_new_window::<add_song::AddSongW>();
self.add_new_window::<new_song::NewSongW>();
self.add_new_window::<new_playlist::NewPlaylistW>();
}
pub fn add_new_window<WT: Window + Default + 'static>(&mut self) {
let builder = ViewportBuilder::default()
.with_window_type(egui::X11WindowType::Dialog)
.with_title(WT::default_title());
self.windows.insert(WT::id(), (ViewportId::from_hash_of(WT::id()), builder));
WINDOWS.lock().unwrap().insert(WT::id(), Box::<WT>::default());
}
pub fn draw_all(&mut self, ctx: &egui::Context, state: &mut GuiState) {
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
for (win_id, (vp_id, builder)) in &self.windows {
if self.is_open(&win_id) {
ctx.show_viewport_immediate(vp_id.clone(), builder.clone(), |ctx, _vp_class| {
ctx.input(|inp| {
self.toggle(win_id, !inp.viewport().close_requested());
});
egui::CentralPanel::default()
.frame(
egui::Frame::none()
.fill(theme.primary_bg_color)
.stroke(egui::Stroke::new(
1.0,
theme.secondary_bg_color,
)),
)
.show(ctx, |ui| {
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
WINDOWS.lock().unwrap().get_mut(&win_id).unwrap().draw(ui, state)
})
});
}
}
}
pub fn toggle(&self, id: &WindowId, status: bool) {
if status {
OPEN_WINDOWS.lock().unwrap().insert(id.clone());
} else {
OPEN_WINDOWS.lock().unwrap().remove(id);
}
}
pub fn is_open(&self, id: &WindowId) -> bool {
OPEN_WINDOWS.lock().unwrap().contains(&id)
}
}

View File

@ -1,102 +0,0 @@
use std::str::FromStr;
use egui::{Sense, Vec2};
use xmpd_manifest::{playlist::{self, Playlist}, store::BaseStore};
use super::{Window, WindowId};
#[derive(Debug)]
pub struct NewPlaylistW {
name: String,
author: String,
}
impl Default for NewPlaylistW {
fn default() -> Self {
Self {
name: String::from("New Playlist"),
author: String::from("Unknown"),
}
}
}
impl Window for NewPlaylistW {
fn id() -> WindowId where Self: Sized {
WindowId::NewPlaylist
}
fn default_title() -> &'static str where Self: Sized {
"New Playlist"
}
fn draw(&mut self, ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
let theme = xmpd_settings::Settings::get()?.theme.clone();
let img_size = 64.0;
let img_spacing = 10.0;
ui.vertical(|ui| {
ui.horizontal(|ui| {
let mut rect = egui::Rect::ZERO;
rect.set_width(img_size);
rect.set_height(img_size);
rect.set_top(img_spacing);
rect.set_left(img_spacing);
let rect_int = ui.interact(rect, "new_playlist_w".into(), Sense::click());
if rect_int.hovered() {
ui.allocate_ui_at_rect(rect, |ui| {
ui.group(|ui| {
let img = egui::Image::new(crate::data::PLUS_ICON)
.tint(theme.accent_color)
.fit_to_exact_size(Vec2::new(img_size, img_size));
//.paint_at(ui, rect);
ui.add(img);
});
});
} else {
ui.allocate_ui_at_rect(rect, |ui| {
ui.group(|ui| {
let img = egui::Image::new(crate::data::NOTE_ICON)
.tint(theme.accent_color)
.fit_to_exact_size(Vec2::new(img_size, img_size));
//.paint_at(ui, rect);
ui.add(img);
});
});
}
if rect_int.clicked() {
// TODO: Add a way to add custom icons
}
ui.vertical(|ui| {
ui.add_space(img_spacing);
ui.horizontal(|ui| {
ui.label("Name: ");
ui.text_edit_singleline(&mut self.name);
});
ui.horizontal(|ui| {
ui.label("Author: ");
ui.text_edit_singleline(&mut self.author);
});
});
});
ui.with_layout(egui::Layout::bottom_up(egui::Align::Max), |ui| {
ui.add_space(3.0);
ui.horizontal(|ui| {
ui.add_space(3.0);
if ui.button("Cancel").clicked() {
self.author = String::from("New Playlist");
self.name = String::from("Unknown");
state.windows.toggle(&WindowId::NewPlaylist, false);
}
if ui.button("Add").clicked() {
let mut playlist = Playlist::default();
playlist.set_name(&self.name);
playlist.set_author(&self.author);
let playlists = state.manifest.store_mut().get_playlists_mut();
playlists.insert(uuid::Uuid::new_v4(), playlist);
state.windows.toggle(&WindowId::NewPlaylist, false);
}
});
});
});
Ok(())
}
}

View File

@ -1,20 +0,0 @@
use super::Window;
#[derive(Debug, Default)]
pub struct NewSongW {
}
impl Window for NewSongW {
fn id() -> super::WindowId where Self: Sized {
super::WindowId::NewSong
}
fn default_title() -> &'static str where Self: Sized {
"New Song"
}
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
ui.label("Hello from other window!");
Ok(())
}
}

View File

@ -1,103 +0,0 @@
use std::str::FromStr;
use super::Window;
#[derive(Debug, Clone)]
pub struct SettingsW {
ytdlp_p: String,
spotdl_p: String,
ffmpeg_p: String,
song_fmt: String,
}
impl Default for SettingsW {
fn default() -> Self {
let tooling = xmpd_settings::Settings::get().unwrap().tooling.clone();
Self {
ytdlp_p: tooling.ytdlp_path.to_string(),
spotdl_p: tooling.spotdl_path.to_string(),
ffmpeg_p: tooling.ffmpeg_path.to_string(),
song_fmt: tooling.song_format
}
}
}
impl Window for SettingsW {
fn id() -> super::WindowId where Self: Sized {
super::WindowId::Settings
}
fn default_title() -> &'static str where Self: Sized {
"Settings"
}
#[allow(irrefutable_let_patterns)]
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
ui.group(|ui| {
ui.vertical(|ui| {
ui.horizontal(|ui| {
{
let theme = &mut handle_error_ui!(xmpd_settings::Settings::get()).theme;
ui.group(|ui| {
ui.vertical(|ui| {
ui.heading("Theme");
Self::add_theme_button(&mut theme.accent_color, ui, "Accent");
Self::add_theme_button(&mut theme.primary_bg_color, ui, "Primary BG");
Self::add_theme_button(&mut theme.secondary_bg_color, ui, "Secondary BG");
Self::add_theme_button(&mut theme.text_color, ui, "Text");
Self::add_theme_button(&mut theme.dim_text_color, ui, "Dim Text");
if ui.button("Reset").clicked() {
*theme = xmpd_settings::theme::Theme::default();
}
});
});
}
{
ui.group(|ui| {
ui.vertical(|ui| {
ui.heading("Tooling paths");
Self::add_tooling_input(&mut self.ytdlp_p, ui, "stdlp");
Self::add_tooling_input(&mut self.spotdl_p, ui, "spotdl");
Self::add_tooling_input(&mut self.ffmpeg_p, ui, "ffmpeg");
Self::add_tooling_input(&mut self.song_fmt, ui, "Format");
});
});
}
});
ui.with_layout(egui::Layout::bottom_up(egui::Align::RIGHT), |ui| {
if ui.button("Save").clicked() {
let mut settings = handle_error_ui!(xmpd_settings::Settings::get());
if let Ok(p) = camino::Utf8PathBuf::from_str(&self.ytdlp_p) {
settings.tooling.ytdlp_path = p;
}
if let Ok(p) = camino::Utf8PathBuf::from_str(&self.spotdl_p) {
settings.tooling.spotdl_path = p;
}
if let Ok(p) = camino::Utf8PathBuf::from_str(&self.ffmpeg_p) {
settings.tooling.ffmpeg_path = p;
}
settings.tooling.song_format.clone_from(&self.song_fmt);
handle_error_ui!(settings.save(None));
}
});
});
});
Ok(())
}
}
impl SettingsW {
fn add_theme_button(rf: &mut egui::Color32, ui: &mut egui::Ui, name: &str) {
ui.horizontal(|ui| {
ui.label(format!("{name}: "));
ui.color_edit_button_srgba(rf);
});
}
fn add_tooling_input(inp: &mut String, ui: &mut egui::Ui, name: &str) {
ui.horizontal(|ui|{
ui.label(format!("{name}: "));
ui.text_edit_singleline(inp);
});
}
}

View File

@ -1,28 +0,0 @@
[package]
name = "xmpd-manifest"
edition = "2021"
readme="README.md"
authors.workspace = true
version.workspace = true
repository.workspace = true
license.workspace = true
autobins = false
autotests = false
autoexamples = false
[features]
default = []
[lib]
crate-type = ["rlib"]
bench = false
[dependencies]
xmpd-cliargs.path = "../xmpd-cliargs"
xmpd-settings.path = "../xmpd-settings"
anyhow.workspace = true
uuid.workspace = true
serde.workspace = true
serde_json.workspace = true
url.workspace = true
toml.workspace = true

View File

@ -1,78 +0,0 @@
use std::path::{Path, PathBuf};
#[cfg(test)]
pub mod tests;
pub mod store;
pub mod song;
pub mod playlist;
pub mod query;
pub type Result<T> = anyhow::Result<T>;
#[derive(Debug, Clone)]
pub struct Manifest<ST: store::BaseStore> {
store: Box<ST>,
}
impl<ST: store::BaseStore + Clone> Manifest<ST> {
pub fn new(p: &Path) -> Result<Self>{
let mut store = ST::empty();
if p.exists() {
store.load_from(p)?;
} else {
store.save_to(p)?;
}
store.save_original_path(p);
Ok(Self {
store: Box::new(store)
})
}
pub fn store(&self) -> &ST {
self.store.as_ref()
}
pub fn store_mut(&mut self) -> &mut ST {
self.store.as_mut()
}
pub fn save(&self) -> Result<()> {
self.store().save_to(self.store().get_original_path())?;
Ok(())
}
pub fn load(&mut self) -> Result<()> {
let p = self.store().get_original_path().to_path_buf();
self.store_mut().load_from(&p)?;
Ok(())
}
pub fn convert_to<ST2: store::BaseStore>(&self) -> ST2 {
let songs = self.store().get_songs().clone();
let playlists = self.store().get_playlists().clone();
let mut st2 = ST2::empty();
*st2.get_songs_mut() = songs;
*st2.get_playlists_mut() = playlists;
st2
}
pub fn convert_and_save_to<ST2: store::BaseStore>(&self, path: &Path) -> Result<()> {
let st2 = self.convert_to::<ST2>();
std::fs::write(path, st2.to_bytes()?)?;
Ok(())
}
pub fn get_song_as_path(&self, sid: uuid::Uuid) -> Result<PathBuf> {
let ext = &xmpd_settings::Settings::get()?.tooling.song_format;
let mut p = xmpd_cliargs::CLIARGS.cache_path().into_std_path_buf();
p.push("songs");
p.push(sid.to_string());
p.set_extension(ext);
Ok(p)
}
}

View File

@ -1,40 +0,0 @@
use uuid::Uuid;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, PartialOrd, Default)]
pub struct Playlist {
name: String,
author: String,
songs: Vec<Uuid>
}
impl Playlist {
pub fn name(&self) -> &str {
&self.name
}
pub fn author(&self) -> &str {
&self.author
}
pub fn songs(&self) -> &Vec<Uuid> {
&self.songs
}
pub fn songs_mut(&mut self) -> &mut Vec<Uuid> {
&mut self.songs
}
pub fn set_name(&mut self, v: &str) {
self.name = v.to_string();
}
pub fn set_author(&mut self, v: &str) {
self.author = v.to_string();
}
pub fn add_song(&mut self, v: &Uuid) {
self.songs.push(v.clone());
}
pub fn remove_song(&mut self, v: &Uuid) {
for (i, id) in self.songs.iter().enumerate() {
if id == v {
self.songs.remove(i);
break;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More