Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95ea5da248 |
No files matched your search
@@ -1,2 +1 @@
|
||||
CMakeLists.txt.user
|
||||
flatpak/flatpak-builder-tools/
|
||||
@@ -1,117 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) 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 this service 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 make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. 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.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), 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 distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions of the 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 a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE 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.
|
||||
|
||||
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 convey 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 an idea of what it does. Copyright (C) yyyy 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author Gnomovision 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, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice
|
||||
@@ -7,7 +7,3 @@ AudioTube is a client for YouTube Music.
|
||||
It depends on Qt and Kirigami in addition to a few python packages:
|
||||
* ytmusicapi
|
||||
* youtube_dl
|
||||
|
||||
# Troubleshooting
|
||||
|
||||
AudioTube only needs Python 3. If cmake still selects Python 2, you can pass `-DPYTHON_EXECUTABLE=/usr/bin/python3` to correct that.
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"name": "python3-youtube_dl",
|
||||
"buildsystem": "simple",
|
||||
"build-commands": [
|
||||
"pip3 install --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"youtube_dl\" --no-build-isolation"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/be/d5/15995c54364497d2706011439c94a8629ccffc5c2ce0c406929b3958f27a/youtube_dl-2021.3.3.tar.gz",
|
||||
"sha256": "02432aa2dd0e859e64d74fca2ad624abf3bead3dba811d594100e1cb7897dce7"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
{
|
||||
"name": "python3-ytmusicapi",
|
||||
"buildsystem": "simple",
|
||||
"build-commands": [
|
||||
"pip3 install --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"ytmusicapi\" --no-build-isolation"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/06/a9/cd1fd8ee13f73a4d4f491ee219deeeae20afefa914dfb4c130cfc9dc397a/certifi-2020.12.5.tar.gz",
|
||||
"sha256": "1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/ee/2d/9cdc2b527e127b4c9db64b86647d567985940ac3698eeabc7ffaccb4ea61/chardet-4.0.0.tar.gz",
|
||||
"sha256": "0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/ea/b7/e0e3c1c467636186c39925827be42f16fee389dc404ac29e930e9136be70/idna-2.10.tar.gz",
|
||||
"sha256": "b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/d7/8d/7ee68c6b48e1ec8d41198f694ecdc15f7596356f2ff8e6b1420300cf5db3/urllib3-1.26.3.tar.gz",
|
||||
"sha256": "de3eedaad74a2683334e282005cd8d7f22f4d55fa690a2a1020a416cb0a47e73"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/6b/47/c14abc08432ab22dc18b9892252efaf005ab44066de871e72a38d6af464b/requests-2.25.1.tar.gz",
|
||||
"sha256": "27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/03/23/5a59520207daae74b5c8d45cc80273c57ad6345761e841f118e0101d36e9/ytmusicapi-0.14.3.tar.gz",
|
||||
"sha256": "83251a95d5bd74116353d29dfda2d0c5055b88276a0876a313a66f8b9c691344"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
export GIT_CLONE_ARGS="--depth 1 --single-branch"
|
||||
export FLATPAK_DIR="$(readlink -f $(dirname $0))"
|
||||
cd ${FLATPAK_DIR}
|
||||
|
||||
if [ ! -d flatpak-builder-tools ]; then
|
||||
git clone ${GIT_CLONE_ARGS} https://github.com/flatpak/flatpak-builder-tools
|
||||
else
|
||||
git -C flatpak-builder-tools pull
|
||||
fi
|
||||
|
||||
./flatpak-builder-tools/pip/flatpak-pip-generator youtube_dl
|
||||
./flatpak-builder-tools/pip/flatpak-pip-generator ytmusicapi
|
||||
@@ -1,12 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<component type="desktop-application">
|
||||
<id>org.kde.audiotube</id>
|
||||
<name>AudioTube</name>
|
||||
<summary>Convergent YouTube Music client</summary>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<project_license>GPL-2.0+</project_license>
|
||||
<developer_name>KDE Community</developer_name>
|
||||
<name>Kirigami Application</name>
|
||||
<summary>A short summary describing what this software is about</summary>
|
||||
<metadata_license>A permissive license for this metadata, e.g. "FSFAP"</metadata_license>
|
||||
<project_license>The license of this software as SPDX string, e.g. "GPL-3+"</project_license>
|
||||
<developer_name>The software vendor name, e.g. "ACME Corporation"</developer_name>
|
||||
<description>
|
||||
<p>AudioTube can search YouTube Music, list albums and artists, play automatically generated playlists, albums and allows to put your own playlist together.</p>
|
||||
<p>Multiple paragraphs of long description, describing this software component.</p>
|
||||
<p>You can also use ordered and unordered lists:</p>
|
||||
<ul>
|
||||
<li>Feature 1</li>
|
||||
<li>Feature 2</li>
|
||||
</ul>
|
||||
<p>Keep in mind to XML-escape characters, and that this is not HTML markup.</p>
|
||||
</description>
|
||||
</component>
|
||||
@@ -1,9 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Name=AudioTube
|
||||
Comment=YouTube Music client
|
||||
Comment=youtube_music Kirigami Application
|
||||
Version=1.0
|
||||
Exec=audiotube
|
||||
Icon=org.kde.audiotube
|
||||
Icon=applications-development
|
||||
Type=Application
|
||||
Terminal=false
|
||||
Categories=Qt;KDE;
|
||||
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"id": "org.kde.audiotube",
|
||||
"runtime": "org.kde.Platform",
|
||||
"runtime-version": "5.15",
|
||||
"sdk": "org.kde.Sdk",
|
||||
"command": "audiotube",
|
||||
"tags": ["nightly"],
|
||||
"desktop-file-name-suffix": " (Nightly)",
|
||||
"finish-args": [
|
||||
"--share=ipc",
|
||||
"--share=network",
|
||||
"--socket=x11",
|
||||
"--socket=wayland",
|
||||
"--socket=pulseaudio",
|
||||
"--device=dri"
|
||||
],
|
||||
"separate-locales": false,
|
||||
|
||||
"modules": [
|
||||
"flatpak/python3-youtube_dl.json",
|
||||
"flatpak/python3-ytmusicapi.json",
|
||||
{
|
||||
"name": "pybind11",
|
||||
"config-opts": ["-DPYBIND11_FINDPYTHON=ON", "-DPYBIND11_TEST=OFF"],
|
||||
"buildsystem": "cmake-ninja",
|
||||
"builddir": true,
|
||||
"sources": [ { "type": "git", "url": "https://github.com/pybind/pybind11" } ]
|
||||
},
|
||||
{
|
||||
"name": "org.kde.audiotube",
|
||||
"config-opts": ["-DPYBIND11_FINDPYTHON=ON"],
|
||||
"buildsystem": "cmake-ninja",
|
||||
"builddir": true,
|
||||
"sources": [ { "type": "dir", "path": ".", "skip": [".git"] } ]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ add_executable(audiotube
|
||||
videoinfoextractor.cpp
|
||||
artistmodel.cpp
|
||||
playlistmodel.cpp
|
||||
errorhandler.cpp
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
|
||||
+6
-17
@@ -11,9 +11,9 @@ AlbumModel::AlbumModel(QObject *parent)
|
||||
{
|
||||
connect(this, &AlbumModel::browseIdChanged, this, [=] {
|
||||
setLoading(true);
|
||||
YTMusicThread::instance()->fetchAlbum(m_browseId);
|
||||
AsyncYTMusic::instance().fetchAlbum(m_browseId);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::fetchAlbumFinished, this, [=](const album::Album &album) {
|
||||
connect(&AsyncYTMusic::instance(), &AsyncYTMusic::fetchAlbumFinished, this, [=](const album::Album &album) {
|
||||
setLoading(false);
|
||||
|
||||
beginResetModel();
|
||||
@@ -25,30 +25,20 @@ AlbumModel::AlbumModel(QObject *parent)
|
||||
Q_EMIT thumbnailUrlChanged();
|
||||
Q_EMIT playlistIdChanged();
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [=] {
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
int AlbumModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : int(m_album.tracks.size());
|
||||
return parent.isValid() ? 0 : m_album.tracks.size();
|
||||
}
|
||||
|
||||
QVariant AlbumModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
switch (role) {
|
||||
case Title:
|
||||
return QString::fromStdString(m_album.tracks[index.row()].title);
|
||||
return QString::fromStdString(m_album.tracks.at(index.row()).title);
|
||||
case VideoId:
|
||||
return QString::fromStdString(m_album.tracks[index.row()].video_id.value_or(std::string()));
|
||||
case Artists:
|
||||
return QVariant::fromValue(std::vector<meta::Artist> {
|
||||
{
|
||||
m_album.tracks[index.row()].artists,
|
||||
std::nullopt
|
||||
}
|
||||
});
|
||||
return QString::fromStdString(m_album.tracks.at(index.row()).video_id.value_or(std::string()));
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
@@ -60,8 +50,7 @@ QHash<int, QByteArray> AlbumModel::roleNames() const
|
||||
{
|
||||
return {
|
||||
{Title, "title"},
|
||||
{VideoId, "videoId"},
|
||||
{Artists, "artists"}
|
||||
{VideoId, "videoId"}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -22,8 +22,7 @@ class AlbumModel : public QAbstractListModel
|
||||
public:
|
||||
enum Role {
|
||||
Title = Qt::UserRole + 1,
|
||||
VideoId,
|
||||
Artists
|
||||
VideoId
|
||||
};
|
||||
|
||||
explicit AlbumModel(QObject *parent = nullptr);
|
||||
@@ -51,7 +50,7 @@ public:
|
||||
|
||||
private:
|
||||
QString m_browseId;
|
||||
bool m_loading = false;
|
||||
bool m_loading;
|
||||
|
||||
album::Album m_album;
|
||||
};
|
||||
+3
-35
@@ -18,9 +18,9 @@ ArtistModel::ArtistModel(QObject *parent)
|
||||
|
||||
setLoading(true);
|
||||
|
||||
YTMusicThread::instance()->fetchArtist(m_channelId);
|
||||
AsyncYTMusic::instance().fetchArtist(m_channelId);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::fetchArtistFinished, this, [=](const artist::Artist &artist) {
|
||||
connect(&AsyncYTMusic::instance(), &AsyncYTMusic::fetchArtistFinished, this, [=](const artist::Artist &artist) {
|
||||
setLoading(false);
|
||||
|
||||
beginResetModel();
|
||||
@@ -31,9 +31,6 @@ ArtistModel::ArtistModel(QObject *parent)
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT thumbnailUrlChanged();
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [=] {
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -108,33 +105,6 @@ QVariant ArtistModel::data(const QModelIndex &index, int role) const
|
||||
} else {
|
||||
return Song;
|
||||
}
|
||||
case Artists:
|
||||
return QVariant::fromValue(std::vector<meta::Artist> {
|
||||
{
|
||||
m_artist.name,
|
||||
m_artist.channel_id
|
||||
}
|
||||
});
|
||||
case VideoId:
|
||||
if (index.row() >= countItems(m_artist.songs)
|
||||
+ countItems(m_artist.albums)
|
||||
+ countItems(m_artist.singles)) {
|
||||
|
||||
int videoIndex = index.row() - (countItems(m_artist.songs)
|
||||
+ countItems(m_artist.albums)
|
||||
+ countItems(m_artist.singles));
|
||||
|
||||
if (m_artist.videos.has_value()) {
|
||||
return QString::fromStdString(m_artist.videos.value().results[videoIndex].video_id);
|
||||
}
|
||||
break;
|
||||
} else if (index.row() >= countItems(m_artist.songs) + countItems(m_artist.albums)) {
|
||||
return QVariant();
|
||||
} else if (index.row() >= countItems(m_artist.songs)) {
|
||||
return QVariant();
|
||||
} else {
|
||||
return QString::fromStdString(m_artist.songs.value().results[index.row()].video_id);
|
||||
}
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
@@ -146,9 +116,7 @@ QHash<int, QByteArray> ArtistModel::roleNames() const
|
||||
{
|
||||
return {
|
||||
{Title, "title"},
|
||||
{Type, "type"},
|
||||
{Artists, "artists"},
|
||||
{VideoId, "videoId"}
|
||||
{Type, "type"}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -1,6 +1,6 @@
|
||||
// SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -30,9 +30,7 @@ public:
|
||||
|
||||
enum Role {
|
||||
Title,
|
||||
Type,
|
||||
Artists,
|
||||
VideoId
|
||||
Type
|
||||
};
|
||||
|
||||
explicit ArtistModel(QObject *parent = nullptr);
|
||||
|
||||
+46
-90
@@ -12,6 +12,11 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
static QThread *ytmthread = []() -> QThread * {
|
||||
auto *thread = new QThread();
|
||||
thread->setObjectName("YTMusicAPI");
|
||||
return thread;
|
||||
}();
|
||||
|
||||
AsyncYTMusic::AsyncYTMusic(QObject *parent)
|
||||
: QObject(parent)
|
||||
@@ -25,8 +30,6 @@ AsyncYTMusic::AsyncYTMusic(QObject *parent)
|
||||
qRegisterMetaType<video_info::VideoInfo>();
|
||||
qRegisterMetaType<watch::Playlist>();
|
||||
qRegisterMetaType<std::optional<QString>>();
|
||||
qRegisterMetaType<std::vector<meta::Artist>>();
|
||||
qRegisterMetaType<meta::Artist>();
|
||||
|
||||
connect(this, &AsyncYTMusic::startSearch, this, &AsyncYTMusic::internalSearch);
|
||||
connect(this, &AsyncYTMusic::startFetchArtist, this, &AsyncYTMusic::internalFetchArtist);
|
||||
@@ -36,10 +39,25 @@ AsyncYTMusic::AsyncYTMusic(QObject *parent)
|
||||
connect(this, &AsyncYTMusic::startFetchArtistAlbums, this, &AsyncYTMusic::internalFetchArtistAlbums);
|
||||
connect(this, &AsyncYTMusic::startExtractVideoInfo, this, &AsyncYTMusic::internalExtractVideoInfo);
|
||||
connect(this, &AsyncYTMusic::startFetchWatchPlaylist, this, &AsyncYTMusic::internalFetchWatchPlaylist);
|
||||
}
|
||||
|
||||
connect(this, &AsyncYTMusic::errorOccurred, this, [](const QString &err) {
|
||||
qDebug() << err;
|
||||
});
|
||||
AsyncYTMusic &AsyncYTMusic::instance()
|
||||
{
|
||||
static AsyncYTMusic &inst = []() -> AsyncYTMusic& {
|
||||
static AsyncYTMusic ytm;
|
||||
ytm.moveToThread(ytmthread);
|
||||
ytmthread->start();
|
||||
|
||||
return ytm;
|
||||
}();
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
void AsyncYTMusic::stopInstance()
|
||||
{
|
||||
ytmthread->quit();
|
||||
ytmthread->wait();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -52,11 +70,7 @@ void AsyncYTMusic::search(const QString &query)
|
||||
|
||||
void AsyncYTMusic::internalSearch(const QString &query)
|
||||
{
|
||||
try {
|
||||
Q_EMIT searchFinished(m_ytm->search(query.toStdString()));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
Q_EMIT searchFinished(m_ytdl.search(query.toStdString()));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -69,11 +83,7 @@ void AsyncYTMusic::fetchArtist(const QString &channelId)
|
||||
|
||||
void AsyncYTMusic::internalFetchArtist(const QString &channelId)
|
||||
{
|
||||
try {
|
||||
Q_EMIT fetchArtistFinished(m_ytm->get_artist(channelId.toStdString()));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
Q_EMIT fetchArtistFinished(m_ytdl.get_artist(channelId.toStdString()));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -86,11 +96,7 @@ void AsyncYTMusic::fetchAlbum(const QString &browseId)
|
||||
|
||||
void AsyncYTMusic::internalFetchAlbum(const QString &browseId)
|
||||
{
|
||||
try {
|
||||
Q_EMIT fetchAlbumFinished(m_ytm->get_album(browseId.toStdString()));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
Q_EMIT fetchAlbumFinished(m_ytdl.get_album(browseId.toStdString()));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -103,11 +109,7 @@ void AsyncYTMusic::fetchSong(const QString &videoId)
|
||||
|
||||
void AsyncYTMusic::internalFetchSong(const QString &videoId)
|
||||
{
|
||||
try {
|
||||
Q_EMIT fetchSongFinished(m_ytm->get_song(videoId.toStdString()));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
Q_EMIT fetchSongFinished(m_ytdl.get_song(videoId.toStdString()));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -119,11 +121,7 @@ void AsyncYTMusic::fetchPlaylist(const QString &playlistId) {
|
||||
|
||||
void AsyncYTMusic::internalFetchPlaylist(const QString &playlistId)
|
||||
{
|
||||
try {
|
||||
Q_EMIT fetchPlaylistFinished(m_ytm->get_playlist(playlistId.toStdString()));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
Q_EMIT fetchPlaylistFinished(m_ytdl.get_playlist(playlistId.toStdString()));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -136,28 +134,19 @@ void AsyncYTMusic::fetchArtistAlbums(const QString &channelId, const QString &pa
|
||||
|
||||
void AsyncYTMusic::internalFetchArtistAlbums(const QString &channelid, const QString ¶ms)
|
||||
{
|
||||
try {
|
||||
Q_EMIT fetchArtistAlbumsFinished(m_ytm->get_artist_albums(channelid.toStdString(), params.toStdString()));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
Q_EMIT fetchArtistAlbumsFinished(m_ytdl.get_artist_albums(channelid.toStdString(), params.toStdString()));
|
||||
}
|
||||
|
||||
//
|
||||
// extractVideoInfo
|
||||
//
|
||||
void AsyncYTMusic::extractVideoInfo(const QString &videoId)
|
||||
{
|
||||
void AsyncYTMusic::extractVideoInfo(const QString &videoId) {
|
||||
qDebug() << "extract video " << videoId;
|
||||
Q_EMIT startExtractVideoInfo(videoId);
|
||||
}
|
||||
|
||||
void AsyncYTMusic::internalExtractVideoInfo(const QString &videoId)
|
||||
{
|
||||
try {
|
||||
Q_EMIT extractVideoInfoFinished(m_ytm->extract_video_info(videoId.toStdString()));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
void AsyncYTMusic::internalExtractVideoInfo(const QString &videoId) {
|
||||
Q_EMIT extractVideoInfoFinished(m_ytdl.extract_video_info(videoId.toStdString()));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -170,52 +159,19 @@ void AsyncYTMusic::fetchWatchPlaylist(const std::optional<QString> &videoId, con
|
||||
|
||||
void AsyncYTMusic::internalFetchWatchPlaylist(const std::optional<QString> &videoId, const std::optional<QString> &playlistId)
|
||||
{
|
||||
try {
|
||||
Q_EMIT fetchWatchPlaylistFinished(m_ytm->get_watch_playlist(
|
||||
[&]() -> std::optional<std::string> {
|
||||
if (!videoId.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
Q_EMIT fetchWatchPlaylistFinished(m_ytdl.get_watch_playlist(
|
||||
[&]() -> std::optional<std::string> {
|
||||
if (!videoId.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return videoId->toStdString();
|
||||
}(),
|
||||
[&]() -> std::optional<std::string> {
|
||||
if (!playlistId.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return videoId->toStdString();
|
||||
}(),
|
||||
[&]() -> std::optional<std::string> {
|
||||
if (!playlistId.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return playlistId->toStdString();
|
||||
}()));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
}
|
||||
|
||||
YTMusicThread &YTMusicThread::instance()
|
||||
{
|
||||
static YTMusicThread thread;
|
||||
return thread;
|
||||
}
|
||||
|
||||
YTMusicThread::~YTMusicThread()
|
||||
{
|
||||
quit();
|
||||
wait();
|
||||
}
|
||||
|
||||
AsyncYTMusic *YTMusicThread::operator->()
|
||||
{
|
||||
return &m_ytm;
|
||||
}
|
||||
|
||||
AsyncYTMusic &YTMusicThread::get()
|
||||
{
|
||||
return m_ytm;
|
||||
}
|
||||
|
||||
YTMusicThread::YTMusicThread()
|
||||
{
|
||||
setObjectName(QStringLiteral("YTMusicAPI"));
|
||||
m_ytm.moveToThread(this);
|
||||
start();
|
||||
return playlistId->toStdString();
|
||||
}()));
|
||||
}
|
||||
+12
-44
@@ -20,37 +20,23 @@ Q_DECLARE_METATYPE(playlist::Playlist)
|
||||
Q_DECLARE_METATYPE(video_info::VideoInfo)
|
||||
Q_DECLARE_METATYPE(watch::Playlist)
|
||||
Q_DECLARE_METATYPE(std::optional<QString>)
|
||||
Q_DECLARE_METATYPE(std::vector<meta::Artist>)
|
||||
Q_DECLARE_METATYPE(meta::Artist)
|
||||
|
||||
///
|
||||
/// Lazy initialized unique_ptr
|
||||
///
|
||||
template <class T>
|
||||
class Lazy {
|
||||
public:
|
||||
T *operator->() {
|
||||
return get().operator->();
|
||||
}
|
||||
|
||||
inline std::unique_ptr<T> &get() {
|
||||
if (!m_item) {
|
||||
m_item = std::make_unique<T>();
|
||||
}
|
||||
return m_item;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<T> m_item = nullptr;
|
||||
};
|
||||
|
||||
class AsyncYTMusic : public QObject
|
||||
{
|
||||
friend class YTMusicThread;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AsyncYTMusic(QObject *parent = nullptr);
|
||||
|
||||
///
|
||||
/// Singleton instance of AsyncYtMusic running on it's own thread.
|
||||
///
|
||||
/// It is necessary t call stopInstance before the application exits,
|
||||
/// so the thread can properly finish.
|
||||
///
|
||||
static AsyncYTMusic &instance();
|
||||
static void stopInstance();
|
||||
|
||||
// public functions need to be thread safe
|
||||
void search(const QString &query);
|
||||
Q_SIGNAL void searchFinished(std::vector<search::SearchResultItem>);
|
||||
@@ -79,9 +65,6 @@ public:
|
||||
|
||||
Q_SIGNAL void errorOccurred(const QString &error);
|
||||
|
||||
protected:
|
||||
explicit AsyncYTMusic(QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
Q_SIGNAL void startSearch(const QString &query);
|
||||
Q_SLOT void internalSearch(const QString &query);
|
||||
@@ -107,20 +90,5 @@ private:
|
||||
Q_SIGNAL void startFetchWatchPlaylist(const std::optional<QString> &videoId, const std::optional<QString> &playlistId);
|
||||
Q_SLOT void internalFetchWatchPlaylist(const std::optional<QString> &videoId, const std::optional<QString> &playlistId);
|
||||
|
||||
// Python interpreter will be ininitalized from the thread calling the methods
|
||||
Lazy<YTMusic> m_ytm;
|
||||
};
|
||||
|
||||
class YTMusicThread : private QThread {
|
||||
public:
|
||||
static YTMusicThread &instance();
|
||||
~YTMusicThread();
|
||||
|
||||
AsyncYTMusic *operator->();
|
||||
AsyncYTMusic &get();
|
||||
|
||||
private:
|
||||
YTMusicThread();
|
||||
|
||||
AsyncYTMusic m_ytm;
|
||||
YTMusic m_ytdl;
|
||||
};
|
||||
@@ -28,40 +28,12 @@ Kirigami.ScrollablePage {
|
||||
model: AlbumModel {
|
||||
id: albumModel
|
||||
}
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
id: delegateItem
|
||||
|
||||
delegate: Kirigami.BasicListItem {
|
||||
required property string title
|
||||
required property string videoId
|
||||
required property var artists
|
||||
|
||||
RowLayout {
|
||||
Layout.fillHeight: true
|
||||
Kirigami.Icon {
|
||||
Layout.fillHeight: true
|
||||
source: "emblem-music-symbolic"
|
||||
}
|
||||
|
||||
Controls.Label {
|
||||
Layout.fillWidth: true
|
||||
text: title
|
||||
elide: Qt.ElideRight
|
||||
}
|
||||
}
|
||||
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
icon.name: "go-next"
|
||||
text: i18n("Play next")
|
||||
onTriggered: PlaylistModel.playNext(delegateItem.videoId, delegateItem.title, delegateItem.artists)
|
||||
},
|
||||
Kirigami.Action {
|
||||
icon.name: "media-playlist-append"
|
||||
text: i18n("Add to playlist")
|
||||
onTriggered: PlaylistModel.append(delegateItem.videoId, delegateItem.title, delegateItem.artists)
|
||||
}
|
||||
]
|
||||
|
||||
icon: "emblem-music-symbolic"
|
||||
text: title
|
||||
onClicked: play(videoId)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,54 +47,23 @@ Kirigami.ScrollablePage {
|
||||
}
|
||||
}
|
||||
}
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
id: delegateItem
|
||||
|
||||
delegate: Kirigami.BasicListItem {
|
||||
required property string title
|
||||
required property int type
|
||||
required property int index
|
||||
required property var artists
|
||||
required property string videoId
|
||||
|
||||
RowLayout {
|
||||
Layout.fillHeight: true
|
||||
Kirigami.Icon {
|
||||
Layout.fillHeight: true
|
||||
source: {
|
||||
switch (type) {
|
||||
case ArtistModel.Album:
|
||||
return "media-album-cover"
|
||||
case ArtistModel.Single:
|
||||
case ArtistModel.Song:
|
||||
return "emblem-music-symbolic"
|
||||
case ArtistModel.Video:
|
||||
return "emblem-videos-symbolic"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controls.Label {
|
||||
Layout.fillWidth: true
|
||||
text: title
|
||||
elide: Qt.ElideRight
|
||||
text: title
|
||||
icon: {
|
||||
switch (type) {
|
||||
case ArtistModel.Album:
|
||||
return "media-album-cover"
|
||||
case ArtistModel.Single:
|
||||
case ArtistModel.Song:
|
||||
return "emblem-music-symbolic"
|
||||
case ArtistModel.Video:
|
||||
return "emblem-videos-symbolic"
|
||||
}
|
||||
}
|
||||
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
icon.name: "go-next"
|
||||
text: i18n("Play next")
|
||||
visible: type == ArtistModel.Song
|
||||
onTriggered: PlaylistModel.playNext(delegateItem.videoId, delegateItem.title, delegateItem.artists)
|
||||
},
|
||||
Kirigami.Action {
|
||||
icon.name: "media-playlist-append"
|
||||
text: i18n("Add to playlist")
|
||||
visible: type == ArtistModel.Song
|
||||
onTriggered: PlaylistModel.append(delegateItem.videoId, delegateItem.title, delegateItem.artists)
|
||||
}
|
||||
]
|
||||
|
||||
onClicked: artistModel.triggerItem(index)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,116 +1,81 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Layouts 1.3
|
||||
|
||||
import QtQuick.Controls 2.12 as Controls
|
||||
import org.kde.kirigami 2.12 as Kirigami
|
||||
|
||||
import org.kde.ytmusic 1.0
|
||||
|
||||
import QtMultimedia 5.12
|
||||
|
||||
ColumnLayout {
|
||||
id: footerLayout
|
||||
|
||||
// input only
|
||||
property alias videoId: playlistModel.initialVideoId
|
||||
property alias playlistId: playlistModel.playlistId
|
||||
|
||||
property bool maximized: false
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: maximized ? applicationWindow().height : player.preferredHeight
|
||||
|
||||
GridLayout {
|
||||
id: playerLayout
|
||||
|
||||
readonly property bool mobile: width > height
|
||||
Image {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
source: info.thumbnail
|
||||
}
|
||||
|
||||
Controls.ScrollView {
|
||||
Layout.fillHeight: footerLayout.maximized
|
||||
Layout.fillWidth: true
|
||||
flow: width > height ? GridLayout.LeftToRight : GridLayout.TopToBottom
|
||||
visible: footerLayout.maximized
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.preferredWidth: !playerLayout.mobile && playerLayout.width * 0.5
|
||||
Layout.preferredHeight: playerLayout.mobile && playerLayout.height * 0.5
|
||||
ListView {
|
||||
id: playlistView
|
||||
anchors.fill: parent
|
||||
|
||||
Image {
|
||||
source: info.thumbnail
|
||||
anchors.fill: parent
|
||||
fillMode: Image.PreserveAspectFit
|
||||
model: PlaylistModel {
|
||||
id: playlistModel
|
||||
}
|
||||
delegate: Kirigami.BasicListItem {
|
||||
required property string title
|
||||
required property string videoId
|
||||
required property string artists
|
||||
required property bool isCurrent
|
||||
|
||||
highlighted: isCurrent
|
||||
|
||||
onClicked: playlistModel.skipTo(videoId)
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
|
||||
Kirigami.Heading {
|
||||
Layout.fillWidth: true
|
||||
|
||||
level: 2
|
||||
text: title
|
||||
}
|
||||
Controls.Label {
|
||||
Layout.fillWidth: true
|
||||
|
||||
text: artists
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controls.BusyIndicator {
|
||||
anchors.centerIn: parent
|
||||
visible: playlistModel.loading || playlistModel.loading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controls.ScrollView {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.preferredWidth: !playerLayout.mobile && playerLayout.width * 0.5
|
||||
Layout.preferredHeight: playerLayout.mobile && playerLayout.height * 0.5
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
|
||||
ListView {
|
||||
anchors.fill: parent
|
||||
id: playlistView
|
||||
|
||||
clip: true
|
||||
|
||||
Controls.BusyIndicator {
|
||||
anchors.centerIn: parent
|
||||
visible: PlaylistModel.loading || PlaylistModel.loading
|
||||
}
|
||||
|
||||
onCountChanged: {
|
||||
if (count < 1) {
|
||||
footerLayout.maximized = false
|
||||
}
|
||||
}
|
||||
|
||||
model: PlaylistModel
|
||||
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
id: delegateItem
|
||||
required property string title
|
||||
required property string videoId
|
||||
required property string artists
|
||||
required property bool isCurrent
|
||||
|
||||
highlighted: isCurrent
|
||||
onClicked: PlaylistModel.skipTo(videoId)
|
||||
|
||||
ColumnLayout {
|
||||
Kirigami.Heading {
|
||||
Layout.fillWidth: true
|
||||
level: 2
|
||||
text: title
|
||||
}
|
||||
|
||||
Controls.Label {
|
||||
Layout.fillWidth: true
|
||||
text: artists
|
||||
}
|
||||
}
|
||||
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
text: i18n("Remove track")
|
||||
icon.name: "list-remove"
|
||||
onTriggered: PlaylistModel.remove(delegateItem.videoId)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
header: Controls.ToolBar {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
icon.name: "edit-clear-all"
|
||||
onClicked: PlaylistModel.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,19 +91,19 @@ ColumnLayout {
|
||||
|
||||
VideoInfoExtractor {
|
||||
id: info
|
||||
|
||||
onSongChanged: audio.play()
|
||||
videoId: PlaylistModel.currentVideoId
|
||||
videoId: playlistModel.currentVideoId
|
||||
}
|
||||
|
||||
Audio {
|
||||
id: audio
|
||||
|
||||
source: info.audioUrl
|
||||
|
||||
|
||||
onStatusChanged: {
|
||||
if (status === Audio.EndOfMedia) {
|
||||
console.log("Song ended");
|
||||
PlaylistModel.next();
|
||||
console.log("Song ended")
|
||||
playlistModel.next()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,9 +112,13 @@ ColumnLayout {
|
||||
display: Controls.AbstractButton.IconOnly
|
||||
Layout.preferredWidth: parent.height
|
||||
Layout.fillHeight: true
|
||||
enabled: info.audioUrl !== ""
|
||||
text: audio.playbackState === Audio.PlayingState ? i18n("Pause") : i18n("Play")
|
||||
|
||||
enabled: info.audioUrl != ""
|
||||
|
||||
text: audio.playbackState === Audio.PlayingState ? i18n("Pause") : i18n("Play")
|
||||
|
||||
visible: !info.loading
|
||||
|
||||
icon.name: audio.playbackState === Audio.PlayingState ? "media-playback-pause" : "media-playback-start"
|
||||
onClicked: audio.playbackState === Audio.PlayingState ? audio.pause() : audio.play()
|
||||
}
|
||||
@@ -158,10 +127,13 @@ ColumnLayout {
|
||||
display: Controls.AbstractButton.IconOnly
|
||||
Layout.preferredWidth: parent.height
|
||||
Layout.fillHeight: true
|
||||
enabled: PlaylistModel.canSkip
|
||||
|
||||
enabled: playlistView.count > 1
|
||||
|
||||
visible: !info.loading
|
||||
|
||||
icon.name: "media-skip-forward"
|
||||
onClicked: PlaylistModel.next()
|
||||
onClicked: playlistModel.next()
|
||||
}
|
||||
|
||||
Controls.BusyIndicator {
|
||||
@@ -171,53 +143,45 @@ ColumnLayout {
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillHeight: true
|
||||
Layout.topMargin: Kirigami.Units.smallSpacing
|
||||
Layout.bottomMargin: Kirigami.Units.smallSpacing
|
||||
Layout.topMargin: Kirigami.Units.largeSpacing
|
||||
Layout.bottomMargin: Kirigami.Units.largeSpacing
|
||||
|
||||
Kirigami.Heading {
|
||||
level: 3
|
||||
Layout.fillWidth: true
|
||||
elide: Qt.ElideRight
|
||||
level: 2
|
||||
text: info.title ? info.title : i18n("No media playing")
|
||||
}
|
||||
|
||||
Controls.Slider {
|
||||
Layout.fillWidth: true
|
||||
|
||||
from: 0
|
||||
to: audio.duration
|
||||
value: audio.position
|
||||
|
||||
enabled: audio.seekable
|
||||
onMoved: {
|
||||
console.log("Value:", value);
|
||||
audio.seek(Math.floor(value));
|
||||
console.log("Value:", value)
|
||||
audio.seek(Math.floor(value))
|
||||
}
|
||||
|
||||
Behavior on value {
|
||||
NumberAnimation {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
display: Controls.AbstractButton.IconOnly
|
||||
Layout.preferredWidth: parent.height
|
||||
|
||||
text: i18n("Expand")
|
||||
enabled: playlistView.count > 0
|
||||
|
||||
Layout.fillHeight: true
|
||||
icon.name: footerLayout.maximized ? "arrow-down" : "arrow-up"
|
||||
onClicked: footerLayout.maximized = !footerLayout.maximized
|
||||
icon.name: footer.maximized ? "arrow-down" : "arrow-up"
|
||||
|
||||
onClicked: footer.maximized = !footer.maximized
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtQuick.Controls 2.14 as Controls
|
||||
import org.kde.kirigami 2.14 as Kirigami
|
||||
|
||||
import org.kde.ytmusic 1.0
|
||||
|
||||
Kirigami.ScrollablePage {
|
||||
title: i18n("Youtube Music")
|
||||
|
||||
header: Controls.Control {
|
||||
padding: Kirigami.Units.largeSpacing
|
||||
contentItem: Kirigami.SearchField {
|
||||
onAccepted: {
|
||||
searchModel.searchQuery = text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
model: SearchModel {
|
||||
id: searchModel
|
||||
|
||||
onOpenAlbum: (browseId) => {
|
||||
pageStack.push("qrc:/AlbumPage.qml", {
|
||||
"browseId": browseId
|
||||
})
|
||||
}
|
||||
|
||||
onOpenArtist: (channelId) => {
|
||||
pageStack.push("qrc:/ArtistPage.qml", {
|
||||
"channelId": channelId
|
||||
})
|
||||
}
|
||||
|
||||
onOpenPlaylist: (browseId) => {
|
||||
|
||||
}
|
||||
|
||||
onOpenSong: (videoId) => {
|
||||
play(videoId)
|
||||
}
|
||||
|
||||
onOpenVideo: (videoId) => {
|
||||
|
||||
}
|
||||
}
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
id: delegateItem
|
||||
required property int index
|
||||
required property string title
|
||||
required property int type
|
||||
required property string videoId
|
||||
required property var artists
|
||||
|
||||
RowLayout {
|
||||
Layout.fillHeight: true
|
||||
Kirigami.Icon {
|
||||
Layout.fillHeight: true
|
||||
source: {
|
||||
switch (type) {
|
||||
case SearchModel.Artist:
|
||||
return "view-media-artist"
|
||||
case SearchModel.Album:
|
||||
return "media-album-cover"
|
||||
case SearchModel.Playlist:
|
||||
return "view-media-playlist"
|
||||
case SearchModel.Song:
|
||||
return "emblem-music-symbolic"
|
||||
case SearchModel.Video:
|
||||
return "emblem-videos-symbolic"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controls.Label {
|
||||
Layout.fillWidth: true
|
||||
text: title
|
||||
elide: Qt.ElideRight
|
||||
}
|
||||
}
|
||||
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
icon.name: "go-next"
|
||||
text: i18n("Play next")
|
||||
visible: type === SearchModel.Song
|
||||
onTriggered: PlaylistModel.playNext(delegateItem.videoId, delegateItem.title, delegateItem.artists)
|
||||
},
|
||||
Kirigami.Action {
|
||||
icon.name: "media-playlist-append"
|
||||
text: i18n("Add to playlist")
|
||||
visible: type === SearchModel.Song
|
||||
onTriggered: PlaylistModel.append(delegateItem.videoId, delegateItem.title, delegateItem.artists)
|
||||
}
|
||||
]
|
||||
|
||||
onClicked: searchModel.triggerItem(index)
|
||||
}
|
||||
Controls.BusyIndicator {
|
||||
anchors.centerIn: parent
|
||||
visible: searchModel.loading
|
||||
}
|
||||
}
|
||||
}
|
||||
+73
-13
@@ -1,5 +1,7 @@
|
||||
import QtQuick 2.1
|
||||
import org.kde.kirigami 2.14 as Kirigami
|
||||
import QtQuick.Controls 2.14 as Controls
|
||||
import QtQuick.Layouts 1.3
|
||||
|
||||
import org.kde.ytmusic 1.0
|
||||
|
||||
@@ -8,28 +10,86 @@ Kirigami.ApplicationWindow {
|
||||
|
||||
title: i18n("AudioTube")
|
||||
|
||||
controlsVisible: !footer.maximized
|
||||
|
||||
contextDrawer: Kirigami.ContextDrawer {
|
||||
id: contextDrawer
|
||||
}
|
||||
|
||||
pageStack.initialPage: "qrc:/SearchPage.qml"
|
||||
pageStack.initialPage: Kirigami.ScrollablePage {
|
||||
title: i18n("Youtube Music")
|
||||
|
||||
header: Controls.Control {
|
||||
padding: Kirigami.Units.largeSpacing
|
||||
contentItem: Kirigami.SearchField {
|
||||
onAccepted: {
|
||||
searchModel.searchQuery = text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
model: SearchModel {
|
||||
id: searchModel
|
||||
|
||||
onOpenAlbum: (browseId) => {
|
||||
pageStack.push("qrc:/AlbumPage.qml", {
|
||||
"browseId": browseId
|
||||
})
|
||||
}
|
||||
|
||||
onOpenArtist: (channelId) => {
|
||||
pageStack.push("qrc:/ArtistPage.qml", {
|
||||
"channelId": channelId
|
||||
})
|
||||
}
|
||||
|
||||
onOpenPlaylist: (browseId) => {
|
||||
|
||||
}
|
||||
|
||||
onOpenSong: (videoId) => {
|
||||
play(videoId)
|
||||
}
|
||||
|
||||
onOpenVideo: (videoId) => {
|
||||
|
||||
}
|
||||
}
|
||||
delegate: Kirigami.BasicListItem {
|
||||
required property int index
|
||||
required property string title
|
||||
required property int type
|
||||
|
||||
text: title
|
||||
icon: {
|
||||
switch (type) {
|
||||
case SearchModel.Artist:
|
||||
return "view-media-artist"
|
||||
case SearchModel.Album:
|
||||
return "media-album-cover"
|
||||
case SearchModel.Playlist:
|
||||
return "view-media-playlist"
|
||||
case SearchModel.Song:
|
||||
return "emblem-music-symbolic"
|
||||
case SearchModel.Video:
|
||||
return "emblem-videos-symbolic"
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: searchModel.triggerItem(index)
|
||||
}
|
||||
Controls.BusyIndicator {
|
||||
anchors.centerIn: parent
|
||||
visible: searchModel.loading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function play(videoId) {
|
||||
PlaylistModel.initialVideoId = videoId
|
||||
footer.videoId = videoId
|
||||
}
|
||||
|
||||
function playPlaylist(playlistId) {
|
||||
PlaylistModel.playlistId = playlistId
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: ErrorHandler
|
||||
|
||||
function onErrorOccurred(error) {
|
||||
showPassiveNotification(error)
|
||||
}
|
||||
footer.playlistId = playlistId
|
||||
}
|
||||
|
||||
footer: PlayerFooter {}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "errorhandler.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
ErrorHandler::ErrorHandler(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, &ErrorHandler::errorOccurred);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "asyncytmusic.h"
|
||||
|
||||
class ErrorHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ErrorHandler(QObject *parent = nullptr);
|
||||
|
||||
Q_SIGNAL void errorOccurred(const QString &error);
|
||||
};
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
int main() {
|
||||
const auto ytm = YTMusic();
|
||||
const auto results = ytm.search("Leoniden Iron Tusk");
|
||||
const auto results = ytm.search("Syd Matters");
|
||||
|
||||
std::cout << "Found " << results.size() << " results." << std::endl;
|
||||
|
||||
@@ -17,12 +17,7 @@ int main() {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, search::Album>) {
|
||||
std::cout << arg.title << std::endl;
|
||||
const album::Album album = ytm.get_album(arg.browse_id);
|
||||
for (const auto &track : album.tracks) {
|
||||
if (track.video_id.has_value()) {
|
||||
ytm.extract_video_info(*track.video_id);
|
||||
}
|
||||
}
|
||||
ytm.get_album(arg.browse_id);
|
||||
} else if constexpr (std::is_same_v<T, search::Artist>) {
|
||||
std::cout << arg.artist << std::endl;
|
||||
const artist::Artist artist = ytm.get_artist(arg.browse_id);
|
||||
|
||||
+7
-11
@@ -13,7 +13,6 @@
|
||||
#include "videoinfoextractor.h"
|
||||
#include "artistmodel.h"
|
||||
#include "playlistmodel.h"
|
||||
#include "errorhandler.h"
|
||||
|
||||
constexpr auto URI = "org.kde.ytmusic";
|
||||
|
||||
@@ -21,9 +20,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QApplication app(argc, argv);
|
||||
QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
|
||||
QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("audiotube"));
|
||||
QCoreApplication::setOrganizationName("KDE");
|
||||
QCoreApplication::setOrganizationDomain("kde.org");
|
||||
QCoreApplication::setApplicationName("audiotube");
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
@@ -31,12 +30,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
qmlRegisterType<AlbumModel>(URI, 1, 0, "AlbumModel");
|
||||
qmlRegisterType<VideoInfoExtractor>(URI, 1, 0, "VideoInfoExtractor");
|
||||
qmlRegisterType<ArtistModel>(URI, 1, 0, "ArtistModel");
|
||||
qmlRegisterSingletonType<PlaylistModel>(URI, 1, 0, "PlaylistModel", [](QQmlEngine *, QJSEngine *) {
|
||||
return new PlaylistModel();
|
||||
});
|
||||
qmlRegisterSingletonType<ErrorHandler>(URI, 1, 0, "ErrorHandler", [](QQmlEngine *, QJSEngine *) {
|
||||
return new ErrorHandler();
|
||||
});
|
||||
qmlRegisterType<PlaylistModel>(URI, 1, 0, "PlaylistModel");
|
||||
|
||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
||||
@@ -45,5 +39,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
int ret = app.exec();
|
||||
AsyncYTMusic::stopInstance();
|
||||
return ret;
|
||||
}
|
||||
+10
-105
@@ -15,7 +15,7 @@ PlaylistModel::PlaylistModel(QObject *parent)
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
YTMusicThread::instance()->fetchWatchPlaylist(m_initialVideoId);
|
||||
AsyncYTMusic::instance().fetchWatchPlaylist(m_initialVideoId);
|
||||
});
|
||||
connect(this, &PlaylistModel::playlistIdChanged, this, [=] {
|
||||
if (m_playlistId.isEmpty()) {
|
||||
@@ -23,9 +23,9 @@ PlaylistModel::PlaylistModel(QObject *parent)
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
YTMusicThread::instance()->fetchWatchPlaylist(std::nullopt, m_playlistId);
|
||||
AsyncYTMusic::instance().fetchWatchPlaylist(std::nullopt, m_playlistId);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::fetchWatchPlaylistFinished, this, [=](const watch::Playlist &playlist) {
|
||||
connect(&AsyncYTMusic::instance(), &AsyncYTMusic::fetchWatchPlaylistFinished, this, [=](const watch::Playlist &playlist) {
|
||||
setLoading(false);
|
||||
|
||||
beginResetModel();
|
||||
@@ -35,16 +35,13 @@ PlaylistModel::PlaylistModel(QObject *parent)
|
||||
}
|
||||
endResetModel();
|
||||
|
||||
Q_EMIT currentVideoIdChanged();
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [=] {
|
||||
setLoading(false);
|
||||
currentVideoIdChanged();
|
||||
});
|
||||
}
|
||||
|
||||
int PlaylistModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : int(m_playlist.tracks.size());
|
||||
return parent.isValid() ? 0 : m_playlist.tracks.size();
|
||||
}
|
||||
|
||||
QVariant PlaylistModel::data(const QModelIndex &index, int role) const
|
||||
@@ -60,7 +57,7 @@ QVariant PlaylistModel::data(const QModelIndex &index, int role) const
|
||||
std::transform(artists.begin(), artists.end(), std::back_inserter(artistNames), [](const meta::Artist &artist) {
|
||||
return QString::fromStdString(artist.name);
|
||||
});
|
||||
return artistNames.join(QStringLiteral(", "));
|
||||
return artistNames.join(", ");
|
||||
}
|
||||
case IsCurrent:
|
||||
return m_playlist.tracks[index.row()].video_id == m_currentVideoId.toStdString();
|
||||
@@ -128,25 +125,14 @@ void PlaylistModel::setCurrentVideoId(const QString &videoId)
|
||||
m_currentVideoId = videoId;
|
||||
emitCurrentVideoChanged(old);
|
||||
Q_EMIT currentVideoIdChanged();
|
||||
Q_EMIT canSkipChanged();
|
||||
}
|
||||
|
||||
bool PlaylistModel::canSkip() const
|
||||
{
|
||||
const auto currentTrackIt = std::find_if(m_playlist.tracks.begin(), m_playlist.tracks.end(),
|
||||
[=](const watch::Playlist::Track &track) {
|
||||
return track.video_id == m_currentVideoId.toStdString();
|
||||
});
|
||||
|
||||
return currentTrackIt != m_playlist.tracks.end() - 1 && !m_playlist.tracks.empty();
|
||||
}
|
||||
|
||||
void PlaylistModel::next()
|
||||
{
|
||||
const auto old = m_currentVideoId;
|
||||
setCurrentVideoId(nextVideoId());
|
||||
m_currentVideoId = nextVideoId();
|
||||
emitCurrentVideoChanged(old);
|
||||
Q_EMIT currentVideoIdChanged();
|
||||
Q_EMIT canSkipChanged();
|
||||
}
|
||||
|
||||
void PlaylistModel::skipTo(const QString &videoId)
|
||||
@@ -155,87 +141,6 @@ void PlaylistModel::skipTo(const QString &videoId)
|
||||
m_currentVideoId = videoId;
|
||||
emitCurrentVideoChanged(old);
|
||||
Q_EMIT currentVideoIdChanged();
|
||||
Q_EMIT canSkipChanged();
|
||||
}
|
||||
|
||||
void PlaylistModel::playNext(const QString &videoId, const QString &title, const std::vector<meta::Artist> &artists)
|
||||
{
|
||||
const auto currentIt = std::find_if(m_playlist.tracks.begin(), m_playlist.tracks.end(),
|
||||
[=](const watch::Playlist::Track &track) {
|
||||
return track.video_id == m_currentVideoId.toStdString();
|
||||
});
|
||||
|
||||
watch::Playlist::Track track;
|
||||
track.video_id = videoId.toStdString();
|
||||
track.title = title.toStdString();
|
||||
track.artists = artists;
|
||||
|
||||
if (currentIt == m_playlist.tracks.end() || m_playlist.tracks.empty()) {
|
||||
beginInsertRows({}, 0, 0);
|
||||
m_playlist.tracks.push_back(std::move(track));
|
||||
endInsertRows();
|
||||
setCurrentVideoId(videoId);
|
||||
Q_EMIT canSkipChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentIt == m_playlist.tracks.end() - 1) {
|
||||
int index = std::distance(m_playlist.tracks.begin(), currentIt + 1);
|
||||
beginInsertRows({}, index, index);
|
||||
m_playlist.tracks.push_back(std::move(track));
|
||||
endInsertRows();
|
||||
Q_EMIT canSkipChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
int index = std::distance(m_playlist.tracks.begin(), currentIt + 1);
|
||||
beginInsertRows({}, index, index);
|
||||
m_playlist.tracks.insert(currentIt + 1, std::move(track));
|
||||
endInsertRows();
|
||||
Q_EMIT canSkipChanged();
|
||||
}
|
||||
|
||||
void PlaylistModel::append(const QString &videoId, const QString &title, const std::vector<meta::Artist> &artists)
|
||||
{
|
||||
watch::Playlist::Track track;
|
||||
track.video_id = videoId.toStdString();
|
||||
track.title = title.toStdString();
|
||||
track.artists = artists;
|
||||
|
||||
beginInsertRows({}, m_playlist.tracks.size(), m_playlist.tracks.size());
|
||||
m_playlist.tracks.push_back(std::move(track));
|
||||
endInsertRows();
|
||||
|
||||
if (m_playlist.tracks.size() == 1) {
|
||||
setCurrentVideoId(videoId);
|
||||
}
|
||||
}
|
||||
|
||||
void PlaylistModel::clear()
|
||||
{
|
||||
beginResetModel();
|
||||
m_playlist.tracks.clear();
|
||||
endResetModel();
|
||||
|
||||
setCurrentVideoId({});
|
||||
Q_EMIT canSkipChanged();
|
||||
}
|
||||
|
||||
void PlaylistModel::remove(const QString &videoId)
|
||||
{
|
||||
if (m_currentVideoId == videoId) {
|
||||
setCurrentVideoId(nextVideoId());
|
||||
}
|
||||
|
||||
const auto trackIt = std::find_if(m_playlist.tracks.begin(), m_playlist.tracks.end(), [&](const watch::Playlist::Track &track) {
|
||||
return track.video_id == videoId.toStdString();
|
||||
});
|
||||
int index = std::distance(m_playlist.tracks.begin(), trackIt);
|
||||
beginRemoveRows({}, index, index);
|
||||
m_playlist.tracks.erase(trackIt);
|
||||
endRemoveRows();
|
||||
|
||||
Q_EMIT canSkipChanged();
|
||||
}
|
||||
|
||||
void PlaylistModel::emitCurrentVideoChanged(const QString &oldVideoId)
|
||||
@@ -252,8 +157,8 @@ void PlaylistModel::emitCurrentVideoChanged(const QString &oldVideoId)
|
||||
int oldIndex = std::distance(m_playlist.tracks.begin(), oldVideoIt);
|
||||
int newIndex = std::distance(m_playlist.tracks.begin(), currentVideoIt);
|
||||
|
||||
Q_EMIT dataChanged(index(oldIndex), index(oldIndex), {IsCurrent});
|
||||
Q_EMIT dataChanged(index(newIndex), index(newIndex), {IsCurrent});
|
||||
dataChanged(index(oldIndex), index(oldIndex), {IsCurrent});
|
||||
dataChanged(index(newIndex), index(newIndex), {IsCurrent});
|
||||
}
|
||||
|
||||
QString PlaylistModel::playlistId() const
|
||||
|
||||
+2
-10
@@ -18,7 +18,6 @@ class PlaylistModel : public QAbstractListModel
|
||||
// output
|
||||
Q_PROPERTY(bool loading READ loading WRITE setLoading NOTIFY loadingChanged)
|
||||
Q_PROPERTY(QString currentVideoId READ currentVideoId NOTIFY currentVideoIdChanged)
|
||||
Q_PROPERTY(bool canSkip READ canSkip NOTIFY canSkipChanged)
|
||||
|
||||
public:
|
||||
enum Role {
|
||||
@@ -48,20 +47,13 @@ public:
|
||||
void setCurrentVideoId(const QString &videoId);
|
||||
Q_SIGNAL void currentVideoIdChanged();
|
||||
|
||||
bool canSkip() const;
|
||||
Q_SIGNAL void canSkipChanged();
|
||||
Q_INVOKABLE void next();
|
||||
Q_INVOKABLE void skipTo(const QString &videoId);
|
||||
|
||||
QString playlistId() const;
|
||||
void setPlaylistId(const QString &playlistId);
|
||||
Q_SIGNAL void playlistIdChanged();
|
||||
|
||||
Q_INVOKABLE void next();
|
||||
Q_INVOKABLE void skipTo(const QString &videoId);
|
||||
Q_INVOKABLE void playNext(const QString &videoId, const QString &title, const std::vector<meta::Artist> &artists);
|
||||
Q_INVOKABLE void append(const QString &videoId, const QString &title, const std::vector<meta::Artist> &artists);
|
||||
Q_INVOKABLE void clear();
|
||||
Q_INVOKABLE void remove(const QString &videoId);
|
||||
|
||||
private:
|
||||
void emitCurrentVideoChanged(const QString &oldVideoId);
|
||||
|
||||
|
||||
@@ -4,6 +4,5 @@
|
||||
<file alias="AlbumPage.qml">contents/ui/AlbumPage.qml</file>
|
||||
<file alias="ArtistPage.qml">contents/ui/ArtistPage.qml</file>
|
||||
<file alias="PlayerFooter.qml">contents/ui/PlayerFooter.qml</file>
|
||||
<file alias="SearchPage.qml">contents/ui/SearchPage.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
+7
-44
@@ -18,24 +18,23 @@ SearchModel::SearchModel(QObject *parent)
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
YTMusicThread::instance()->search(m_searchQuery);
|
||||
AsyncYTMusic::instance().search(m_searchQuery);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::searchFinished, this, [=](const std::vector<search::SearchResultItem> &results) {
|
||||
connect(&AsyncYTMusic::instance(), &AsyncYTMusic::searchFinished, this, [=](const std::vector<search::SearchResultItem> &results) {
|
||||
beginResetModel();
|
||||
setLoading(false);
|
||||
m_searchResults = results;
|
||||
endResetModel();
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [=] {
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
SearchModel::~SearchModel() = default;
|
||||
SearchModel::~SearchModel()
|
||||
{
|
||||
}
|
||||
|
||||
int SearchModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : int(m_searchResults.size());
|
||||
return parent.isValid() ? 0 : m_searchResults.size();
|
||||
}
|
||||
|
||||
QVariant SearchModel::data(const QModelIndex &index, int role) const
|
||||
@@ -75,40 +74,6 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}, m_searchResults.at(index.row()));
|
||||
case VideoId:
|
||||
return std::visit([&](auto&& arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, search::Album>) {
|
||||
return QString();
|
||||
} else if constexpr (std::is_same_v<T, search::Artist>) {
|
||||
return QString();
|
||||
} else if constexpr (std::is_same_v<T, search::Playlist>) {
|
||||
return QString();
|
||||
} else if constexpr (std::is_same_v<T, search::Song>) {
|
||||
return QString::fromStdString(arg.video_id);
|
||||
} else if constexpr (std::is_same_v<T, search::Video>) {
|
||||
return QString::fromStdString(arg.video_id);
|
||||
} else {
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}, m_searchResults.at(index.row()));
|
||||
case Artists:
|
||||
return QVariant::fromValue(std::visit([&](auto&& arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, search::Album>) {
|
||||
return std::vector<meta::Artist>();
|
||||
} else if constexpr (std::is_same_v<T, search::Artist>) {
|
||||
return std::vector<meta::Artist>();
|
||||
} else if constexpr (std::is_same_v<T, search::Playlist>) {
|
||||
return std::vector<meta::Artist>();
|
||||
} else if constexpr (std::is_same_v<T, search::Song>) {
|
||||
return arg.artists;
|
||||
} else if constexpr (std::is_same_v<T, search::Video>) {
|
||||
return arg.artists;
|
||||
} else {
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}, m_searchResults.at(index.row())));
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
@@ -120,9 +85,7 @@ QHash<int, QByteArray> SearchModel::roleNames() const
|
||||
{
|
||||
return {
|
||||
{Title, "title"},
|
||||
{Type, "type"},
|
||||
{VideoId, "videoId"},
|
||||
{Artists, "artists"}
|
||||
{Type, "type"}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -28,9 +28,7 @@ public:
|
||||
|
||||
enum Role {
|
||||
Title = Qt::UserRole + 1,
|
||||
Type,
|
||||
VideoId,
|
||||
Artists
|
||||
Type
|
||||
};
|
||||
|
||||
explicit SearchModel(QObject *parent = nullptr);
|
||||
|
||||
@@ -13,19 +13,14 @@ VideoInfoExtractor::VideoInfoExtractor(QObject *parent)
|
||||
{
|
||||
connect(this, &VideoInfoExtractor::videoIdChanged, this, [=] {
|
||||
if (m_videoId.isEmpty()) {
|
||||
m_videoInfo = {};
|
||||
Q_EMIT audioUrlChanged();
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT songChanged();
|
||||
Q_EMIT thumbnailChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
YTMusicThread::instance()->extractVideoInfo(QString::fromStdString(m_videoId.toStdString()));
|
||||
AsyncYTMusic::instance().extractVideoInfo(QString::fromStdString(m_videoId.toStdString()));
|
||||
});
|
||||
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::extractVideoInfoFinished, this, [=](const video_info::VideoInfo &info) {
|
||||
connect(&AsyncYTMusic::instance(), &AsyncYTMusic::extractVideoInfoFinished, this, [=](const video_info::VideoInfo &info) {
|
||||
m_videoInfo = info;
|
||||
setLoading(false);
|
||||
Q_EMIT audioUrlChanged();
|
||||
@@ -84,6 +79,7 @@ QString VideoInfoExtractor::title() const
|
||||
|
||||
QString VideoInfoExtractor::thumbnail() const
|
||||
{
|
||||
qDebug() << "thumb" << QString::fromStdString(m_videoInfo.thumnnail);
|
||||
return QString::fromStdString(m_videoInfo.thumnnail);
|
||||
}
|
||||
|
||||
|
||||
+21
-24
@@ -22,7 +22,7 @@ struct UNEXPORT YTMusicPrivate {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::optional<T> optional_key(py::handle obj, const char *name) {
|
||||
std::optional<T> optional_key(const py::handle &obj, const char *name) {
|
||||
if (!obj.cast<py::dict>().contains(name)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ std::optional<T> optional_key(py::handle obj, const char *name) {
|
||||
return obj[name].cast<T>();
|
||||
}
|
||||
|
||||
meta::Thumbnail extract_thumbnail(py::handle thumbnail) {
|
||||
meta::Thumbnail extract_thumbnail(const py::handle &thumbnail) {
|
||||
return {
|
||||
thumbnail["url"].cast<std::string>(),
|
||||
thumbnail["width"].cast<int>(),
|
||||
@@ -38,14 +38,14 @@ meta::Thumbnail extract_thumbnail(py::handle thumbnail) {
|
||||
};
|
||||
}
|
||||
|
||||
meta::Artist extract_meta_artist(py::handle artist) {
|
||||
meta::Artist extract_meta_artist(const py::handle &artist) {
|
||||
return {
|
||||
artist["name"].cast<std::string>(),
|
||||
artist["id"].cast<std::optional<std::string>>()
|
||||
};
|
||||
};
|
||||
|
||||
album::Track extract_album_track(py::handle track) {
|
||||
album::Track extract_album_track(const py::handle &track) {
|
||||
return {
|
||||
track["index"].cast<std::string>(),
|
||||
track["title"].cast<std::string>(),
|
||||
@@ -56,7 +56,7 @@ album::Track extract_album_track(py::handle track) {
|
||||
};
|
||||
}
|
||||
|
||||
video_info::Format extract_format(py::handle format) {
|
||||
video_info::Format extract_format(const py::handle &format) {
|
||||
return {
|
||||
format["quality"].cast<int>(),
|
||||
format["url"].cast<std::string>(),
|
||||
@@ -65,15 +65,15 @@ video_info::Format extract_format(py::handle format) {
|
||||
};
|
||||
}
|
||||
|
||||
playlist::Track extract_playlist_track(py::handle track);
|
||||
watch::Playlist::Track extract_watch_track(py::handle track);
|
||||
playlist::Track extract_playlist_track(const py::handle &track);
|
||||
watch::Playlist::Track extract_watch_track(const py::handle &track);
|
||||
|
||||
template <typename T>
|
||||
inline auto extract_py_list(py::handle obj) {
|
||||
const auto list = obj.cast<py::list>();
|
||||
inline auto extract_py_list(const py::handle &obj) {
|
||||
const py::list list = obj.cast<py::list>();
|
||||
std::vector<T> output;
|
||||
|
||||
std::transform(list.begin(), list.end(), std::back_inserter(output), [](py::handle item) {
|
||||
std::transform(list.begin(), list.end(), std::back_inserter(output), [](const py::handle &item) {
|
||||
if constexpr(std::is_same_v<T, meta::Thumbnail>) {
|
||||
return extract_thumbnail(item);
|
||||
} else if constexpr(std::is_same_v<T, meta::Artist>) {
|
||||
@@ -94,18 +94,17 @@ inline auto extract_py_list(py::handle obj) {
|
||||
return output;
|
||||
}
|
||||
|
||||
meta::Album extract_meta_album(py::handle album) {
|
||||
meta::Album extract_meta_album(const py::handle &album) {
|
||||
return meta::Album {
|
||||
album["name"].cast<std::string>(),
|
||||
album["id"].cast<std::optional<std::string>>()
|
||||
};
|
||||
}
|
||||
|
||||
watch::Playlist::Track extract_watch_track(py::handle track) {
|
||||
py::print(track);
|
||||
watch::Playlist::Track extract_watch_track(const py::handle &track) {
|
||||
return {
|
||||
track["title"].cast<std::string>(),
|
||||
track["length"].cast<std::optional<std::string>>(),
|
||||
track["length"].cast<std::string>(),
|
||||
track["videoId"].cast<std::string>(),
|
||||
track["playlistId"].cast<std::string>(),
|
||||
extract_py_list<meta::Thumbnail>(track["thumbnail"]),
|
||||
@@ -122,7 +121,7 @@ watch::Playlist::Track extract_watch_track(py::handle track) {
|
||||
}
|
||||
|
||||
|
||||
playlist::Track extract_playlist_track(py::handle track) {
|
||||
playlist::Track extract_playlist_track(const py::handle &track) {
|
||||
return {
|
||||
track["videoId"].cast<std::optional<std::string>>(),
|
||||
track["title"].cast<std::string>(),
|
||||
@@ -142,7 +141,7 @@ playlist::Track extract_playlist_track(py::handle track) {
|
||||
};
|
||||
}
|
||||
|
||||
artist::Artist::Song::Album extract_song_album(py::handle album) {
|
||||
artist::Artist::Song::Album extract_song_album(const py::handle &album) {
|
||||
return {
|
||||
album["name"].cast<std::string>(),
|
||||
album["id"].cast<std::string>()
|
||||
@@ -150,14 +149,14 @@ artist::Artist::Song::Album extract_song_album(py::handle album) {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
auto extract_artist_section_results(py::handle section) {
|
||||
auto extract_artist_section_results(const py::handle §ion) {
|
||||
if (!section.cast<py::dict>().contains("results")) {
|
||||
return std::vector<T>();
|
||||
}
|
||||
|
||||
const py::list py_results = section["results"];
|
||||
std::vector<T> results;
|
||||
std::transform(py_results.begin(), py_results.end(), std::back_inserter(results), [](py::handle result) {
|
||||
std::transform(py_results.begin(), py_results.end(), std::back_inserter(results), [](const py::handle &result) {
|
||||
if constexpr(std::is_same_v<T, artist::Artist::Song>) {
|
||||
return artist::Artist::Song {
|
||||
result["videoId"].cast<std::string>(),
|
||||
@@ -198,7 +197,7 @@ auto extract_artist_section_results(py::handle section) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<artist::Artist::Section<T>> extract_artist_section(py::handle artist, const char* name) {
|
||||
std::optional<artist::Artist::Section<T>> extract_artist_section(const py::handle &artist, const char* name) {
|
||||
if (artist.cast<py::dict>().contains(name)) {
|
||||
const auto section = artist[name];
|
||||
return artist::Artist::Section<T> {
|
||||
@@ -211,8 +210,8 @@ std::optional<artist::Artist::Section<T>> extract_artist_section(py::handle arti
|
||||
}
|
||||
}
|
||||
|
||||
search::SearchResultItem extract_search_result(py::handle result) {
|
||||
const auto resultType = result["resultType"].cast<std::string>();
|
||||
search::SearchResultItem extract_search_result(const py::handle &result) {
|
||||
const std::string resultType = result["resultType"].cast<std::string>();
|
||||
if (resultType == "video") {
|
||||
return search::Video {
|
||||
{
|
||||
@@ -273,8 +272,6 @@ YTMusic::YTMusic(
|
||||
const auto module = py::module::import("ytmusicapi");
|
||||
d->ytmusic = module.attr("YTMusic")(auth, user, requests_session, proxies, language);
|
||||
|
||||
setenv("LC_ALL", "en_US.utf8", true);
|
||||
|
||||
const auto version = module.attr("_version").attr("__version__").cast<std::string>();
|
||||
if (version != "0.14.3") {
|
||||
std::cerr << "Running with untested version of ytmusicapi." << std::endl;
|
||||
@@ -393,7 +390,7 @@ std::vector<artist::Artist::Album> YTMusic::get_artist_albums(const std::string
|
||||
const auto py_albums = d->ytmusic.attr("get_artist_albums")(channel_id, params);
|
||||
std::vector<artist::Artist::Album> albums;
|
||||
|
||||
std::transform(py_albums.begin(), py_albums.end(), std::back_inserter(albums), [](py::handle album) {
|
||||
std::transform(py_albums.begin(), py_albums.end(), std::back_inserter(albums), [](const py::handle &album) {
|
||||
return artist::Artist::Album {
|
||||
album["title"].cast<std::string>(),
|
||||
extract_py_list<meta::Thumbnail>(album["thumbnails"]),
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ struct Thumbnail {
|
||||
int width;
|
||||
int height;
|
||||
|
||||
bool operator<(const Thumbnail &other) const {
|
||||
bool operator<(const Thumbnail other) const {
|
||||
return height < other.height;
|
||||
}
|
||||
};
|
||||
@@ -250,9 +250,9 @@ namespace watch {
|
||||
struct Playlist {
|
||||
struct Track {
|
||||
std::string title;
|
||||
std::optional<std::string> length;
|
||||
std::string length;
|
||||
std::string video_id;
|
||||
std::optional<std::string> playlistId;
|
||||
std::string playlistId;
|
||||
std::vector<meta::Thumbnail> thumbnail;
|
||||
std::optional<std::string> like_status;
|
||||
std::vector<meta::Artist> artists;
|
||||
|
||||
Reference in new issue
Block a user