Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6803f1a42 |
No files matched your search
@@ -1,9 +1,6 @@
|
||||
# SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
# SPDX-FileCopyrightText: 2021 Bhushan Shah <[email protected]>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
*.kdev4
|
||||
CMakeLists.txt.user
|
||||
flatpak/flatpak-builder-tools/
|
||||
build/
|
||||
-21
@@ -2,24 +2,3 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: AudioTube
|
||||
Upstream-Contact: Jonah Brüchert <[email protected]>
|
||||
Source: https://invent.kde.org/plasma-mobile/audiotube
|
||||
|
||||
# Sample paragraph, commented out:
|
||||
#
|
||||
# Files: ...
|
||||
# Copyright: $YEAR $NAME <$CONTACT>
|
||||
# License: ...
|
||||
# Comment: ...
|
||||
|
||||
Files: README.md
|
||||
Copyright: 2021 Jonah Brüchert <[email protected]>
|
||||
License: CC0-1.0
|
||||
|
||||
Files: org.kde.audiotube.desktop
|
||||
org.kde.audiotube.json
|
||||
Copyright: 2021 Jonah Brüchert <[email protected]>
|
||||
License: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
Files: logo.png
|
||||
org.kde.audiotube.svg
|
||||
Copyright: 2021 Mathis Brüchert <[email protected]>
|
||||
License: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
+2
-9
@@ -8,11 +8,10 @@ project(audiotube)
|
||||
|
||||
include(FeatureSummary)
|
||||
|
||||
set(PROJECT_VERSION "22.02")
|
||||
set(QT5_MIN_VERSION 5.15)
|
||||
set(KF5_MIN_VERSION 5.81)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
|
||||
@@ -26,21 +25,15 @@ include(ECMSetupVersion)
|
||||
include(ECMGenerateHeaders)
|
||||
include(ECMPoQmTools)
|
||||
|
||||
ecm_setup_version(${PROJECT_VERSION}
|
||||
VARIABLE_PREFIX AUDIOTUBE
|
||||
VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/version.h
|
||||
)
|
||||
|
||||
kde_enable_exceptions()
|
||||
|
||||
find_package(Qt5 ${QT5_MIN_VERSION} REQUIRED COMPONENTS Core Gui Qml QuickControls2 Svg)
|
||||
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n CoreAddons Crash)
|
||||
find_package(pybind11 REQUIRED)
|
||||
find_package(Ytdlp REQUIRED RUNTIME)
|
||||
find_package(YoutubeDL REQUIRED RUNTIME)
|
||||
find_package(YTMusicAPI REQUIRED RUNTIME)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(qpersistentdata)
|
||||
|
||||
install(PROGRAMS org.kde.audiotube.desktop DESTINATION ${KDE_INSTALL_APPDIR})
|
||||
install(FILES org.kde.audiotube.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR})
|
||||
|
||||
@@ -4,9 +4,9 @@ AudioTube is a client for YouTube Music.
|
||||
|
||||
# Dependencies
|
||||
|
||||
It depends on Qt, Kirigami, KI18n, KCoreAddons and KCrash in addition to a few python packages:
|
||||
It depends on Qt and Kirigami in addition to a few python packages:
|
||||
* ytmusicapi
|
||||
* yt_dlp
|
||||
* youtube_dl
|
||||
|
||||
YouTube uses webp images for the cover art, so you will need to install qtimageformats.
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
@@ -0,0 +1,4 @@
|
||||
[Project]
|
||||
CreatedFrom=CMakeLists.txt
|
||||
Manager=KDevCMakeManager
|
||||
Name=audiotube
|
||||
@@ -0,0 +1,3 @@
|
||||
SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
||||
|
||||
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import yt_dlp" RESULT_VARIABLE YTDLP_CHECK_RESULT)
|
||||
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import youtube_dl" RESULT_VARIABLE YTDL_CHECK_RESULT)
|
||||
|
||||
if (${YTDLP_CHECK_RESULT} EQUAL 0)
|
||||
set(Ytdlp_FOUND TRUE)
|
||||
if (${YTDL_CHECK_RESULT} EQUAL 0)
|
||||
set(YoutubeDL_FOUND TRUE)
|
||||
endif()
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "python3-youtube_dl",
|
||||
"buildsystem": "simple",
|
||||
"build-commands": [
|
||||
"pip3 install --verbose --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/12/67/a37eb6231ff26b4a4bc7cee2568d44e11ffeddb84a9b0798869a4392f3ce/youtube_dl-2021.5.16.tar.gz",
|
||||
"sha256": "4e569cb0477428fd96ee6f7e7a6640b7c9416be626ed708ac4b8ada6c5a6ffbe"
|
||||
}
|
||||
]
|
||||
}
|
||||
File renamed without changes.
@@ -1,39 +0,0 @@
|
||||
{
|
||||
"name": "python3-yt-dlp",
|
||||
"buildsystem": "simple",
|
||||
"build-commands": [
|
||||
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"yt-dlp\" --no-build-isolation"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/37/45/946c02767aabb873146011e665728b680884cd8fe70dde973c640e45b775/certifi-2021.10.8-py2.py3-none-any.whl",
|
||||
"sha256": "d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/f8/a3/622d9acbfb9a71144b5d7609906bc648c62e3ca5fdbb1c8cca222949d82c/websockets-10.3.tar.gz",
|
||||
"sha256": "fc06cc8073c8e87072138ba1e431300e2d408f054b27047d047b549455066ff4"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/16/b3/f7aa8edf2ff4495116f95fd442b2a346aa55d1d46313143c8814886dbcdb/mutagen-1.45.1-py3-none-any.whl",
|
||||
"sha256": "9c9f243fcec7f410f138cb12c21c84c64fde4195481a30c9bfb05b5f003adfed"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/6e/77/efb8398b88e51b5d81ec5fefe1c3ea69e775a6f8fef06654be840d22b433/yt_dlp-2022.4.8-py2.py3-none-any.whl",
|
||||
"sha256": "6edefe326b1e1478fdbe627a66203e5248a6b0dd50c101e682cf700ab70cdf72"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/2a/18/70c32fe9357f3eea18598b23aa9ed29b1711c3001835f7cf99a9818985d0/Brotli-1.0.9.zip",
|
||||
"sha256": "4d1b810aa0ed773f81dceda2cc7b403d01057458730e309856356d4ef4188438"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/24/40/e249ac3845a2333ce50f1bb02299ffb766babdfe80ca9d31e0158ad06afd/pycryptodomex-3.14.1.tar.gz",
|
||||
"sha256": "2ce76ed0081fd6ac8c74edc75b9d14eca2064173af79843c24fa62573263c1f2"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,33 +7,33 @@
|
||||
"sources": [
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/cb/58/834a6445479c72544d9285badce0a58650520c8ba5adfae7b98e61d133bb/ytmusicapi-0.21.0-py3-none-any.whl",
|
||||
"sha256": "29d8d44e1911458041882a453b05c37021ff850757c648f93a45d1775dddbae2"
|
||||
"url": "https://files.pythonhosted.org/packages/94/40/c396b5b212533716949a4d295f91a4c100d51ba95ea9e2d96b6b0517e5a5/urllib3-1.26.5.tar.gz",
|
||||
"sha256": "a7acd0977125325f516bda9735fa7142b909a8d01e8b2e4c8108d0984e6e0098"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/37/45/946c02767aabb873146011e665728b680884cd8fe70dde973c640e45b775/certifi-2021.10.8-py2.py3-none-any.whl",
|
||||
"sha256": "d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"
|
||||
"url": "https://files.pythonhosted.org/packages/ea/b7/e0e3c1c467636186c39925827be42f16fee389dc404ac29e930e9136be70/idna-2.10.tar.gz",
|
||||
"sha256": "b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/ec/03/062e6444ce4baf1eac17a6a0ebfe36bb1ad05e1df0e20b110de59c278498/urllib3-1.26.9-py2.py3-none-any.whl",
|
||||
"sha256": "44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14"
|
||||
"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/06/b3/24afc8868eba069a7f03650ac750a778862dc34941a4bebeb58706715726/charset_normalizer-2.0.12-py3-none-any.whl",
|
||||
"sha256": "6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"
|
||||
"url": "https://files.pythonhosted.org/packages/6d/78/f8db8d57f520a54f0b8a438319c342c61c22759d8f9a1cd2e2180b5e5ea9/certifi-2021.5.30.tar.gz",
|
||||
"sha256": "2bbf76fd432960138b3ef6dda3dde0544f27cbf8546c458e60baf371917ba9ee"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"url": "https://files.pythonhosted.org/packages/2d/61/08076519c80041bc0ffa1a8af0cbd3bf3e2b62af10435d269a9d0f40564d/requests-2.27.1-py2.py3-none-any.whl",
|
||||
"sha256": "f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"
|
||||
"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/04/a2/d918dcd22354d8958fe113e1a3630137e0fc8b44859ade3063982eacd2a4/idna-3.3-py3-none-any.whl",
|
||||
"sha256": "84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"
|
||||
"url": "https://files.pythonhosted.org/packages/1b/8e/2bc4c8160083bbfaac215637f1e9f4a43263833c2e81212cba3073aeaa25/ytmusicapi-0.17.3.tar.gz",
|
||||
"sha256": "9a249cc53efd6408034f401a9a4375272a9b339e8eb64f3a2e713a1ccd06d55b"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -16,5 +16,5 @@ else
|
||||
git -C flatpak-builder-tools pull
|
||||
fi
|
||||
|
||||
./flatpak-builder-tools/pip/flatpak-pip-generator yt-dlp
|
||||
./flatpak-builder-tools/pip/flatpak-pip-generator youtube_dl
|
||||
./flatpak-builder-tools/pip/flatpak-pip-generator ytmusicapi
|
||||
@@ -0,0 +1,3 @@
|
||||
SPDX-FileCopyrightText: 2021 Mathis Brüchert <[email protected]>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
@@ -7,100 +7,61 @@ SPDX-License-Identifier: CC0-1.0
|
||||
<component type="desktop-application">
|
||||
<id>org.kde.audiotube</id>
|
||||
<name>AudioTube</name>
|
||||
<name xml:lang="ar">تيوب الصوتي</name>
|
||||
<name xml:lang="ca">AudioTube</name>
|
||||
<name xml:lang="ca-valencia">AudioTube</name>
|
||||
<name xml:lang="cs">AudioTube</name>
|
||||
<name xml:lang="de">AudioTube</name>
|
||||
<name xml:lang="en-GB">AudioTube</name>
|
||||
<name xml:lang="es">AudioTube</name>
|
||||
<name xml:lang="eu">AudioTube</name>
|
||||
<name xml:lang="fi">AudioTube</name>
|
||||
<name xml:lang="fr">AudioTube</name>
|
||||
<name xml:lang="hi">ओडियो-ट्यूब</name>
|
||||
<name xml:lang="it">AudioTube</name>
|
||||
<name xml:lang="ko">AudioTube</name>
|
||||
<name xml:lang="nl">AudioTube</name>
|
||||
<name xml:lang="pa">ਆਡੀਓ-ਟਿਊਬ</name>
|
||||
<name xml:lang="pl">AudioTube</name>
|
||||
<name xml:lang="pt">AudioTube</name>
|
||||
<name xml:lang="pt-BR">AudioTube</name>
|
||||
<name xml:lang="ro">AudioTube</name>
|
||||
<name xml:lang="sk">AudioTube</name>
|
||||
<name xml:lang="sl">AudioTube</name>
|
||||
<name xml:lang="sv">AudioTube</name>
|
||||
<name xml:lang="uk">AudioTube</name>
|
||||
<name xml:lang="x-test">xxAudioTubexx</name>
|
||||
<name xml:lang="zh-CN">AudioTube</name>
|
||||
<summary>Convergent YouTube Music client</summary>
|
||||
<summary xml:lang="ar">عميل موسيقى يوتيوب متعدد المنصات</summary>
|
||||
<summary xml:lang="ca">Client convergent de música de YouTube</summary>
|
||||
<summary xml:lang="ca-valencia">Client convergent de música de YouTube</summary>
|
||||
<summary xml:lang="ca">Client convergent per a la música de YouTube</summary>
|
||||
<summary xml:lang="ca-valencia">Client convergent per a la música de YouTube</summary>
|
||||
<summary xml:lang="de">Konvergentes YouTube-Musikprogramm</summary>
|
||||
<summary xml:lang="en-GB">Convergent YouTube Music client</summary>
|
||||
<summary xml:lang="es">Cliente de música de YouTube convergente</summary>
|
||||
<summary xml:lang="eu">YouTube Music bezero konbergentea</summary>
|
||||
<summary xml:lang="fi">Mukautuva YouTube Music -asiakas</summary>
|
||||
<summary xml:lang="fr">Client convergent pour musique sur YouTube</summary>
|
||||
<summary xml:lang="hi">अभिसृत यूट्यूब संगीत क्लाएंट</summary>
|
||||
<summary xml:lang="it">Client YouTube Music convergente</summary>
|
||||
<summary xml:lang="ko">올인원 YouTube Music 클라이언트</summary>
|
||||
<summary xml:lang="nl">Convergente muziekclient van YouTube</summary>
|
||||
<summary xml:lang="pl">Adaptacyjny program do YouTube Music</summary>
|
||||
<summary xml:lang="pl">Całościowy program do muzyki z YouTube</summary>
|
||||
<summary xml:lang="pt">Cliente de música do YouTube convergente</summary>
|
||||
<summary xml:lang="pt-BR">Um cliente convergente para o YouTube Music</summary>
|
||||
<summary xml:lang="ro">Client convergent de muzică pentru YouTube</summary>
|
||||
<summary xml:lang="sl">Konvergentni odjemalec glasbe YouTube</summary>
|
||||
<summary xml:lang="sv">Konvergent YouTube-musikprogram</summary>
|
||||
<summary xml:lang="uk">Зручний музичний клієнт YouTube</summary>
|
||||
<summary xml:lang="x-test">xxConvergent YouTube Music clientxx</summary>
|
||||
<summary xml:lang="zh-CN">桌面和移动设备通用 YouTube Music 客户端</summary>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<project_license>GPL-2.0+</project_license>
|
||||
<developer_name>KDE Community</developer_name>
|
||||
<developer_name xml:lang="ar">مجتمع كدي</developer_name>
|
||||
<developer_name xml:lang="ca">La comunitat KDE</developer_name>
|
||||
<developer_name xml:lang="ca-valencia">La comunitat KDE</developer_name>
|
||||
<developer_name xml:lang="cs">Komunita KDE</developer_name>
|
||||
<developer_name xml:lang="de">KDE-Gemeinschaft</developer_name>
|
||||
<developer_name xml:lang="en-GB">KDE Community</developer_name>
|
||||
<developer_name xml:lang="es">Comunidad KDE</developer_name>
|
||||
<developer_name xml:lang="eu">KDE komunitatea</developer_name>
|
||||
<developer_name xml:lang="fi">KDE-yhteisö</developer_name>
|
||||
<developer_name xml:lang="fr">Communauté de KDE</developer_name>
|
||||
<developer_name xml:lang="hi">केडीई समुदाय</developer_name>
|
||||
<developer_name xml:lang="it">Comunità KDE</developer_name>
|
||||
<developer_name xml:lang="ko">KDE 커뮤니티</developer_name>
|
||||
<developer_name xml:lang="nl">KDE-gemeenschap</developer_name>
|
||||
<developer_name xml:lang="pa">ਕੇਡੀਈ ਕਮਿਊਨਟੀ</developer_name>
|
||||
<developer_name xml:lang="pl">Społeczność KDE</developer_name>
|
||||
<developer_name xml:lang="pt">Comunidade do KDE</developer_name>
|
||||
<developer_name xml:lang="pt-BR">A Comunidade KDE</developer_name>
|
||||
<developer_name xml:lang="ro">Comunitatea KDE</developer_name>
|
||||
<developer_name xml:lang="sk">KDE komunita</developer_name>
|
||||
<developer_name xml:lang="sl">Skupnost KDE</developer_name>
|
||||
<developer_name xml:lang="sv">KDE-gemenskapen</developer_name>
|
||||
<developer_name xml:lang="uk">Спільнота KDE</developer_name>
|
||||
<developer_name xml:lang="x-test">xxKDE Communityxx</developer_name>
|
||||
<developer_name xml:lang="zh-CN">KDE 社区</developer_name>
|
||||
<content_rating type="oars-1.0"/>
|
||||
<url type="homepage">https://apps.kde.org/en/audiotube</url>
|
||||
<releases>
|
||||
<release version="22.02" date="2022-02-09">
|
||||
<url>https://www.plasma-mobile.org/2022/02/09/plasma-mobile-gear-22-02/</url>
|
||||
<description>
|
||||
<ul>
|
||||
<li>Update the version of ytmusicapi</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="21.12" date="2021-12-07">
|
||||
<url>https://www.plasma-mobile.org/2021/12/07/plasma-mobile-gear-21-12/</url>
|
||||
</release>
|
||||
<release version="21.08" date="2021-08-31">
|
||||
<url>https://www.plasma-mobile.org/2021/08/31/plasma-mobile-gear-21-08/</url>
|
||||
</release>
|
||||
</releases>
|
||||
<launchable type="desktop-id">org.kde.audiotube.desktop</launchable>
|
||||
<screenshots>
|
||||
<screenshot>
|
||||
@@ -117,26 +78,20 @@ SPDX-License-Identifier: CC0-1.0
|
||||
</recommends>
|
||||
<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 xml:lang="ar">يمكن لتيوب الصوتي البحث في موسيقى يوتيوب، وعرض الألبومات والفنانين، وتشغيل القوائم والألبومات المولدة تلقائيًا، ويسمح لك بوضع قائمة التشغيل الخاصة بك معًا.</p>
|
||||
<p xml:lang="ca">L'AudioTube pot cercar música a YouTube, llistar àlbums i artistes, reproduir llistes de reproducció generades automàticament, àlbums i permet crear la vostra pròpia llista de reproducció.</p>
|
||||
<p xml:lang="ca-valencia">L'AudioTube pot cercar música a YouTube, llistar àlbums i artistes, reproduir llistes de reproducció generades automàticament, àlbums i permet crear la vostra pròpia llista de reproducció.</p>
|
||||
<p xml:lang="de">AudioTube kann Musik auf YouTube durchsuchen, Alben und Interpreten auflisten, automatisch generierte Wiedergabelisten und Alben abspielen und erlaubt es, eine eigene Wiedergabeliste zusammenzustellen.</p>
|
||||
<p xml:lang="en-GB">AudioTube can search YouTube Music, list albums and artists, play automatically generated playlists, albums and allows to put your own playlist together.</p>
|
||||
<p xml:lang="es">AudioTube puede buscar música de YouTube, listar álbumes y artistas, reproducir las listas de reproducción generadas, álbumes y le permite crear su propia lista de reproducción.</p>
|
||||
<p xml:lang="eu">AudioTube-k YouTube Music-en bilatu dezake, albumak eta artistak zerrendatu, automatikoki sortutako jotze-zerrendak eta albumak jo, eta zure jotze-zerrenda osatzeko aukera eskaintzen dizu.</p>
|
||||
<p xml:lang="fi">AudioTube osaa etsiä YouTube Music -haun, albumien ja artistien luettelun, luotujen soittolistojen automaattisen toiston ja omien soittolistojen kokoamisen.</p>
|
||||
<p xml:lang="fr">AudioTube peut effectuer des recherches de musiques sur YouTube Music, établir une liste d'albums et d'artistes, lire des listes de lecture générées automatiquement, des albums et permet de composer sa propre liste de lecture.</p>
|
||||
<p xml:lang="hi">ऑडियोट्यूब यूट्यूब संगीत खोज सकता है, एल्बम और कलाकारों की सूची बना सकता है, स्वचालित रूप से उत्पन्न की गई गीतसूची, एल्बम बजा सकता है और आपकी अपनी खुद की प्लेलिस्ट को एक साथ रखने में मदद करता है।</p>
|
||||
<p xml:lang="it">AudioTube può eseguire ricerche su YouTube Music, elencare album e artisti, riprodurre scalette e album generati automaticamente e ti consente di creare la tua scaletta.</p>
|
||||
<p xml:lang="ko">AudioTube는 YouTube Music을 검색하고, 앨범과 아티스트를 표시하고, 자동 생성된 재생 목록, 앨범을 재생하고, 사용자 정의 재생 목록을 만들 수 있습니다.</p>
|
||||
<p xml:lang="nl">AudioTube kan in YouTube Music zoeken, een lijst maken van albums en artiesten, automatically gegenereerde afspeellijsten, albums afspelen en biedt u het samenstellen van uw eigen afspeellijst.</p>
|
||||
<p xml:lang="pl">AudioTube może przeszukiwać serwis YouTube Music, wypisać albumy i wykonawców, odtwarzać samoczynnie utworzone listy odtwarzania, albumy oraz umożliwia tworzenie własnych list odtwarzania.</p>
|
||||
<p xml:lang="pl">AudioTube może wyszukać muzyki na YouTube, wypisać albumy i wykonawców, odtwarzać samoczynnie utworzone listy odtwarzania, albumy oraz umożliwia tworzenie własnych list odtwarzania.</p>
|
||||
<p xml:lang="pt">O AudioTube consegue pesquisar no YouTube Music, enumerar os álbuns e artistas, reproduzir listas geradas automaticamente, álbuns e permite-lhe reproduzir as suas próprias listas de reprodução.</p>
|
||||
<p xml:lang="pt-BR">O AudioTube pode pesquisar no YouTube Music, listar álbuns e artistas, rodar listas de reprodução geradas automaticamente, álbuns inteiros, e criar a sua própria lista de reprodução.</p>
|
||||
<p xml:lang="sl">AudioTube lahko išče po YouTube Music, izdela sezname albumov in avtorjev, samodejno predvaja generirane sezname, albume in sestavlja vaše sezname predvajanja.</p>
|
||||
<p xml:lang="sv">AudioTube kan söka på YouTube Music, lista album och artister, spela upp automatiskt genererade spellistor, albums och låter dig sammanställa egna spellistor.</p>
|
||||
<p xml:lang="uk">AudioTube може виконувати пошук на YouTube Music, показувати списки альбомів та виконавців, відтворювати створені автоматично списки відтворення, альбоми та надає вам змогу створювати власні списки відворення.</p>
|
||||
<p xml:lang="x-test">xxAudioTube can search YouTube Music, list albums and artists, play automatically generated playlists, albums and allows to put your own playlist together.xx</p>
|
||||
<p xml:lang="zh-CN">AudioTube 可以搜索 YouTube Music 的内容,列出专辑和艺人,播放自动生成的播放列表,还可以自行制作播放列表。</p>
|
||||
</description>
|
||||
</component>
|
||||
@@ -1,56 +1,42 @@
|
||||
[Desktop Entry]
|
||||
Name=AudioTube
|
||||
Name[ar]=تيوب الصوتي
|
||||
Name[ca]=AudioTube
|
||||
Name[ca@valencia]=AudioTube
|
||||
Name[cs]=AudioTube
|
||||
Name[de]=AudioTube
|
||||
Name[en_GB]=AudioTube
|
||||
Name[es]=AudioTube
|
||||
Name[eu]=AudioTube
|
||||
Name[fi]=AudioTube
|
||||
Name[fr]=AudioTube
|
||||
Name[hi]=ओडियो-ट्यूब
|
||||
Name[it]=AudioTube
|
||||
Name[ko]=AudioTube
|
||||
Name[nl]=AudioTube
|
||||
Name[pa]=ਆਡੀਓ-ਟਿਊਬ
|
||||
Name[pl]=AudioTube
|
||||
Name[pt]=AudioTube
|
||||
Name[pt_BR]=AudioTube
|
||||
Name[ro]=AudioTube
|
||||
Name[sk]=AudioTube
|
||||
Name[sl]=AudioTube
|
||||
Name[sv]=AudioTube
|
||||
Name[uk]=AudioTube
|
||||
Name[x-test]=xxAudioTubexx
|
||||
Name[zh_CN]=AudioTube
|
||||
Comment=YouTube Music client
|
||||
Comment[ar]=عميل يوتيوب ميوزيك
|
||||
Comment[ca]=Client de música de YouTube
|
||||
Comment[ca@valencia]=Client de música de YouTube
|
||||
Comment[cs]=Hudební klient YouTube
|
||||
Comment[de]=YouTube-Musikprogramm
|
||||
Comment[en_GB]=YouTube Music client
|
||||
Comment[es]=Cliente de música de YouTube
|
||||
Comment[eu]=YouTube Music bezeroa
|
||||
Comment[fi]=YouTube Music -asiakas
|
||||
Comment[fr]=Client de musique sur Youtube
|
||||
Comment[hi]=यूट्यूब संगीत क्लाएंट
|
||||
Comment[it]=Client YouTube Music
|
||||
Comment[ko]=YouTube Music 클라이언트
|
||||
Comment[nl]=Muziekclient van YouTube
|
||||
Comment[pa]=ਯੂਟਿਊਬ ਸੰਗੀਤ ਕਲਾਈਂਟ
|
||||
Comment[pl]=Program do YouTube Music
|
||||
Comment[pl]=Program do muzyki z YouTube
|
||||
Comment[pt]=Cliente do YouTube Music
|
||||
Comment[pt_BR]=Cliente YouTube Music
|
||||
Comment[ro]=Client de muzică pentru YouTube
|
||||
Comment[sk]=Hudobný klient YouTube
|
||||
Comment[sl]=Glasbeni odjemalec Youtube
|
||||
Comment[sv]=YouTube-musikprogram
|
||||
Comment[uk]=Музичний клієнт YouTube
|
||||
Comment[x-test]=xxYouTube Music clientxx
|
||||
Comment[zh_CN]=YouTube Music 客户端
|
||||
Version=1.0
|
||||
Exec=audiotube
|
||||
Icon=org.kde.audiotube
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "org.kde.audiotube",
|
||||
"runtime": "org.kde.Platform",
|
||||
"runtime-version": "5.15-21.08",
|
||||
"runtime-version": "5.15",
|
||||
"sdk": "org.kde.Sdk",
|
||||
"command": "audiotube",
|
||||
"tags": ["nightly"],
|
||||
@@ -21,14 +21,14 @@
|
||||
],
|
||||
|
||||
"modules": [
|
||||
"flatpak/python3-yt-dlp.json",
|
||||
"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", "tag": "v2.9.1" } ]
|
||||
"sources": [ { "type": "git", "url": "https://github.com/pybind/pybind11", "tag": "v2.6.2" } ]
|
||||
},
|
||||
{
|
||||
"name": "org.kde.audiotube",
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
@@ -0,0 +1,3 @@
|
||||
SPDX-FileCopyrightText: 2021 Mathis Brüchert <[email protected]>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
@@ -1,8 +0,0 @@
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
find_package(LMDB REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Core REQUIRED)
|
||||
|
||||
add_subdirectory(src)
|
||||
@@ -1,24 +0,0 @@
|
||||
# Try to find the LMBD libraries and headers
|
||||
# LMDB_FOUND - system has LMDB lib
|
||||
# LMDB_INCLUDE_DIR - the LMDB include directory
|
||||
# LMDB_LIBRARIES - Libraries needed to use LMDB
|
||||
|
||||
# FindCWD based on FindGMP by:
|
||||
# Copyright (c) 2006, Laurent Montel, <[email protected]>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
|
||||
# Adapted from FindCWD by:
|
||||
# Copyright 2013 Conrad Steenberg <[email protected]>
|
||||
# Aug 31, 2013
|
||||
|
||||
find_path(LMDB_INCLUDE_DIR NAMES lmdb.h PATHS "$ENV{LMDB_DIR}/include")
|
||||
find_library(LMDB_LIBRARIES NAMES lmdb PATHS "$ENV{LMDB_DIR}/lib" )
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(LMDB DEFAULT_MSG LMDB_INCLUDE_DIR LMDB_LIBRARIES)
|
||||
|
||||
if(LMDB_FOUND)
|
||||
message(STATUS "Found lmdb (include: ${LMDB_INCLUDE_DIR}, library: ${LMDB_LIBRARIES})")
|
||||
mark_as_advanced(LMDB_INCLUDE_DIR LMDB_LIBRARIES)
|
||||
endif()
|
||||
@@ -1,3 +0,0 @@
|
||||
add_library(qpersistentdata STATIC qpersistentdata.h qpersistentdata.cpp)
|
||||
target_link_libraries(qpersistentdata PUBLIC Qt::Core ${LMDB_LIBRARIES})
|
||||
target_include_directories(qpersistentdata PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -1,17 +0,0 @@
|
||||
#include "qpersistentdata.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
int main() {
|
||||
auto data = QPersistentData("/tmp");
|
||||
Q_ASSERT(data.isValid());
|
||||
|
||||
data.insert(1, QSize(1,11));
|
||||
Q_ASSERT(data.value<QSize>(1) == QSize(1,11));
|
||||
data.insert("idList", QVector<int> {1, 2, 3, 4, 5});
|
||||
data.insert(u"moinLeude", u"Moin Leude");
|
||||
data.insert(QVector<QByteArray>({"moin", "leude"}), "Yo");
|
||||
data.insert(QDateTime(), u"Hello World"_qs);
|
||||
qDebug() << data.value<QVector<int>>("idList");
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
#include "qpersistentdata.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
#include <QDir>
|
||||
#include <QStringBuilder>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
|
||||
#include <lmdb.h>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(PersistentDataLog)
|
||||
Q_LOGGING_CATEGORY(PersistentDataLog, "qpersistentdata")
|
||||
|
||||
struct EnvironmentHolder {
|
||||
MDB_env *env = nullptr;
|
||||
int users = 0;
|
||||
int maxDbs = 10;
|
||||
};
|
||||
|
||||
EnvironmentHolder DATABASE_ENVIRONMENT;
|
||||
|
||||
void qPersistentDataSetMaxDbs(int num)
|
||||
{
|
||||
DATABASE_ENVIRONMENT.maxDbs = num;
|
||||
}
|
||||
|
||||
///
|
||||
/// Increments the number of references to the global database
|
||||
/// environment on construction, and decrements it on destruction
|
||||
///
|
||||
/// This should ensure that an EnvHandle is always a valid handle to
|
||||
/// an MDB_env
|
||||
///
|
||||
class EnvHandle {
|
||||
public:
|
||||
EnvHandle() {
|
||||
DATABASE_ENVIRONMENT.users++;
|
||||
|
||||
if (!DATABASE_ENVIRONMENT.env) {
|
||||
const QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) % "/persistent-data/";
|
||||
QDir(path).mkpath(QStringLiteral("."));
|
||||
|
||||
int s = mdb_env_create(&DATABASE_ENVIRONMENT.env);
|
||||
Q_ASSERT(s == MDB_SUCCESS);
|
||||
s = mdb_env_set_maxdbs(DATABASE_ENVIRONMENT.env, DATABASE_ENVIRONMENT.maxDbs);
|
||||
Q_ASSERT(s == MDB_SUCCESS);
|
||||
if (int status = mdb_env_open(DATABASE_ENVIRONMENT.env, path.toUtf8(), 0, 0664) != MDB_SUCCESS) {
|
||||
qCDebug(PersistentDataLog) << "Failed to open database with exit code" << status;
|
||||
mdb_env_close(DATABASE_ENVIRONMENT.env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EnvHandle(EnvHandle &) {
|
||||
DATABASE_ENVIRONMENT.users++;
|
||||
}
|
||||
|
||||
EnvHandle &operator=(const EnvHandle &) = default;
|
||||
EnvHandle(EnvHandle &&) = default;
|
||||
EnvHandle &operator=(EnvHandle &&) = default;
|
||||
|
||||
~EnvHandle() {
|
||||
DATABASE_ENVIRONMENT.users--;
|
||||
|
||||
if (DATABASE_ENVIRONMENT.users == 0) {
|
||||
qCDebug(PersistentDataLog) << "Closing database handle";
|
||||
mdb_env_close(DATABASE_ENVIRONMENT.env);
|
||||
}
|
||||
}
|
||||
|
||||
operator MDB_env*() {
|
||||
return DATABASE_ENVIRONMENT.env;
|
||||
}
|
||||
};
|
||||
|
||||
/// Qt wrapper for MDB_val
|
||||
struct LMDBValueView : public MDB_val {
|
||||
constexpr LMDBValueView() : MDB_val()
|
||||
{
|
||||
mv_size = 0;
|
||||
mv_data = nullptr;
|
||||
}
|
||||
|
||||
constexpr LMDBValueView(const QByteArray &bytes) : MDB_val()
|
||||
{
|
||||
mv_size = static_cast<size_t>(bytes.size());
|
||||
mv_data = const_cast<char *>(bytes.data());
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const char *data() const {
|
||||
return static_cast<const char *>(mv_data);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr std::size_t size() const {
|
||||
return mv_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] QByteArray toByteArray() const {
|
||||
return QByteArray(data(), size());
|
||||
}
|
||||
};
|
||||
|
||||
struct QPersistentDataPrivate {
|
||||
QByteArray name;
|
||||
EnvHandle handle;
|
||||
|
||||
~QPersistentDataPrivate() = default;
|
||||
};
|
||||
|
||||
QPersistentData::QPersistentData(EnvHandle handle, const QByteArray &name)
|
||||
: d(std::make_unique<QPersistentDataPrivate>())
|
||||
{
|
||||
d->handle = handle;
|
||||
d->name = name;
|
||||
}
|
||||
|
||||
QPersistentData::QPersistentData(const QByteArray &name)
|
||||
: QPersistentData(EnvHandle(), name)
|
||||
{
|
||||
}
|
||||
|
||||
int QPersistentData::insert(const QByteArray &key, const QByteArray &value)
|
||||
{
|
||||
if (!d->handle) {
|
||||
return MDB_INVALID;
|
||||
}
|
||||
|
||||
MDB_txn *wtxn = nullptr;
|
||||
if (int status = mdb_txn_begin(d->handle, nullptr, 0, &wtxn) != MDB_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
MDB_dbi dbi {};
|
||||
if (int status = mdb_dbi_open(wtxn, d->name, MDB_CREATE, &dbi) != MDB_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
LMDBValueView k(key);
|
||||
LMDBValueView v(value);
|
||||
|
||||
if (int status = mdb_put(wtxn, dbi, &k, &v, 0) != MDB_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
if (int status = mdb_txn_commit(wtxn) != MDB_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
mdb_dbi_close(d->handle, dbi);
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray QPersistentData::value(const QByteArray &key) const
|
||||
{
|
||||
if (!d->handle) {
|
||||
return {};
|
||||
}
|
||||
|
||||
MDB_txn *rtxn = nullptr;
|
||||
if (int status = mdb_txn_begin(d->handle, nullptr, MDB_RDONLY, &rtxn) != MDB_SUCCESS) {
|
||||
qCDebug(PersistentDataLog) << "Failed to start transaction:" << status;
|
||||
return {};
|
||||
}
|
||||
|
||||
MDB_dbi dbi {};
|
||||
if (int status = mdb_dbi_open(rtxn, d->name, MDB_CREATE, &dbi) != MDB_SUCCESS) {
|
||||
qCDebug(PersistentDataLog) << "Failed to open database handle:" << status;
|
||||
return {};
|
||||
}
|
||||
|
||||
LMDBValueView k(key);
|
||||
LMDBValueView v;
|
||||
|
||||
if (int status = mdb_get(rtxn, dbi, &k, &v) != MDB_SUCCESS) {
|
||||
qCDebug(PersistentDataLog) << "Failed to retrieve data from the database:" << status;
|
||||
return {};
|
||||
}
|
||||
mdb_txn_abort(rtxn);
|
||||
mdb_dbi_close(d->handle, dbi);
|
||||
|
||||
return v.toByteArray();
|
||||
}
|
||||
|
||||
bool QPersistentData::isValid() const
|
||||
{
|
||||
return d->handle;
|
||||
}
|
||||
|
||||
QPersistentData::~QPersistentData() = default;
|
||||
QPersistentData::QPersistentData(QPersistentData &&other) noexcept = default;
|
||||
@@ -1,66 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDataStream>
|
||||
#include <QSize>
|
||||
#include <QIODevice>
|
||||
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
struct QPersistentDataPrivate;
|
||||
class MDB_env;
|
||||
class MDB_cursor;
|
||||
class MDB_txn;
|
||||
class EnvHandle;
|
||||
typedef unsigned int MDB_dbi;
|
||||
|
||||
///
|
||||
/// Set the number of databases that can be used in parallel
|
||||
///
|
||||
void qPersistentDataSetMaxDbs(int num);
|
||||
|
||||
class QPersistentData {
|
||||
public:
|
||||
QPersistentData(QPersistentData &&other) noexcept;
|
||||
~QPersistentData();
|
||||
|
||||
QPersistentData(const QByteArray &name);
|
||||
|
||||
int insert(const QByteArray &key, const QByteArray &value);
|
||||
|
||||
template <typename KeyType, typename ValueType>
|
||||
int insert(const KeyType &key, const ValueType &value) {
|
||||
QByteArray keyS;
|
||||
QByteArray valS;
|
||||
|
||||
QDataStream keyStream(&keyS, QIODevice::WriteOnly);
|
||||
keyStream << key;
|
||||
QDataStream valStream(&valS, QIODevice::WriteOnly);
|
||||
valStream << value;
|
||||
|
||||
return insert(keyS, valS);
|
||||
}
|
||||
|
||||
[[nodiscard]] QByteArray value(const QByteArray &key) const;
|
||||
|
||||
template <typename ValueType, typename KeyType>
|
||||
ValueType value(const KeyType &key) const {
|
||||
QByteArray keyS;
|
||||
QDataStream keyStream(&keyS, QIODevice::WriteOnly);
|
||||
keyStream << key;
|
||||
|
||||
auto val = value(keyS);
|
||||
QDataStream vStream(val);
|
||||
|
||||
ValueType out;
|
||||
vStream >> out;
|
||||
return out;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isValid() const;
|
||||
|
||||
private:
|
||||
explicit QPersistentData(EnvHandle handle, const QByteArray &name);
|
||||
std::shared_ptr<QPersistentDataPrivate> d;
|
||||
};
|
||||
+2
-2
@@ -3,5 +3,5 @@
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
ytmusicapi==0.21.0
|
||||
yt-dlp
|
||||
ytmusicapi==0.17.3
|
||||
youtube_dl
|
||||
@@ -24,9 +24,7 @@ add_executable(audiotube
|
||||
playlistutils.cpp
|
||||
errorhandler.cpp
|
||||
playerutils.cpp
|
||||
abstractytmusicmodel.cpp
|
||||
multiiterableview.h
|
||||
library.cpp
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
@@ -41,7 +39,6 @@ target_link_libraries(audiotube
|
||||
KF5::CoreAddons
|
||||
KF5::Crash
|
||||
ytm
|
||||
qpersistentdata
|
||||
)
|
||||
target_compile_definitions(audiotube PRIVATE -DQT_NO_KEYWORDS -DQT_NO_URL_CAST_FROM_STRING)
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
#include "abstractytmusicmodel.h"
|
||||
|
||||
#include "asyncytmusic.h"
|
||||
|
||||
|
||||
AbstractYTMusicModel::AbstractYTMusicModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool AbstractYTMusicModel::loading() const
|
||||
{
|
||||
return m_loading;
|
||||
}
|
||||
|
||||
void AbstractYTMusicModel::setLoading(bool loading)
|
||||
{
|
||||
if (m_loading == loading)
|
||||
return;
|
||||
|
||||
m_loading = loading;
|
||||
Q_EMIT loadingChanged();
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
///
|
||||
/// Base class for all models that work with data from the AsyncYTMusic class.
|
||||
/// It provides a loading property, that is automatically set to false if a query fails.
|
||||
///
|
||||
class AbstractYTMusicModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool loading READ loading WRITE setLoading NOTIFY loadingChanged)
|
||||
|
||||
public:
|
||||
explicit AbstractYTMusicModel(QObject *parent = nullptr);
|
||||
|
||||
bool loading() const;
|
||||
void setLoading(bool loading);
|
||||
Q_SIGNAL void loadingChanged();
|
||||
|
||||
private:
|
||||
bool m_loading = false;
|
||||
};
|
||||
|
||||
+34
-18
@@ -7,26 +7,25 @@
|
||||
#include <QDebug>
|
||||
|
||||
AlbumModel::AlbumModel(QObject *parent)
|
||||
: AbstractYTMusicModel(parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
connect(this, &AlbumModel::browseIdChanged, this, [this] {
|
||||
connect(this, &AlbumModel::browseIdChanged, this, [=] {
|
||||
setLoading(true);
|
||||
auto future = YTMusicThread::instance()->fetchAlbum(m_browseId);
|
||||
connectFuture(future, this, [=, this](const album::Album &album) {
|
||||
setLoading(false);
|
||||
|
||||
beginResetModel();
|
||||
m_album = album;
|
||||
endResetModel();
|
||||
std::sort(m_album.thumbnails.begin(), m_album.thumbnails.end());
|
||||
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT thumbnailUrlChanged();
|
||||
Q_EMIT playlistIdChanged();
|
||||
});
|
||||
YTMusicThread::instance()->fetchAlbum(m_browseId);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::fetchAlbumFinished, this, [=](const album::Album &album) {
|
||||
setLoading(false);
|
||||
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [=, this] {
|
||||
beginResetModel();
|
||||
m_album = album;
|
||||
endResetModel();
|
||||
std::sort(m_album.thumbnails.begin(), m_album.thumbnails.end());
|
||||
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT thumbnailUrlChanged();
|
||||
Q_EMIT playlistIdChanged();
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [=] {
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
@@ -44,7 +43,12 @@ QVariant AlbumModel::data(const QModelIndex &index, int role) const
|
||||
case VideoId:
|
||||
return QString::fromStdString(m_album.tracks[index.row()].video_id.value_or(std::string()));
|
||||
case Artists:
|
||||
return QVariant::fromValue(m_album.tracks[index.row()].artists);
|
||||
return QVariant::fromValue(std::vector<meta::Artist> {
|
||||
{
|
||||
m_album.tracks[index.row()].artists,
|
||||
std::nullopt
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
@@ -77,6 +81,18 @@ QString AlbumModel::title() const
|
||||
return QString::fromStdString(m_album.title);
|
||||
}
|
||||
|
||||
bool AlbumModel::loading() const
|
||||
{
|
||||
return m_loading;
|
||||
}
|
||||
|
||||
void AlbumModel::setLoading(bool loading)
|
||||
{
|
||||
m_loading = loading;
|
||||
Q_EMIT loadingChanged();
|
||||
}
|
||||
|
||||
|
||||
QUrl AlbumModel::thumbnailUrl() const
|
||||
{
|
||||
if (m_album.thumbnails.empty()) {
|
||||
@@ -88,5 +104,5 @@ QUrl AlbumModel::thumbnailUrl() const
|
||||
|
||||
QString AlbumModel::playlistId() const
|
||||
{
|
||||
return QString::fromStdString(m_album.audio_playlist_id);
|
||||
return QString::fromStdString(m_album.playlist_id);
|
||||
}
|
||||
+7
-2
@@ -8,15 +8,15 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include "asyncytmusic.h"
|
||||
#include "abstractytmusicmodel.h"
|
||||
|
||||
class AlbumModel : public AbstractYTMusicModel
|
||||
class AlbumModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString browseId READ browseId WRITE setBrowseId NOTIFY browseIdChanged REQUIRED)
|
||||
|
||||
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
|
||||
Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl NOTIFY thumbnailUrlChanged)
|
||||
Q_PROPERTY(bool loading READ loading WRITE setLoading NOTIFY loadingChanged)
|
||||
Q_PROPERTY(QString playlistId READ playlistId NOTIFY playlistIdChanged)
|
||||
|
||||
public:
|
||||
@@ -39,6 +39,10 @@ public:
|
||||
QString title() const;
|
||||
Q_SIGNAL void titleChanged();
|
||||
|
||||
bool loading() const;
|
||||
void setLoading(bool loading);
|
||||
Q_SIGNAL void loadingChanged();
|
||||
|
||||
QUrl thumbnailUrl() const;
|
||||
Q_SIGNAL void thumbnailUrlChanged();
|
||||
|
||||
@@ -47,6 +51,7 @@ public:
|
||||
|
||||
private:
|
||||
QString m_browseId;
|
||||
bool m_loading = false;
|
||||
|
||||
album::Album m_album;
|
||||
};
|
||||
+61
-42
@@ -7,49 +7,55 @@
|
||||
#include <asyncytmusic.h>
|
||||
|
||||
ArtistModel::ArtistModel(QObject *parent)
|
||||
: AbstractYTMusicModel(parent)
|
||||
, m_view(albums, singles, songs, videos)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
connect(this, &ArtistModel::channelIdChanged, this, [this] {
|
||||
connect(this, &ArtistModel::channelIdChanged, this, [=] {
|
||||
if (m_channelId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
|
||||
auto future = YTMusicThread::instance()->fetchArtist(m_channelId);
|
||||
connectFuture(future, this, [=, this](const artist::Artist &artist) {
|
||||
setLoading(false);
|
||||
|
||||
beginResetModel();
|
||||
m_artist = artist;
|
||||
std::sort(m_artist.thumbnails.begin(), m_artist.thumbnails.end());
|
||||
|
||||
albums = m_artist.albums ? m_artist.albums->results : std::vector<artist::Artist::Album>();
|
||||
singles = m_artist.singles ? m_artist.singles->results : std::vector<artist::Artist::Single>();
|
||||
songs = m_artist.songs ? m_artist.songs->results : std::vector<artist::Artist::Song>();
|
||||
videos = m_artist.videos ? m_artist.videos->results : std::vector<artist::Artist::Video>();
|
||||
|
||||
// std::span can't know if the data pointer underneath it was changed, so re-create
|
||||
m_view = MultiIterableView(albums, singles, songs, videos);
|
||||
endResetModel();
|
||||
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT thumbnailUrlChanged();
|
||||
});
|
||||
YTMusicThread::instance()->fetchArtist(m_channelId);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [this] {
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::fetchArtistFinished, this, [=](const artist::Artist &artist) {
|
||||
setLoading(false);
|
||||
|
||||
beginResetModel();
|
||||
m_artist = artist;
|
||||
std::sort(m_artist.thumbnails.begin(), m_artist.thumbnails.end());
|
||||
|
||||
auto albums = m_artist.albums ? m_artist.albums->results : std::vector<artist::Artist::Album>();
|
||||
auto singles = m_artist.singles ? m_artist.singles->results : std::vector<artist::Artist::Single>();
|
||||
auto songs = m_artist.songs ? m_artist.songs->results : std::vector<artist::Artist::Song>();
|
||||
auto videos = m_artist.videos ? m_artist.videos->results : std::vector<artist::Artist::Video>();
|
||||
|
||||
m_view = std::optional(MultiIterableView(std::move(albums),
|
||||
std::move(singles),
|
||||
std::move(songs),
|
||||
std::move(videos)));
|
||||
endResetModel();
|
||||
|
||||
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT thumbnailUrlChanged();
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [=] {
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
int ArtistModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : m_view.size();
|
||||
return parent.isValid() ? 0 : m_view ? int(m_view->size()) : 0;
|
||||
}
|
||||
|
||||
QVariant ArtistModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!m_view) {
|
||||
return {};
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Title:
|
||||
return QString::fromStdString(std::visit([&](auto&& item) {
|
||||
@@ -65,7 +71,7 @@ QVariant ArtistModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
}, m_view[index.row()]));
|
||||
}, m_view.value()[index.row()]));
|
||||
case Type:
|
||||
return std::visit([&](auto&& item) {
|
||||
using T = std::decay_t<decltype(item)>;
|
||||
@@ -80,7 +86,7 @@ QVariant ArtistModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
}, m_view[index.row()]);
|
||||
}, m_view.value()[index.row()]);
|
||||
case Artists:
|
||||
return QVariant::fromValue(std::vector<meta::Artist> {
|
||||
{
|
||||
@@ -102,7 +108,7 @@ QVariant ArtistModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
}, m_view[index.row()]);
|
||||
}, m_view.value()[index.row()]);
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
@@ -145,20 +151,33 @@ QUrl ArtistModel::thumbnailUrl() const
|
||||
return QUrl(QString::fromStdString(m_artist.thumbnails.back().url));
|
||||
}
|
||||
|
||||
bool ArtistModel::loading() const
|
||||
{
|
||||
return m_loading;
|
||||
}
|
||||
|
||||
void ArtistModel::setLoading(bool loading)
|
||||
{
|
||||
m_loading = loading;
|
||||
Q_EMIT loadingChanged();
|
||||
}
|
||||
|
||||
void ArtistModel::triggerItem(int row)
|
||||
{
|
||||
std::visit([&](auto&& item) {
|
||||
using T = std::decay_t<decltype(item)>;
|
||||
if constexpr(std::is_same_v<T, artist::Artist::Album>) {
|
||||
Q_EMIT openAlbum(QString::fromStdString(item.browse_id));
|
||||
} else if constexpr(std::is_same_v<T, artist::Artist::Single>) {
|
||||
Q_EMIT openAlbum(QString::fromStdString(item.browse_id));
|
||||
} else if constexpr(std::is_same_v<T, artist::Artist::Song>) {
|
||||
Q_EMIT openSong(QString::fromStdString(item.video_id));
|
||||
} else if constexpr(std::is_same_v<T, artist::Artist::Video>) {
|
||||
Q_EMIT openVideo(QString::fromStdString(item.video_id), QString::fromStdString(item.title));
|
||||
} else {
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}, m_view[row]);
|
||||
if (m_view) {
|
||||
std::visit([&](auto&& item) {
|
||||
using T = std::decay_t<decltype(item)>;
|
||||
if constexpr(std::is_same_v<T, artist::Artist::Album>) {
|
||||
Q_EMIT openAlbum(QString::fromStdString(item.browse_id));
|
||||
} else if constexpr(std::is_same_v<T, artist::Artist::Single>) {
|
||||
Q_EMIT openAlbum(QString::fromStdString(item.browse_id));
|
||||
} else if constexpr(std::is_same_v<T, artist::Artist::Song>) {
|
||||
Q_EMIT openSong(QString::fromStdString(item.video_id));
|
||||
} else if constexpr(std::is_same_v<T, artist::Artist::Video>) {
|
||||
Q_EMIT openVideo(QString::fromStdString(item.video_id));
|
||||
} else {
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}, m_view.value()[row]);
|
||||
}
|
||||
}
|
||||
+10
-13
@@ -10,12 +10,9 @@
|
||||
#include <optional>
|
||||
|
||||
#include <ytmusic.h>
|
||||
|
||||
#include "multiiterableview.h"
|
||||
#include "abstractytmusicmodel.h"
|
||||
|
||||
|
||||
class ArtistModel : public AbstractYTMusicModel
|
||||
class ArtistModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -23,6 +20,7 @@ class ArtistModel : public AbstractYTMusicModel
|
||||
|
||||
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
|
||||
Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl NOTIFY thumbnailUrlChanged)
|
||||
Q_PROPERTY(bool loading READ loading WRITE setLoading NOTIFY loadingChanged)
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
@@ -56,23 +54,22 @@ public:
|
||||
QUrl thumbnailUrl() const;
|
||||
Q_SIGNAL void thumbnailUrlChanged();
|
||||
|
||||
bool loading() const;
|
||||
void setLoading(bool loading);
|
||||
Q_SIGNAL void loadingChanged();
|
||||
|
||||
Q_INVOKABLE void triggerItem(int row);
|
||||
|
||||
Q_SIGNAL void openAlbum(const QString &browseId);
|
||||
Q_SIGNAL void openSong(const QString &videoId);
|
||||
Q_SIGNAL void openVideo(const QString &videoId, const QString &title);
|
||||
Q_SIGNAL void openVideo(const QString &videoId);
|
||||
|
||||
private:
|
||||
QString m_channelId;
|
||||
bool m_loading = false;
|
||||
|
||||
artist::Artist m_artist;
|
||||
|
||||
std::vector<artist::Artist::Album> albums;
|
||||
std::vector<artist::Artist::Single> singles;
|
||||
std::vector<artist::Artist::Song> songs;
|
||||
std::vector<artist::Artist::Video> videos;
|
||||
|
||||
MultiIterableView<
|
||||
std::optional<MultiIterableView<
|
||||
artist::Artist::Album, artist::Artist::Single, artist::Artist::Song, artist::Artist::Video
|
||||
> m_view;
|
||||
>> m_view;
|
||||
};
|
||||
+101
-50
@@ -6,9 +6,6 @@
|
||||
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QFutureInterface>
|
||||
|
||||
#include <pybind11/embed.h>
|
||||
|
||||
@@ -16,21 +13,10 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
#include <ranges>
|
||||
#include <type_traits>
|
||||
#include <memory>
|
||||
|
||||
template <typename R, typename T, typename OP>
|
||||
std::optional<R> map_optional(const std::optional<T> &optional, OP op) {
|
||||
if (optional.has_value()) {
|
||||
if constexpr (std::is_member_function_pointer<OP>::value) {
|
||||
return (&optional.value()->*op)();
|
||||
} else {
|
||||
return op(optional.value());
|
||||
}
|
||||
return op(optional.value());
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
@@ -51,6 +37,15 @@ AsyncYTMusic::AsyncYTMusic(QObject *parent)
|
||||
qRegisterMetaType<std::vector<meta::Artist>>();
|
||||
qRegisterMetaType<meta::Artist>();
|
||||
|
||||
connect(this, &AsyncYTMusic::startSearch, this, &AsyncYTMusic::internalSearch);
|
||||
connect(this, &AsyncYTMusic::startFetchArtist, this, &AsyncYTMusic::internalFetchArtist);
|
||||
connect(this, &AsyncYTMusic::startFetchAlbum, this, &AsyncYTMusic::internalFetchAlbum);
|
||||
connect(this, &AsyncYTMusic::startFetchSong, this, &AsyncYTMusic::internalFetchSong);
|
||||
connect(this, &AsyncYTMusic::startFetchPlaylist, this, &AsyncYTMusic::internalFetchPlaylist);
|
||||
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) {
|
||||
std::cerr << qPrintable(err);
|
||||
});
|
||||
@@ -59,83 +54,139 @@ AsyncYTMusic::AsyncYTMusic(QObject *parent)
|
||||
//
|
||||
// search
|
||||
//
|
||||
QFuture<std::vector<search::SearchResultItem>> AsyncYTMusic::search(const QString &query)
|
||||
void AsyncYTMusic::search(const QString &query)
|
||||
{
|
||||
return invokeAndCatchOnThread<std::vector<search::SearchResultItem>>([=, this]() {
|
||||
return m_ytm->search(query.toStdString());
|
||||
});
|
||||
Q_EMIT startSearch(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()));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// fetchArtist
|
||||
//
|
||||
QFuture<artist::Artist> AsyncYTMusic::fetchArtist(const QString &channelId)
|
||||
void AsyncYTMusic::fetchArtist(const QString &channelId)
|
||||
{
|
||||
return invokeAndCatchOnThread<artist::Artist>([=, this]() {
|
||||
return m_ytm->get_artist(channelId.toStdString());
|
||||
});
|
||||
Q_EMIT startFetchArtist(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()));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// fetchAlbum
|
||||
//
|
||||
QFuture<album::Album> AsyncYTMusic::fetchAlbum(const QString &browseId)
|
||||
void AsyncYTMusic::fetchAlbum(const QString &browseId)
|
||||
{
|
||||
return invokeAndCatchOnThread<album::Album>([=, this]() {
|
||||
return m_ytm->get_album(browseId.toStdString());
|
||||
});
|
||||
Q_EMIT startFetchAlbum(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()));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// fetchSong
|
||||
//
|
||||
QFuture<std::optional<song::Song>> AsyncYTMusic::fetchSong(const QString &videoId)
|
||||
void AsyncYTMusic::fetchSong(const QString &videoId)
|
||||
{
|
||||
return invokeAndCatchOnThread<std::optional<song::Song>>([=, this]() {
|
||||
return m_ytm->get_song(videoId.toStdString());
|
||||
});
|
||||
Q_EMIT startFetchSong(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()));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// fetchPlaylist
|
||||
//
|
||||
QFuture<playlist::Playlist> AsyncYTMusic::fetchPlaylist(const QString &playlistId) {
|
||||
return invokeAndCatchOnThread<playlist::Playlist>([=, this]() {
|
||||
return m_ytm->get_playlist(playlistId.toStdString());
|
||||
});
|
||||
void AsyncYTMusic::fetchPlaylist(const QString &playlistId) {
|
||||
Q_EMIT startFetchPlaylist(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()));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// fetchArtistAlbum
|
||||
//
|
||||
QFuture<std::vector<artist::Artist::Album>> AsyncYTMusic::fetchArtistAlbums(const QString &channelId, const QString ¶ms)
|
||||
void AsyncYTMusic::fetchArtistAlbums(const QString &channelId, const QString ¶ms)
|
||||
{
|
||||
return invokeAndCatchOnThread<std::vector<artist::Artist::Album>>([=, this]() {
|
||||
return m_ytm->get_artist_albums(channelId.toStdString(), params.toStdString());
|
||||
});
|
||||
Q_EMIT startFetchArtistAlbums(channelId, params);
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// extractVideoInfo
|
||||
//
|
||||
QFuture<video_info::VideoInfo> AsyncYTMusic::extractVideoInfo(const QString &videoId)
|
||||
void AsyncYTMusic::extractVideoInfo(const QString &videoId)
|
||||
{
|
||||
return invokeAndCatchOnThread<video_info::VideoInfo>([=, this]() {
|
||||
return m_ytm->extract_video_info(videoId.toStdString());
|
||||
});
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// fetchWatchPlaylist
|
||||
//
|
||||
QFuture<watch::Playlist> AsyncYTMusic::fetchWatchPlaylist(const std::optional<QString> &videoId, const std::optional<QString> &playlistId)
|
||||
void AsyncYTMusic::fetchWatchPlaylist(const std::optional<QString> &videoId, const std::optional<QString> &playlistId)
|
||||
{
|
||||
return invokeAndCatchOnThread<watch::Playlist>([=, this]() {
|
||||
return m_ytm->get_watch_playlist(
|
||||
map_optional<std::string>(videoId, &QString::toStdString),
|
||||
map_optional<std::string>(playlistId, &QString::toStdString)
|
||||
);
|
||||
});
|
||||
Q_EMIT startFetchWatchPlaylist(videoId, playlistId);
|
||||
}
|
||||
|
||||
void AsyncYTMusic::internalFetchWatchPlaylist(const std::optional<QString> &videoId, const std::optional<QString> &playlistId)
|
||||
{
|
||||
try {
|
||||
Q_EMIT fetchWatchPlaylistFinished(m_ytm->get_watch_playlist(
|
||||
map_optional<std::string>(videoId, [](const QString &value) { return value.toStdString(); }),
|
||||
map_optional<std::string>(playlistId, [](const QString &value) { return value.toStdString(); })
|
||||
));
|
||||
} catch (const py::error_already_set &err) {
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
}
|
||||
|
||||
YTMusicThread &YTMusicThread::instance()
|
||||
|
||||
+39
-38
@@ -6,8 +6,6 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -39,7 +37,6 @@ public:
|
||||
if (!m_item) {
|
||||
m_item = std::make_unique<T>();
|
||||
}
|
||||
Q_ASSERT(m_item);
|
||||
return m_item;
|
||||
}
|
||||
|
||||
@@ -47,17 +44,6 @@ private:
|
||||
std::unique_ptr<T> m_item = nullptr;
|
||||
};
|
||||
|
||||
template <typename T, typename Function>
|
||||
void connectFuture(const QFuture<T> &future, QObject *self, const Function &fun) {
|
||||
auto watcher = std::make_shared<QFutureWatcher<T>>();
|
||||
watcher->setFuture(future);
|
||||
QObject::connect(watcher.get(), &QFutureWatcherBase::finished, self, [watcher, fun, future] {
|
||||
if (future.resultCount() > 0) {
|
||||
fun(watcher->result());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class AsyncYTMusic : public QObject
|
||||
{
|
||||
friend class YTMusicThread;
|
||||
@@ -66,22 +52,30 @@ class AsyncYTMusic : public QObject
|
||||
|
||||
public:
|
||||
// public functions need to be thread safe
|
||||
QFuture<std::vector<search::SearchResultItem>> search(const QString &query);
|
||||
void search(const QString &query);
|
||||
Q_SIGNAL void searchFinished(std::vector<search::SearchResultItem>);
|
||||
|
||||
QFuture<artist::Artist> fetchArtist(const QString &channelId);
|
||||
void fetchArtist(const QString &channelId);
|
||||
Q_SIGNAL void fetchArtistFinished(artist::Artist);
|
||||
|
||||
QFuture<album::Album> fetchAlbum(const QString &browseId);
|
||||
void fetchAlbum(const QString &browseId);
|
||||
Q_SIGNAL void fetchAlbumFinished(album::Album);
|
||||
|
||||
QFuture<std::optional<song::Song> > fetchSong(const QString &videoId);
|
||||
void fetchSong(const QString &videoId);
|
||||
Q_SIGNAL void fetchSongFinished(song::Song);
|
||||
|
||||
QFuture<playlist::Playlist> fetchPlaylist(const QString &playlistId);
|
||||
void fetchPlaylist(const QString &playlistId);
|
||||
Q_SIGNAL void fetchPlaylistFinished(playlist::Playlist);
|
||||
|
||||
QFuture<std::vector<artist::Artist::Album>> fetchArtistAlbums(const QString &channelId, const QString ¶ms);
|
||||
void fetchArtistAlbums(const QString &channelId, const QString ¶ms);
|
||||
Q_SIGNAL void fetchArtistAlbumsFinished(std::vector<artist::Artist::Album>);
|
||||
|
||||
QFuture<video_info::VideoInfo> extractVideoInfo(const QString &videoId);
|
||||
void extractVideoInfo(const QString &videoId);
|
||||
Q_SIGNAL void extractVideoInfoFinished(video_info::VideoInfo);
|
||||
|
||||
QFuture<watch::Playlist> fetchWatchPlaylist(const std::optional<QString> &videoId = std::nullopt ,
|
||||
void fetchWatchPlaylist(const std::optional<QString> &videoId = std::nullopt ,
|
||||
const std::optional<QString> &playlistId = std::nullopt);
|
||||
Q_SIGNAL void fetchWatchPlaylistFinished(watch::Playlist);
|
||||
|
||||
Q_SIGNAL void errorOccurred(const QString &error);
|
||||
|
||||
@@ -89,22 +83,29 @@ protected:
|
||||
explicit AsyncYTMusic(QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
/// Invokes the given function on the thread of the YTMusic object, and handles exceptions that occur while invoking it.
|
||||
template <typename ReturnType>
|
||||
QFuture<ReturnType> invokeAndCatchOnThread(const std::function<ReturnType()> &fun) {
|
||||
auto interface = std::make_shared<QFutureInterface<ReturnType>>();
|
||||
QMetaObject::invokeMethod(this, [=, this]() {
|
||||
try {
|
||||
ReturnType val = fun();
|
||||
interface->reportResult(val);
|
||||
interface->reportFinished();
|
||||
} catch (const std::exception &err) {
|
||||
interface->reportFinished();
|
||||
Q_EMIT errorOccurred(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
});
|
||||
return interface->future();
|
||||
}
|
||||
Q_SIGNAL void startSearch(const QString &query);
|
||||
Q_SLOT void internalSearch(const QString &query);
|
||||
|
||||
Q_SIGNAL void startFetchArtist(const QString &channelId);
|
||||
Q_SLOT void internalFetchArtist(const QString &channelId);
|
||||
|
||||
Q_SIGNAL void startFetchAlbum(const QString &browseId);
|
||||
Q_SLOT void internalFetchAlbum(const QString &browseId);
|
||||
|
||||
Q_SIGNAL void startFetchSong(const QString &videoId);
|
||||
Q_SLOT void internalFetchSong(const QString &videoId);
|
||||
|
||||
Q_SIGNAL void startFetchPlaylist(const QString &playlistId);
|
||||
Q_SLOT void internalFetchPlaylist(const QString &playlistId);
|
||||
|
||||
Q_SIGNAL void startFetchArtistAlbums(const QString &channelid, const QString ¶ms);
|
||||
Q_SLOT void internalFetchArtistAlbums(const QString &channelid, const QString ¶ms);
|
||||
|
||||
Q_SIGNAL void startExtractVideoInfo(const QString &videoId);
|
||||
Q_SLOT void internalExtractVideoInfo(const QString &videoId);
|
||||
|
||||
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 initialized from the thread calling the methods
|
||||
Lazy<YTMusic> m_ytm;
|
||||
|
||||
@@ -35,16 +35,8 @@ Kirigami.ScrollablePage {
|
||||
play(videoId)
|
||||
}
|
||||
|
||||
onOpenVideo: (videoId, title) => {
|
||||
videoPlayMessage.text = i18n("Video playback is not supported yet. Do you want to play only the audio of \"%1\"?", title)
|
||||
videoPlayMessage.visible = true
|
||||
videoPlayMessage.okAction = function() {
|
||||
play(videoId)
|
||||
videoPlayMessage.visible = false
|
||||
}
|
||||
videoPlayMessage.cancelAction = function() {
|
||||
videoPlayMessage.visible = false
|
||||
}
|
||||
onOpenVideo: (videoId) => {
|
||||
askPlayVideoAudio(videoId)
|
||||
}
|
||||
}
|
||||
section.property: "type"
|
||||
@@ -118,8 +110,4 @@ Kirigami.ScrollablePage {
|
||||
visible: artistModel.loading
|
||||
}
|
||||
}
|
||||
|
||||
footer: ConfirmationMessage {
|
||||
id: videoPlayMessage
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2021 Dimitris Kardarakos <[email protected]>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
import QtQuick 2.15
|
||||
import org.kde.kirigami 2.14 as Kirigami
|
||||
|
||||
Kirigami.InlineMessage {
|
||||
|
||||
property var okAction
|
||||
property var cancelAction
|
||||
|
||||
visible: false
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
text: i18n("OK")
|
||||
|
||||
onTriggered: okAction()
|
||||
},
|
||||
Kirigami.Action {
|
||||
text: i18n("Cancel")
|
||||
|
||||
onTriggered: cancelAction()
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
import QtQuick 2.1
|
||||
import QtQuick.Controls 2.12 as Controls
|
||||
import QtQuick.Layouts 1.3
|
||||
import org.kde.kirigami 2.14 as Kirigami
|
||||
|
||||
import org.kde.ytmusic 1.0
|
||||
|
||||
Kirigami.ScrollablePage {
|
||||
ColumnLayout {
|
||||
Kirigami.Heading {
|
||||
text: i18n("Favourites")
|
||||
}
|
||||
Controls.ScrollView {
|
||||
Layout.fillWidth: true
|
||||
RowLayout {
|
||||
Repeater {
|
||||
Layout.fillWidth: true
|
||||
model: Library.favourites
|
||||
onCountChanged: () => console.log("Count:", count)
|
||||
delegate: ColumnLayout {
|
||||
Layout.fillWidth: false
|
||||
Layout.maximumWidth: 200
|
||||
Component.onCompleted: {
|
||||
console.log(modelData)
|
||||
}
|
||||
Kirigami.Card {
|
||||
id: card
|
||||
Layout.preferredHeight: 200
|
||||
|
||||
onClicked: play(modelData)
|
||||
|
||||
ThumbnailSource {
|
||||
id: thumbnailSource
|
||||
videoId: modelData
|
||||
}
|
||||
|
||||
header: Image {
|
||||
sourceSize: "200x200"
|
||||
source: thumbnailSource.cachedPath
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
asynchronous: true
|
||||
}
|
||||
}
|
||||
Controls.Label {
|
||||
Layout.maximumWidth: 200
|
||||
text: Library.videoTitle(modelData)
|
||||
elide: Qt.ElideRight
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+200
-213
@@ -9,256 +9,243 @@ import org.kde.kirigami 2.12 as Kirigami
|
||||
import org.kde.ytmusic 1.0
|
||||
import QtMultimedia 5.12
|
||||
|
||||
Item {
|
||||
id: footerItem
|
||||
ColumnLayout {
|
||||
id: footerLayout
|
||||
|
||||
property bool maximized: false
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: maximized ? applicationWindow().height : 75
|
||||
height: maximized ? applicationWindow().height : player.preferredHeight
|
||||
|
||||
Rectangle {
|
||||
color: Kirigami.Theme.backgroundColor
|
||||
Kirigami.Theme.colorSet: Kirigami.Theme.Window
|
||||
anchors.fill: footerLayout
|
||||
GridLayout {
|
||||
id: playerLayout
|
||||
|
||||
readonly property bool mobile: width > height
|
||||
|
||||
Layout.fillHeight: footerLayout.maximized
|
||||
Layout.fillWidth: true
|
||||
flow: width > height ? GridLayout.LeftToRight : GridLayout.TopToBottom
|
||||
visible: footerLayout.maximized
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: info.thumbnail
|
||||
Layout.fillHeight: info.thumbnail
|
||||
Image {
|
||||
anchors.fill: parent
|
||||
|
||||
source: info.thumbnail
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
Controls.ScrollView {
|
||||
anchors.fill: parent
|
||||
|
||||
ListView {
|
||||
anchors.fill: parent
|
||||
id: playlistView
|
||||
|
||||
clip: true
|
||||
|
||||
Controls.BusyIndicator {
|
||||
anchors.centerIn: parent
|
||||
visible: UserPlaylistModel.loading || UserPlaylistModel.loading
|
||||
}
|
||||
|
||||
onCountChanged: {
|
||||
if (count < 1) {
|
||||
footerLayout.maximized = false
|
||||
}
|
||||
}
|
||||
|
||||
model: UserPlaylistModel
|
||||
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
id: delegateItem
|
||||
required property string title
|
||||
required property string videoId
|
||||
required property string artists
|
||||
required property bool isCurrent
|
||||
|
||||
highlighted: isCurrent
|
||||
onClicked: UserPlaylistModel.skipTo(videoId)
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
Kirigami.Heading {
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
level: 2
|
||||
text: title
|
||||
}
|
||||
|
||||
Controls.Label {
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
text: artists
|
||||
}
|
||||
}
|
||||
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
text: i18n("Remove Track")
|
||||
icon.name: "list-remove"
|
||||
onTriggered: UserPlaylistModel.remove(delegateItem.videoId)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
header: Controls.ToolBar {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
text: i18n("Clear")
|
||||
icon.name: "edit-clear-all"
|
||||
onClicked: UserPlaylistModel.clear()
|
||||
}
|
||||
Controls.ToolButton {
|
||||
text: i18n("Shuffle")
|
||||
icon.name: "media-playlist-shuffle"
|
||||
onClicked: UserPlaylistModel.shufflePlaylist()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: footerLayout
|
||||
height: parent.height
|
||||
anchors.fill: parent
|
||||
Kirigami.Separator {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
GridLayout {
|
||||
id: playerLayout
|
||||
RowLayout {
|
||||
id: player
|
||||
|
||||
readonly property bool mobile: width > height
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: !footer.maximized
|
||||
|
||||
Layout.fillHeight: footerItem.maximized
|
||||
Layout.fillWidth: true
|
||||
flow: width > height ? GridLayout.LeftToRight : GridLayout.TopToBottom
|
||||
visible: footerItem.maximized
|
||||
VideoInfoExtractor {
|
||||
id: info
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: info.thumbnail
|
||||
Layout.fillHeight: info.thumbnail
|
||||
Image {
|
||||
source: info.thumbnail
|
||||
Layout.preferredWidth: footerLayout.width * 0.5
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
Controls.ToolButton{
|
||||
text: "Fav"
|
||||
onClicked: Library.addFavourite(info.videoId)
|
||||
onSongChanged: audio.play()
|
||||
videoId: UserPlaylistModel.currentVideoId
|
||||
}
|
||||
|
||||
Audio {
|
||||
id: audio
|
||||
|
||||
source: info.audioUrl
|
||||
onStatusChanged: {
|
||||
if (status === Audio.EndOfMedia) {
|
||||
console.log("Song ended");
|
||||
UserPlaylistModel.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Controls.ToolButton {
|
||||
display: Controls.AbstractButton.IconOnly
|
||||
Layout.preferredWidth: parent.height
|
||||
Layout.fillHeight: true
|
||||
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()
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
display: Controls.AbstractButton.IconOnly
|
||||
Layout.preferredWidth: parent.height
|
||||
Layout.fillHeight: true
|
||||
enabled: UserPlaylistModel.canSkip
|
||||
visible: !info.loading
|
||||
icon.name: "media-skip-forward"
|
||||
onClicked: UserPlaylistModel.next()
|
||||
}
|
||||
|
||||
Controls.BusyIndicator {
|
||||
Layout.fillHeight: true
|
||||
visible: info.loading
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillHeight: true
|
||||
Layout.topMargin: Kirigami.Units.smallSpacing
|
||||
Layout.bottomMargin: Kirigami.Units.smallSpacing
|
||||
|
||||
Kirigami.Heading {
|
||||
level: 3
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
elide: Qt.ElideRight
|
||||
text: info.title ? info.title : i18n("No media playing")
|
||||
}
|
||||
|
||||
Controls.ScrollView {
|
||||
anchors.fill: parent
|
||||
RowLayout{
|
||||
|
||||
ListView {
|
||||
anchors.fill: parent
|
||||
id: playlistView
|
||||
|
||||
clip: true
|
||||
|
||||
Controls.BusyIndicator {
|
||||
anchors.centerIn: parent
|
||||
visible: UserPlaylistModel.loading || UserPlaylistModel.loading
|
||||
}
|
||||
|
||||
onCountChanged: {
|
||||
if (count < 1) {
|
||||
footerItem.maximized = false
|
||||
}
|
||||
}
|
||||
|
||||
model: UserPlaylistModel
|
||||
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
id: delegateItem
|
||||
required property string title
|
||||
required property string videoId
|
||||
required property string artists
|
||||
required property bool isCurrent
|
||||
|
||||
highlighted: isCurrent
|
||||
onClicked: UserPlaylistModel.skipTo(videoId)
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
Kirigami.Heading {
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
level: 2
|
||||
text: title
|
||||
}
|
||||
|
||||
Controls.Label {
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
text: artists
|
||||
}
|
||||
}
|
||||
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
text: i18n("Remove Track")
|
||||
icon.name: "list-remove"
|
||||
onTriggered: UserPlaylistModel.remove(delegateItem.videoId)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
header: Controls.ToolBar {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
text: i18n("Clear")
|
||||
icon.name: "edit-clear-all"
|
||||
onClicked: UserPlaylistModel.clear()
|
||||
}
|
||||
Controls.ToolButton {
|
||||
text: i18n("Shuffle")
|
||||
icon.name: "media-playlist-shuffle"
|
||||
onClicked: UserPlaylistModel.shufflePlaylist()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Controls.Label{
|
||||
visible: audio.duration > 0
|
||||
text: PlayerUtils.formatTimestamp(audio.position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Kirigami.Separator {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: player
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: !footer.maximized
|
||||
|
||||
VideoInfoExtractor {
|
||||
id: info
|
||||
|
||||
onSongChanged: audio.play()
|
||||
videoId: UserPlaylistModel.currentVideoId
|
||||
}
|
||||
|
||||
Audio {
|
||||
id: audio
|
||||
|
||||
source: info.audioUrl
|
||||
onStatusChanged: {
|
||||
if (status === Audio.EndOfMedia) {
|
||||
console.log("Song ended");
|
||||
UserPlaylistModel.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
display: Controls.AbstractButton.IconOnly
|
||||
Layout.preferredWidth: parent.height
|
||||
Layout.fillHeight: true
|
||||
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()
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
display: Controls.AbstractButton.IconOnly
|
||||
Layout.preferredWidth: parent.height
|
||||
Layout.fillHeight: true
|
||||
enabled: UserPlaylistModel.canSkip
|
||||
visible: !info.loading
|
||||
icon.name: "media-skip-forward"
|
||||
onClicked: UserPlaylistModel.next()
|
||||
}
|
||||
|
||||
Controls.BusyIndicator {
|
||||
Layout.fillHeight: true
|
||||
visible: info.loading
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillHeight: true
|
||||
Layout.topMargin: Kirigami.Units.smallSpacing
|
||||
Layout.bottomMargin: Kirigami.Units.smallSpacing
|
||||
|
||||
Kirigami.Heading {
|
||||
level: 3
|
||||
Controls.Slider {
|
||||
Layout.fillWidth: true
|
||||
elide: Qt.ElideRight
|
||||
text: info.title ? info.title : i18n("No media playing")
|
||||
}
|
||||
|
||||
RowLayout{
|
||||
|
||||
Controls.Label{
|
||||
visible: info.title
|
||||
text: PlayerUtils.formatTimestamp(audio.position)
|
||||
from: 0
|
||||
to: audio.duration
|
||||
value: audio.position
|
||||
enabled: audio.seekable
|
||||
onMoved: {
|
||||
console.log("Value:", value);
|
||||
audio.seek(Math.floor(value));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
Behavior on value {
|
||||
NumberAnimation {
|
||||
duration: 1000
|
||||
}
|
||||
|
||||
Behavior on value {
|
||||
NumberAnimation {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Controls.Label{
|
||||
visible: info.title
|
||||
text: PlayerUtils.formatTimestamp(audio.duration)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Controls.Label{
|
||||
visible: audio.duration > 0
|
||||
text: PlayerUtils.formatTimestamp(audio.duration)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
display: Controls.AbstractButton.IconOnly
|
||||
Layout.preferredWidth: parent.height
|
||||
text: i18n("Expand")
|
||||
enabled: playlistView.count > 0
|
||||
Layout.fillHeight: true
|
||||
icon.name: footerItem.maximized ? "arrow-down" : "arrow-up"
|
||||
onClicked: footerItem.maximized = !footerItem.maximized
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,34 +10,22 @@ import org.kde.kirigami 2.14 as Kirigami
|
||||
import org.kde.ytmusic 1.0
|
||||
|
||||
Kirigami.ScrollablePage {
|
||||
property alias searchQuery: searchModel.searchQuery
|
||||
title: i18n("Youtube Music")
|
||||
|
||||
title: searchQuery
|
||||
header: Controls.Control {
|
||||
padding: Kirigami.Units.largeSpacing
|
||||
contentItem: Kirigami.SearchField {
|
||||
delaySearch: true
|
||||
selectByMouse: true
|
||||
onAccepted: {
|
||||
searchModel.searchQuery = text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
reuseItems: true
|
||||
|
||||
section.delegate: Kirigami.ListSectionHeader {
|
||||
required property string section
|
||||
text: {
|
||||
switch (parseInt(section)) {
|
||||
case SearchModel.Album:
|
||||
return i18n("Albums")
|
||||
case SearchModel.Artist:
|
||||
return i18n("Artists")
|
||||
case SearchModel.Playlist:
|
||||
return i18n("Playlists")
|
||||
case SearchModel.Song:
|
||||
return i18n("Songs")
|
||||
case SearchModel.Video:
|
||||
return i18n("Videos")
|
||||
}
|
||||
|
||||
return i18n("Unknown")
|
||||
}
|
||||
}
|
||||
section.property: "type"
|
||||
|
||||
model: SearchModel {
|
||||
id: searchModel
|
||||
|
||||
@@ -63,16 +51,8 @@ Kirigami.ScrollablePage {
|
||||
play(videoId)
|
||||
}
|
||||
|
||||
onOpenVideo: (videoId, title) => {
|
||||
videoPlayMessage.text = i18n("Video playback is not supported yet. Do you want to play only the audio of \"%1\"?", title)
|
||||
videoPlayMessage.visible = true
|
||||
videoPlayMessage.okAction = function() {
|
||||
play(videoId)
|
||||
videoPlayMessage.visible = false
|
||||
}
|
||||
videoPlayMessage.cancelAction = function() {
|
||||
videoPlayMessage.visible = false
|
||||
}
|
||||
onOpenVideo: (videoId) => {
|
||||
askPlayVideoAudio(videoId)
|
||||
}
|
||||
}
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
@@ -82,7 +62,6 @@ Kirigami.ScrollablePage {
|
||||
required property int type
|
||||
required property string videoId
|
||||
required property var artists
|
||||
required property string radioPlaylistId
|
||||
|
||||
RowLayout {
|
||||
Layout.fillHeight: true
|
||||
@@ -115,20 +94,14 @@ Kirigami.ScrollablePage {
|
||||
Kirigami.Action {
|
||||
icon.name: "go-next"
|
||||
text: i18n("Play next")
|
||||
visible: delegateItem.type === SearchModel.Song || delegateItem.type == SearchModel.Video
|
||||
visible: delegateItem.type === SearchModel.Song
|
||||
onTriggered: UserPlaylistModel.playNext(delegateItem.videoId, delegateItem.title, delegateItem.artists)
|
||||
},
|
||||
Kirigami.Action {
|
||||
icon.name: "media-playlist-append"
|
||||
text: i18n("Add to Playlist")
|
||||
visible: delegateItem.type === SearchModel.Song || delegateItem.type == SearchModel.Video
|
||||
visible: delegateItem.type === SearchModel.Song
|
||||
onTriggered: UserPlaylistModel.append(delegateItem.videoId, delegateItem.title, delegateItem.artists)
|
||||
},
|
||||
Kirigami.Action {
|
||||
icon.name: "radio"
|
||||
text: i18n("Radio")
|
||||
visible: delegateItem.type === SearchModel.Artist && delegateItem.radioPlaylistId
|
||||
onTriggered: playPlaylist(delegateItem.radioPlaylistId)
|
||||
}
|
||||
]
|
||||
|
||||
@@ -138,22 +111,5 @@ Kirigami.ScrollablePage {
|
||||
anchors.centerIn: parent
|
||||
visible: searchModel.loading
|
||||
}
|
||||
Kirigami.PlaceholderMessage {
|
||||
anchors.centerIn: parent
|
||||
width: parent.width - (Kirigami.Units.largeSpacing * 4)
|
||||
|
||||
visible: parent.count === 0 && !searchModel.loading
|
||||
|
||||
text: i18n("Find music on YouTube Music")
|
||||
helpfulAction: Kirigami.Action {
|
||||
onTriggered: searchField.forceActiveFocus()
|
||||
text: i18n("Search")
|
||||
icon.name: "search"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer: ConfirmationMessage {
|
||||
id: videoPlayMessage
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
import QtQuick 2.1
|
||||
import QtQuick.Controls 2.12 as Controls
|
||||
import QtQuick.Layouts 1.3
|
||||
import org.kde.kirigami 2.14 as Kirigami
|
||||
|
||||
import org.kde.ytmusic 1.0
|
||||
@@ -12,81 +10,6 @@ import org.kde.ytmusic 1.0
|
||||
Kirigami.ApplicationWindow {
|
||||
id: root
|
||||
|
||||
property alias searchField: searchField
|
||||
|
||||
header: Controls.Control {
|
||||
visible: !footer.maximized
|
||||
padding: Kirigami.Units.largeSpacing
|
||||
|
||||
background: Rectangle {
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
anchors.fill: parent
|
||||
Kirigami.Theme.inherit: false
|
||||
Kirigami.Theme.colorSet: Kirigami.Theme.Header
|
||||
color: Kirigami.Theme.backgroundColor
|
||||
}
|
||||
contentItem: RowLayout{
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Kirigami.SearchField {
|
||||
id: searchField
|
||||
delaySearch: true
|
||||
selectByMouse: true
|
||||
Layout.fillWidth: true
|
||||
Layout.maximumWidth: 400
|
||||
onFocusChanged: {
|
||||
if (focus)
|
||||
popup.open()
|
||||
}
|
||||
onTextChanged: {
|
||||
if (!popup.opened) {
|
||||
popup.open()
|
||||
}
|
||||
}
|
||||
|
||||
Controls.Popup {
|
||||
id: popup
|
||||
x: searchField.y
|
||||
y: searchField.y + searchField.height
|
||||
visible: true
|
||||
width: searchField.width
|
||||
height: contentItem.implicitHeight
|
||||
|
||||
contentItem: Controls.ScrollView {
|
||||
Controls.ScrollBar.horizontal.policy: Controls.ScrollBar.AlwaysOff
|
||||
ListView {
|
||||
id: completionList
|
||||
model: Library.searches
|
||||
delegate: Controls.ItemDelegate {
|
||||
width: parent.width
|
||||
text: modelData
|
||||
onClicked: {
|
||||
searchField.text = modelData
|
||||
searchField.accepted()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onAccepted: {
|
||||
pageStack.clear()
|
||||
if (text) {
|
||||
Library.addSearch(text)
|
||||
}
|
||||
pageStack.push("qrc:/SearchPage.qml", {
|
||||
"searchQuery": text})
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
title: i18n("AudioTube")
|
||||
|
||||
controlsVisible: !footer.maximized
|
||||
@@ -95,7 +18,7 @@ Kirigami.ApplicationWindow {
|
||||
id: contextDrawer
|
||||
}
|
||||
|
||||
pageStack.initialPage: "qrc:/LibraryPage.qml"
|
||||
pageStack.initialPage: "qrc:/SearchPage.qml"
|
||||
|
||||
function play(videoId) {
|
||||
UserPlaylistModel.initialVideoId = videoId
|
||||
@@ -110,6 +33,14 @@ Kirigami.ApplicationWindow {
|
||||
UserPlaylistModel.playlistId = playlistId
|
||||
}
|
||||
|
||||
function askPlayVideoAudio(videoId) {
|
||||
showPassiveNotification(i18n("Video playback is not supported yet."),
|
||||
"long",
|
||||
i18n("Play only Audio"),
|
||||
function() {
|
||||
play(videoId)
|
||||
})
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: ErrorHandler
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
int main() {
|
||||
const auto ytm = YTMusic();
|
||||
const auto results = ytm.search("Another one bites the dust");
|
||||
const auto results = ytm.search("Thomas Bangalter");
|
||||
|
||||
std::cout << "Found " << results.size() << " results." << std::endl;
|
||||
|
||||
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
#include "library.h"
|
||||
|
||||
#include <QStandardPaths>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QStringBuilder>
|
||||
|
||||
#include <qpersistentdata.h>
|
||||
|
||||
Library::Library(QObject *parent)
|
||||
: QObject{parent}
|
||||
, m_storage("library")
|
||||
, m_cachedVideoTitles("videoTitles")
|
||||
{
|
||||
connect(this, &Library::favouritesChanged, this, []() {
|
||||
qDebug() << "Favs changed" ;
|
||||
});
|
||||
}
|
||||
|
||||
Library &Library::instance()
|
||||
{
|
||||
static Library inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
QStringList Library::favourites() const
|
||||
{
|
||||
return m_storage.value<QStringList>("favourites");
|
||||
}
|
||||
|
||||
void Library::addFavourite(const QString &videoId)
|
||||
{
|
||||
auto favs = favourites();
|
||||
favs.push_front(videoId);
|
||||
m_storage.insert("favourites", favs);
|
||||
Q_EMIT favouritesChanged();
|
||||
}
|
||||
|
||||
QStringList Library::searches() const
|
||||
{
|
||||
auto s = m_storage.value<QStringList>("searches");
|
||||
qDebug() << "searches" << s;
|
||||
return s;
|
||||
}
|
||||
|
||||
void Library::addSearch(const QString &text)
|
||||
{
|
||||
m_storage.insert("searches", searches() << text);
|
||||
Q_EMIT searchesChanged();
|
||||
}
|
||||
|
||||
QStringList Library::playbackHistory() const
|
||||
{
|
||||
auto h = m_storage.value<QStringList>("playbackHistory");
|
||||
return h;
|
||||
}
|
||||
|
||||
void Library::addPlaybackHistoryItem(const QString &videoId)
|
||||
{
|
||||
m_storage.insert("playbackHistory", playbackHistory() << videoId);
|
||||
Q_EMIT playbackHistoryChanged();
|
||||
}
|
||||
|
||||
QString Library::videoTitle(const QString &videoId)
|
||||
{
|
||||
qDebug() << "Fetching video title" << videoId;
|
||||
auto t = m_cachedVideoTitles.value<QString>(videoId);
|
||||
qDebug() << "title" << t;
|
||||
return t;
|
||||
}
|
||||
|
||||
void Library::addVideoTitle(const QString &videoId, const QString &title)
|
||||
{
|
||||
m_cachedVideoTitles.insert(videoId, title);
|
||||
}
|
||||
|
||||
QNetworkAccessManager &Library::nam()
|
||||
{
|
||||
return m_networkImageCacher;
|
||||
}
|
||||
|
||||
void ThumbnailSource::setVideoId(const QString &id) {
|
||||
if (m_videoId == id) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_videoId = id;
|
||||
Q_EMIT videoIdChanged();
|
||||
|
||||
const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) % QDir::separator() % "thumbnails";
|
||||
QDir(cacheDir).mkpath(QStringLiteral("."));
|
||||
const QString cacheLocation = cacheDir % QDir::separator() % id % ".webp";
|
||||
|
||||
if (QFile::exists(cacheLocation)) {
|
||||
setCachedPath(QUrl::fromLocalFile(cacheLocation));
|
||||
return;
|
||||
}
|
||||
|
||||
auto future = YTMusicThread::instance()->extractVideoInfo(id);
|
||||
connectFuture(future, this, [this, id, cacheLocation](video_info::VideoInfo &&info) {
|
||||
auto *reply = Library::instance().nam().get(QNetworkRequest(QUrl(QString::fromStdString(info.thumbnail))));
|
||||
connect(reply, &QNetworkReply::finished, this, [id, reply, this, cacheLocation]() {
|
||||
QFile file(cacheLocation);
|
||||
file.open(QFile::WriteOnly);
|
||||
file.write(reply->readAll());
|
||||
setCachedPath(QUrl::fromLocalFile(cacheLocation));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQuickAsyncImageProvider>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <qpersistentdata.h>
|
||||
|
||||
#include "asyncytmusic.h"
|
||||
|
||||
class Library : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QStringList favourites READ favourites NOTIFY favouritesChanged)
|
||||
Q_PROPERTY(QStringList searches READ searches NOTIFY searchesChanged)
|
||||
Q_PROPERTY(QStringList playbackHistory READ playbackHistory NOTIFY playbackHistoryChanged)
|
||||
|
||||
public:
|
||||
explicit Library(QObject *parent = nullptr);
|
||||
|
||||
static Library &instance();
|
||||
|
||||
QStringList favourites() const;
|
||||
Q_SIGNAL void favouritesChanged();
|
||||
Q_INVOKABLE void addFavourite(const QString &videoId);
|
||||
|
||||
QStringList searches() const;
|
||||
Q_SIGNAL void searchesChanged();
|
||||
Q_INVOKABLE void addSearch(const QString &text);
|
||||
|
||||
QStringList playbackHistory() const;
|
||||
Q_SIGNAL void playbackHistoryChanged();
|
||||
Q_INVOKABLE void addPlaybackHistoryItem(const QString &videoId);
|
||||
|
||||
Q_INVOKABLE QString videoTitle(const QString &videoId);
|
||||
Q_INVOKABLE void addVideoTitle(const QString &videoId, const QString &title);
|
||||
|
||||
QNetworkAccessManager &nam();
|
||||
|
||||
private:
|
||||
QNetworkAccessManager m_networkImageCacher;
|
||||
QPersistentData m_storage;
|
||||
QPersistentData m_cachedVideoTitles;
|
||||
};
|
||||
|
||||
|
||||
class ThumbnailSource : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString videoId READ videoId WRITE setVideoId NOTIFY videoIdChanged)
|
||||
Q_PROPERTY(QUrl cachedPath READ cachedPath NOTIFY cachedPathChanged)
|
||||
|
||||
QString videoId() const {
|
||||
return m_videoId;
|
||||
}
|
||||
void setVideoId(const QString &id);
|
||||
Q_SIGNAL void videoIdChanged();
|
||||
|
||||
QUrl cachedPath() const {
|
||||
return m_cachedPath;
|
||||
}
|
||||
void setCachedPath(const QUrl &path) {
|
||||
m_cachedPath = path;
|
||||
cachedPathChanged();
|
||||
}
|
||||
Q_SIGNAL void cachedPathChanged();
|
||||
|
||||
private:
|
||||
QString m_videoId;
|
||||
QUrl m_cachedPath;
|
||||
};
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "errorhandler.h"
|
||||
#include "playlistmodel.h"
|
||||
#include "playerutils.h"
|
||||
#include "library.h"
|
||||
|
||||
constexpr auto URI = "org.kde.ytmusic";
|
||||
|
||||
@@ -52,10 +51,6 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
qmlRegisterSingletonType<PlayerUtils>(URI, 1, 0, "PlayerUtils", [](QQmlEngine *, QJSEngine *) {
|
||||
return new PlayerUtils();
|
||||
});
|
||||
qmlRegisterSingletonType<Library>(URI, 1, 0, "Library", [](QQmlEngine *, QJSEngine *) {
|
||||
return new Library();
|
||||
});
|
||||
qmlRegisterType<ThumbnailSource>(URI, 1, 0, "ThumbnailSource");
|
||||
|
||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
||||
|
||||
+55
-52
@@ -6,68 +6,71 @@
|
||||
|
||||
#include <variant>
|
||||
#include <tuple>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include <QtGlobal>
|
||||
|
||||
template <typename Tuple, typename Func, std::size_t i>
|
||||
inline constexpr void iterate_impl(Tuple &tup, Func fun)
|
||||
{
|
||||
if constexpr(i >= std::tuple_size_v<std::decay_t<decltype(tup)>>) {
|
||||
return;
|
||||
} else {
|
||||
fun(std::get<i>(tup));
|
||||
return iterate_impl<Tuple, Func, i + 1>(tup, fun);
|
||||
}
|
||||
}
|
||||
// MultiIterableView is usually used on a small number of vectors.
|
||||
// The number is already known, so we can convert this into an if else if else etc tree
|
||||
// instead of recursively calling the function
|
||||
#ifdef __GNUC__
|
||||
#define REMOVE_RECURSION __attribute__((always_inline))
|
||||
#else
|
||||
#define REMOVE_RECURSION
|
||||
#endif
|
||||
|
||||
template <typename Tuple, typename Func>
|
||||
inline constexpr void iterate_tuple(Tuple &tup, Func fun)
|
||||
{
|
||||
iterate_impl<Tuple, Func, 0>(tup, fun);
|
||||
}
|
||||
|
||||
/// MultiIterableView is a view over multiple contigous memory arrays, like std::vector or std::array.
|
||||
/// The elements of the arrays do not need to be of the same type.
|
||||
template <typename... Arguments>
|
||||
class MultiIterableView {
|
||||
public:
|
||||
explicit MultiIterableView(std::span<Arguments>... lists)
|
||||
: m_vectors(std::forward_as_tuple(lists...))
|
||||
{
|
||||
private:
|
||||
template<typename T, size_t i, size_t len>
|
||||
REMOVE_RECURSION inline size_t count(const T &tuple, int initial_size = 0) const {
|
||||
if constexpr(i < len) {
|
||||
return count<T, i + 1, len>(tuple, initial_size + std::get<i>(tuple).size());
|
||||
} else {
|
||||
return initial_size;
|
||||
}
|
||||
}
|
||||
|
||||
explicit MultiIterableView(std::vector<Arguments> &...lists)
|
||||
: MultiIterableView(std::span{lists}...)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr size_t size() const {
|
||||
size_t s = 0;
|
||||
iterate_tuple(m_vectors, [&](auto &vec) {
|
||||
s += vec.size();
|
||||
});
|
||||
return s;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr std::variant<Arguments...> operator[](size_t i) const {
|
||||
size_t s = 0;
|
||||
std::variant<Arguments...> out;
|
||||
iterate_tuple(m_vectors, [&](auto &vec) {
|
||||
if (i >= s && i < s + vec.size()) {
|
||||
out = vec[i - s];
|
||||
template<typename T, size_t tuple_i, size_t tuple_len>
|
||||
REMOVE_RECURSION inline std::variant<Arguments...> get_item(const T &tuple, size_t i) const {
|
||||
if constexpr(tuple_i < tuple_len) {
|
||||
if (i < std::get<tuple_i>(tuple).size()) {
|
||||
return std::get<tuple_i>(tuple)[i];
|
||||
} else {
|
||||
return get_item<T, tuple_i + 1, tuple_len>(tuple, i - std::get<tuple_i>(tuple).size());
|
||||
}
|
||||
s += vec.size();
|
||||
});
|
||||
return out;
|
||||
} else {
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool empty() const {
|
||||
bool empty = true;
|
||||
iterate_tuple(m_vectors, [&](auto &elem) {
|
||||
empty &= elem.empty();
|
||||
});
|
||||
return empty;
|
||||
template<typename T, size_t i, size_t len>
|
||||
REMOVE_RECURSION inline bool everything_empty(const T &tuple, bool initial_state = true) const {
|
||||
if constexpr(i < len) {
|
||||
return everything_empty<T, i + 1, len>(tuple, initial_state && std::get<i>(tuple).empty());
|
||||
} else {
|
||||
return initial_state;
|
||||
}
|
||||
}
|
||||
public:
|
||||
explicit MultiIterableView(std::vector<Arguments> &&...lists)
|
||||
: m_vectors(std::make_tuple(lists...))
|
||||
{
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
constexpr size_t nvecs = std::tuple_size_v<decltype(m_vectors)>;
|
||||
return count<decltype(m_vectors), 0, nvecs>(m_vectors);
|
||||
}
|
||||
|
||||
std::variant<Arguments...> operator[](size_t i) const {
|
||||
constexpr size_t nvecs = std::tuple_size_v<decltype(m_vectors)>;
|
||||
return get_item<decltype(m_vectors), 0, nvecs>(m_vectors, i);
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
constexpr size_t nvecs = std::tuple_size_v<decltype(m_vectors)>;
|
||||
return everything_empty<decltype(m_vectors), 0, nvecs>(m_vectors);
|
||||
}
|
||||
private:
|
||||
std::tuple<std::span<Arguments>...> m_vectors;
|
||||
std::tuple<std::vector<Arguments>...> m_vectors;
|
||||
};
|
||||
+23
-12
@@ -11,21 +11,21 @@
|
||||
#include "playlistutils.h"
|
||||
|
||||
PlaylistModel::PlaylistModel(QObject *parent)
|
||||
: AbstractYTMusicModel(parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
connect(this, &PlaylistModel::playlistIdChanged, this, [=, this] {
|
||||
connect(this, &PlaylistModel::playlistIdChanged, this, [=] {
|
||||
setLoading(true);
|
||||
auto future = YTMusicThread::instance()->fetchPlaylist(m_playlistId);
|
||||
connectFuture(future, this, [=, this](const playlist::Playlist &playlist) {
|
||||
setLoading(false);
|
||||
beginResetModel();
|
||||
m_playlist = playlist;
|
||||
std::sort(m_playlist.thumbnails.begin(), m_playlist.thumbnails.end());
|
||||
endResetModel();
|
||||
YTMusicThread::instance()->fetchPlaylist(m_playlistId);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::fetchPlaylistFinished, this, [=](const playlist::Playlist &playlist) {
|
||||
setLoading(false);
|
||||
beginResetModel();
|
||||
m_playlist = playlist;
|
||||
std::sort(m_playlist.thumbnails.begin(), m_playlist.thumbnails.end());
|
||||
endResetModel();
|
||||
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT thumbnailUrlChanged();
|
||||
});
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT thumbnailUrlChanged();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,6 +76,17 @@ void PlaylistModel::setPlaylistId(const QString &playlistId)
|
||||
Q_EMIT playlistIdChanged();
|
||||
}
|
||||
|
||||
bool PlaylistModel::loading() const
|
||||
{
|
||||
return m_loading;
|
||||
}
|
||||
|
||||
void PlaylistModel::setLoading(bool loading)
|
||||
{
|
||||
m_loading = loading;
|
||||
Q_EMIT loadingChanged();
|
||||
}
|
||||
|
||||
QUrl PlaylistModel::thumbnailUrl() const
|
||||
{
|
||||
if (m_playlist.thumbnails.empty()) {
|
||||
|
||||
+7
-3
@@ -7,9 +7,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <ytmusic.h>
|
||||
|
||||
#include "abstractytmusicmodel.h"
|
||||
|
||||
class PlaylistModel : public AbstractYTMusicModel
|
||||
class PlaylistModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -17,6 +15,7 @@ class PlaylistModel : public AbstractYTMusicModel
|
||||
Q_PROPERTY(QString playlistId READ playlistId WRITE setPlaylistId NOTIFY playlistIdChanged REQUIRED)
|
||||
|
||||
// output
|
||||
Q_PROPERTY(bool loading READ loading WRITE setLoading NOTIFY loadingChanged)
|
||||
Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl NOTIFY thumbnailUrlChanged)
|
||||
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
|
||||
|
||||
@@ -37,6 +36,10 @@ public:
|
||||
void setPlaylistId(const QString &playlistId);
|
||||
Q_SIGNAL void playlistIdChanged();
|
||||
|
||||
bool loading() const;
|
||||
void setLoading(bool loading);
|
||||
Q_SIGNAL void loadingChanged();
|
||||
|
||||
QUrl thumbnailUrl() const;
|
||||
Q_SIGNAL void thumbnailUrlChanged();
|
||||
|
||||
@@ -45,6 +48,7 @@ public:
|
||||
|
||||
private:
|
||||
QString m_playlistId;
|
||||
bool m_loading = false;
|
||||
|
||||
playlist::Playlist m_playlist {};
|
||||
};
|
||||
@@ -15,12 +15,11 @@ namespace PlaylistUtils {
|
||||
QString artistsToString(const std::vector<meta::Artist> &artists)
|
||||
{
|
||||
if (!artists.empty()) {
|
||||
QString string = QString::fromStdString(artists.front().name);
|
||||
std::for_each(artists.begin() + 1, artists.end(),
|
||||
[&string](const meta::Artist &artist) {
|
||||
string.append(QStringLiteral(", %1").arg(QString::fromStdString(artist.name)));
|
||||
return std::accumulate(artists.begin() + 1, artists.end(),
|
||||
QString::fromStdString(artists.front().name),
|
||||
[](QString &string, const meta::Artist &artist) {
|
||||
return string.append(QStringLiteral(", %1").arg(QString::fromStdString(artist.name)));
|
||||
});
|
||||
return string;
|
||||
}
|
||||
|
||||
return {};
|
||||
|
||||
+6
-2
@@ -1,3 +1,9 @@
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2021 Jonah Brüchert <[email protected]>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
-->
|
||||
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="main.qml">contents/ui/main.qml</file>
|
||||
@@ -6,7 +12,5 @@
|
||||
<file alias="PlayerFooter.qml">contents/ui/PlayerFooter.qml</file>
|
||||
<file alias="SearchPage.qml">contents/ui/SearchPage.qml</file>
|
||||
<file alias="PlaylistPage.qml">contents/ui/PlaylistPage.qml</file>
|
||||
<file alias="ConfirmationMessage.qml">contents/ui/ConfirmationMessage.qml</file>
|
||||
<file alias="LibraryPage.qml">contents/ui/LibraryPage.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
+23
-46
@@ -5,9 +5,9 @@
|
||||
#include "searchmodel.h"
|
||||
|
||||
SearchModel::SearchModel(QObject *parent)
|
||||
: AbstractYTMusicModel(parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
connect(this, &SearchModel::searchQueryChanged, this, [this] {
|
||||
connect(this, &SearchModel::searchQueryChanged, this, [=] {
|
||||
if (m_searchQuery.isEmpty()) {
|
||||
beginResetModel();
|
||||
m_searchResults.clear();
|
||||
@@ -16,15 +16,15 @@ SearchModel::SearchModel(QObject *parent)
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
auto future = YTMusicThread::instance()->search(m_searchQuery);
|
||||
connectFuture(future, this, [=, this](const std::vector<search::SearchResultItem> &results) {
|
||||
beginResetModel();
|
||||
setLoading(false);
|
||||
m_searchResults = results;
|
||||
endResetModel();
|
||||
});
|
||||
YTMusicThread::instance()->search(m_searchQuery);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [this] {
|
||||
connect(&YTMusicThread::instance().get(), &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);
|
||||
});
|
||||
}
|
||||
@@ -105,18 +105,6 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}, m_searchResults.at(index.row())));
|
||||
case RadioPlaylistId:
|
||||
return std::visit([&](auto &&arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
|
||||
if constexpr (std::is_same_v<T, search::Artist>) {
|
||||
if (arg.radio_id) {
|
||||
return QString::fromStdString(*arg.radio_id);
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
}, m_searchResults.at(index.row()));
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
@@ -130,8 +118,7 @@ QHash<int, QByteArray> SearchModel::roleNames() const
|
||||
{Title, "title"},
|
||||
{Type, "type"},
|
||||
{VideoId, "videoId"},
|
||||
{Artists, "artists"},
|
||||
{RadioPlaylistId, "radioPlaylistId"},
|
||||
{Artists, "artists"}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -146,6 +133,17 @@ void SearchModel::setSearchQuery(const QString &searchQuery)
|
||||
Q_EMIT searchQueryChanged();
|
||||
}
|
||||
|
||||
bool SearchModel::loading() const
|
||||
{
|
||||
return m_loading;
|
||||
}
|
||||
|
||||
void SearchModel::setLoading(bool loading)
|
||||
{
|
||||
m_loading = loading;
|
||||
Q_EMIT loadingChanged();
|
||||
}
|
||||
|
||||
void SearchModel::triggerItem(int row)
|
||||
{
|
||||
std::visit([&](auto&& arg) {
|
||||
@@ -159,30 +157,9 @@ void SearchModel::triggerItem(int row)
|
||||
} else if constexpr (std::is_same_v<T, search::Song>) {
|
||||
Q_EMIT openSong(QString::fromStdString(arg.video_id));
|
||||
} else if constexpr (std::is_same_v<T, search::Video>) {
|
||||
Q_EMIT openVideo(QString::fromStdString(arg.video_id), QString::fromStdString(arg.title));
|
||||
Q_EMIT openVideo(QString::fromStdString(arg.video_id));
|
||||
} else {
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}, m_searchResults.at(row));
|
||||
}
|
||||
|
||||
|
||||
int SearchModel::itemType(search::SearchResultItem const &item)
|
||||
{
|
||||
return std::visit([&](auto &&arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr(std::is_same_v<T, search::Album>) {
|
||||
return SearchModel::Type::Album;
|
||||
} else if constexpr(std::is_same_v<T, search::Artist>) {
|
||||
return SearchModel::Type::Artist;
|
||||
} else if constexpr(std::is_same_v<T, search::Playlist>) {
|
||||
return SearchModel::Type::Playlist;
|
||||
} else if constexpr(std::is_same_v<T, search::Song>) {
|
||||
return SearchModel::Type::Song;
|
||||
} else if constexpr(std::is_same_v<T, search::Video>) {
|
||||
return SearchModel::Type::Video;
|
||||
} else {
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
}, item);
|
||||
}
|
||||
+9
-6
@@ -8,13 +8,13 @@
|
||||
#include <QThread>
|
||||
|
||||
#include "asyncytmusic.h"
|
||||
#include "abstractytmusicmodel.h"
|
||||
|
||||
class SearchModel : public AbstractYTMusicModel
|
||||
class SearchModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
|
||||
Q_PROPERTY(bool loading READ loading WRITE setLoading NOTIFY loadingChanged)
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
@@ -30,8 +30,7 @@ public:
|
||||
Title = Qt::UserRole + 1,
|
||||
Type,
|
||||
VideoId,
|
||||
Artists,
|
||||
RadioPlaylistId
|
||||
Artists
|
||||
};
|
||||
|
||||
explicit SearchModel(QObject *parent = nullptr);
|
||||
@@ -44,16 +43,20 @@ public:
|
||||
void setSearchQuery(const QString &searchQuery);
|
||||
Q_SIGNAL void searchQueryChanged();
|
||||
|
||||
bool loading() const;
|
||||
void setLoading(bool loading);
|
||||
Q_SIGNAL void loadingChanged();
|
||||
|
||||
Q_INVOKABLE void triggerItem(int row);
|
||||
|
||||
Q_SIGNAL void openAlbum(const QString &browseId);
|
||||
Q_SIGNAL void openArtist(const QString &browseId);
|
||||
Q_SIGNAL void openPlaylist(const QString &browseId);
|
||||
Q_SIGNAL void openSong(const QString &videoId);
|
||||
Q_SIGNAL void openVideo(const QString &videoId, const QString &title);
|
||||
Q_SIGNAL void openVideo(const QString &videoId);
|
||||
|
||||
private:
|
||||
QString m_searchQuery;
|
||||
std::vector<search::SearchResultItem> m_searchResults;
|
||||
static int itemType(search::SearchResultItem const &item);
|
||||
bool m_loading = false;
|
||||
};
|
||||
+35
-27
@@ -9,14 +9,29 @@
|
||||
#include <random>
|
||||
|
||||
#include <QRandomGenerator>
|
||||
#include <QFutureWatcher>
|
||||
|
||||
#include "playlistutils.h"
|
||||
|
||||
UserPlaylistModel::UserPlaylistModel(QObject *parent)
|
||||
: AbstractYTMusicModel(parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
auto handleResult = [=, this](const watch::Playlist &playlist) {
|
||||
connect(this, &UserPlaylistModel::initialVideoIdChanged, this, [=] {
|
||||
if (m_initialVideoId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
YTMusicThread::instance()->fetchWatchPlaylist(m_initialVideoId);
|
||||
});
|
||||
connect(this, &UserPlaylistModel::playlistIdChanged, this, [=] {
|
||||
if (m_playlistId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
YTMusicThread::instance()->fetchWatchPlaylist(std::nullopt, m_playlistId);
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::fetchWatchPlaylistFinished, this, [=](const watch::Playlist &playlist) {
|
||||
setLoading(false);
|
||||
|
||||
beginResetModel();
|
||||
@@ -33,26 +48,8 @@ UserPlaylistModel::UserPlaylistModel(QObject *parent)
|
||||
} else {
|
||||
setCurrentVideoId({});
|
||||
}
|
||||
};
|
||||
connect(this, &UserPlaylistModel::initialVideoIdChanged, this, [=, this] {
|
||||
if (m_initialVideoId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
auto future = YTMusicThread::instance()->fetchWatchPlaylist(m_initialVideoId);
|
||||
connectFuture(future, this, handleResult);
|
||||
});
|
||||
connect(this, &UserPlaylistModel::playlistIdChanged, this, [=, this] {
|
||||
if (m_playlistId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
auto future = YTMusicThread::instance()->fetchWatchPlaylist(std::nullopt, m_playlistId);
|
||||
connectFuture(future, this, handleResult);;
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [this] {
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [=] {
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
@@ -101,10 +98,21 @@ void UserPlaylistModel::setInitialVideoId(const QString &videoId)
|
||||
Q_EMIT initialVideoIdChanged();
|
||||
}
|
||||
|
||||
bool UserPlaylistModel::loading() const
|
||||
{
|
||||
return m_loading;
|
||||
}
|
||||
|
||||
void UserPlaylistModel::setLoading(bool loading)
|
||||
{
|
||||
m_loading = loading;
|
||||
Q_EMIT loadingChanged();
|
||||
}
|
||||
|
||||
QString UserPlaylistModel::nextVideoId() const
|
||||
{
|
||||
auto currentTrack = std::find_if(m_playlist.tracks.begin(), m_playlist.tracks.end(),
|
||||
[this](const watch::Playlist::Track &track) {
|
||||
[=](const watch::Playlist::Track &track) {
|
||||
return track.video_id == m_currentVideoId.toStdString();
|
||||
});
|
||||
|
||||
@@ -132,7 +140,7 @@ void UserPlaylistModel::setCurrentVideoId(const QString &videoId)
|
||||
bool UserPlaylistModel::canSkip() const
|
||||
{
|
||||
const auto currentTrackIt = std::find_if(m_playlist.tracks.begin(), m_playlist.tracks.end(),
|
||||
[this](const watch::Playlist::Track &track) {
|
||||
[=](const watch::Playlist::Track &track) {
|
||||
return track.video_id == m_currentVideoId.toStdString();
|
||||
});
|
||||
|
||||
@@ -160,7 +168,7 @@ void UserPlaylistModel::skipTo(const QString &videoId)
|
||||
void UserPlaylistModel::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(),
|
||||
[this](const watch::Playlist::Track &track) {
|
||||
[=](const watch::Playlist::Track &track) {
|
||||
return track.video_id == m_currentVideoId.toStdString();
|
||||
});
|
||||
|
||||
@@ -242,7 +250,7 @@ void UserPlaylistModel::shufflePlaylist()
|
||||
// Only shuffle playlist after current track
|
||||
if (!m_currentVideoId.isEmpty()) {
|
||||
const auto currentIt = std::find_if(m_playlist.tracks.begin(), m_playlist.tracks.end(),
|
||||
[this](const watch::Playlist::Track &track) {
|
||||
[=](const watch::Playlist::Track &track) {
|
||||
return track.video_id == m_currentVideoId.toStdString();
|
||||
});
|
||||
|
||||
@@ -260,7 +268,7 @@ void UserPlaylistModel::emitCurrentVideoChanged(const QString &oldVideoId)
|
||||
return track.video_id == oldVideoId.toStdString();
|
||||
});
|
||||
const auto currentVideoIt = std::find_if(m_playlist.tracks.begin(), m_playlist.tracks.end(),
|
||||
[this](const watch::Playlist::Track &track) {
|
||||
[=](const watch::Playlist::Track &track) {
|
||||
return track.video_id == m_currentVideoId.toStdString();
|
||||
});
|
||||
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
#include <ytmusic.h>
|
||||
|
||||
#include "abstractytmusicmodel.h"
|
||||
|
||||
class UserPlaylistModel : public AbstractYTMusicModel
|
||||
class UserPlaylistModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -19,6 +17,7 @@ class UserPlaylistModel : public AbstractYTMusicModel
|
||||
Q_PROPERTY(bool shuffle READ shuffle WRITE setShuffle NOTIFY shuffleChanged)
|
||||
|
||||
// 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)
|
||||
|
||||
@@ -40,6 +39,10 @@ public:
|
||||
void setInitialVideoId(const QString &videoId);
|
||||
Q_SIGNAL void initialVideoIdChanged();
|
||||
|
||||
bool loading() const;
|
||||
void setLoading(bool loading);
|
||||
Q_SIGNAL void loadingChanged();
|
||||
|
||||
QString nextVideoId() const;
|
||||
|
||||
QString currentVideoId() const;
|
||||
@@ -71,6 +74,7 @@ private:
|
||||
QString m_initialVideoId;
|
||||
QString m_playlistId;
|
||||
QString m_currentVideoId;
|
||||
bool m_loading = false;
|
||||
bool m_shuffle = false;
|
||||
|
||||
watch::Playlist m_playlist;
|
||||
|
||||
+23
-25
@@ -4,15 +4,12 @@
|
||||
|
||||
#include "videoinfoextractor.h"
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
#include "asyncytmusic.h"
|
||||
#include "library.h"
|
||||
#include <asyncytmusic.h>
|
||||
|
||||
VideoInfoExtractor::VideoInfoExtractor(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
connect(this, &VideoInfoExtractor::videoIdChanged, this, [this] {
|
||||
connect(this, &VideoInfoExtractor::videoIdChanged, this, [=] {
|
||||
if (m_videoId.isEmpty()) {
|
||||
m_videoInfo = {};
|
||||
Q_EMIT audioUrlChanged();
|
||||
@@ -23,24 +20,24 @@ VideoInfoExtractor::VideoInfoExtractor(QObject *parent)
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
YTMusicThread::instance()->extractVideoInfo(QString::fromStdString(m_videoId.toStdString()));
|
||||
});
|
||||
|
||||
auto future = YTMusicThread::instance()->extractVideoInfo(QString::fromStdString(m_videoId.toStdString()));
|
||||
connectFuture(future, this, [this](const video_info::VideoInfo &videoInfo) {
|
||||
m_videoInfo = videoInfo;
|
||||
setLoading(false);
|
||||
Library::instance().addVideoTitle(m_videoId, QString::fromStdString(m_videoInfo.title));
|
||||
Q_EMIT audioUrlChanged();
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT songChanged();
|
||||
Q_EMIT thumbnailChanged();
|
||||
});
|
||||
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::extractVideoInfoFinished, this, [=](const video_info::VideoInfo &info) {
|
||||
m_videoInfo = info;
|
||||
setLoading(false);
|
||||
Q_EMIT audioUrlChanged();
|
||||
Q_EMIT titleChanged();
|
||||
Q_EMIT songChanged();
|
||||
Q_EMIT thumbnailChanged();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
QUrl VideoInfoExtractor::audioUrl() const
|
||||
{
|
||||
if (m_videoInfo.formats.empty()) {
|
||||
return {};
|
||||
return QUrl();
|
||||
}
|
||||
|
||||
std::vector<video_info::Format> audioFormats;
|
||||
@@ -52,13 +49,17 @@ QUrl VideoInfoExtractor::audioUrl() const
|
||||
});
|
||||
|
||||
if (audioFormats.empty()) {
|
||||
return {};
|
||||
return QUrl();
|
||||
}
|
||||
|
||||
std::sort(audioFormats.begin(), audioFormats.end(),
|
||||
[](const video_info::Format &a, const video_info::Format &b) {
|
||||
return a.quality > b.quality;
|
||||
});
|
||||
|
||||
struct {
|
||||
bool operator()(const video_info::Format &a, const video_info::Format &b) {
|
||||
return a.quality > b.quality;
|
||||
}
|
||||
} qualitySort;
|
||||
|
||||
std::sort(audioFormats.begin(), audioFormats.end(), qualitySort);
|
||||
|
||||
return QUrl(QString::fromStdString(audioFormats.front().url));
|
||||
}
|
||||
@@ -70,9 +71,6 @@ QString VideoInfoExtractor::videoId() const
|
||||
|
||||
void VideoInfoExtractor::setVideoId(const QString &videoId)
|
||||
{
|
||||
if (m_videoId == videoId || videoId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
m_videoId = videoId;
|
||||
Q_EMIT videoIdChanged();
|
||||
}
|
||||
@@ -84,7 +82,7 @@ QString VideoInfoExtractor::title() const
|
||||
|
||||
QString VideoInfoExtractor::thumbnail() const
|
||||
{
|
||||
return QString::fromStdString(m_videoInfo.thumbnail);
|
||||
return QString::fromStdString(m_videoInfo.thumnnail);
|
||||
}
|
||||
|
||||
bool VideoInfoExtractor::loading() const
|
||||
|
||||
+69
-98
@@ -13,54 +13,13 @@ namespace py = pybind11;
|
||||
|
||||
using namespace py::literals;
|
||||
|
||||
/// Useful for debugging
|
||||
void pyPrintPretty(py::handle obj) {
|
||||
auto json = py::module::import("json");
|
||||
py::print(json.attr("dumps")(obj, "indent"_a=py::int_(4)));
|
||||
}
|
||||
|
||||
#define UNEXPORT __attribute__ ((visibility("hidden")))
|
||||
|
||||
constexpr auto TESTED_YTMUSICAPI_VERSION = "0.20.0";
|
||||
constexpr auto TESTED_YTMUSICAPI_VERSION = "0.17.3";
|
||||
|
||||
struct UNEXPORT YTMusicPrivate {
|
||||
py::scoped_interpreter guard {};
|
||||
|
||||
std::optional<std::string> auth;
|
||||
std::optional<std::string> user;
|
||||
std::optional<bool> requests_session;
|
||||
std::optional<std::map<std::string, std::string> > proxies;
|
||||
std::string language;
|
||||
|
||||
py::object get_ytmusic() {
|
||||
if (ytmusic.is_none()) {
|
||||
const auto module = py::module::import("ytmusicapi");
|
||||
ytmusic = module.attr("YTMusic")(auth, user, requests_session, proxies, language);
|
||||
|
||||
// Some of the called python code randomly fails if the encoding is not utf8
|
||||
setenv("LC_ALL", "en_US.utf8", true);
|
||||
|
||||
const auto version = module.attr("_version").attr("__version__").cast<std::string>();
|
||||
if (version != TESTED_YTMUSICAPI_VERSION) {
|
||||
std::cerr << "Running with untested version of ytmusicapi." << std::endl;
|
||||
std::cerr << "The currently tested and supported version is " << TESTED_YTMUSICAPI_VERSION << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return ytmusic;
|
||||
}
|
||||
|
||||
py::object get_ytdl() {
|
||||
// lazy initialization
|
||||
if (ytdl.is_none()) {
|
||||
ytdl = py::module::import("yt_dlp").attr("YoutubeDL")(py::dict());
|
||||
}
|
||||
|
||||
return ytdl;
|
||||
}
|
||||
|
||||
private:
|
||||
py::object ytmusic = py::none();
|
||||
py::object ytmusic;
|
||||
py::object ytdl = py::none();
|
||||
};
|
||||
|
||||
@@ -70,7 +29,7 @@ std::optional<T> optional_key(py::handle obj, const char *name) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return obj[name].cast<std::optional<T>>();
|
||||
return obj[name].cast<T>();
|
||||
}
|
||||
|
||||
meta::Thumbnail extract_thumbnail(py::handle thumbnail) {
|
||||
@@ -88,10 +47,28 @@ meta::Artist extract_meta_artist(py::handle artist) {
|
||||
};
|
||||
};
|
||||
|
||||
album::Track extract_album_track(py::handle track) {
|
||||
return {
|
||||
track["index"].cast<std::string>(),
|
||||
track["title"].cast<std::string>(),
|
||||
track["artists"].cast<std::string>(),
|
||||
track["videoId"].cast<std::optional<std::string>>(), // E rated songs don't have a videoId
|
||||
track["lengthMs"].cast<std::optional<std::string>>(), //
|
||||
track["likeStatus"].cast<std::optional<std::string>>()
|
||||
};
|
||||
}
|
||||
|
||||
video_info::Format extract_format(py::handle format) {
|
||||
return {
|
||||
optional_key<int>(format, "quality"),
|
||||
format["url"].cast<std::string>(),
|
||||
format["vcodec"].cast<std::string>(),
|
||||
format["acodec"].cast<std::string>()
|
||||
};
|
||||
}
|
||||
|
||||
playlist::Track extract_playlist_track(py::handle track);
|
||||
watch::Playlist::Track extract_watch_track(py::handle track);
|
||||
album::Track extract_album_track(py::handle track);
|
||||
video_info::Format extract_format(py::handle format);
|
||||
|
||||
template <typename T>
|
||||
inline auto extract_py_list(py::handle obj) {
|
||||
@@ -123,27 +100,6 @@ inline auto extract_py_list(py::handle obj) {
|
||||
return output;
|
||||
}
|
||||
|
||||
album::Track extract_album_track(py::handle track) {
|
||||
return {
|
||||
track["isExplicit"].cast<bool>(),
|
||||
track["title"].cast<std::string>(),
|
||||
extract_py_list<meta::Artist>(track["artists"]),
|
||||
track["album"].cast<std::optional<std::string>>(),
|
||||
track["videoId"].cast<std::optional<std::string>>(), // E rated songs don't have a videoId
|
||||
track["duration"].cast<std::optional<std::string>>(), //
|
||||
track["likeStatus"].cast<std::optional<std::string>>()
|
||||
};
|
||||
}
|
||||
|
||||
video_info::Format extract_format(py::handle format) {
|
||||
return {
|
||||
optional_key<int>(format, "quality"),
|
||||
format["url"].cast<std::string>(),
|
||||
format["vcodec"].cast<std::string>(),
|
||||
format["acodec"].cast<std::string>()
|
||||
};
|
||||
}
|
||||
|
||||
meta::Album extract_meta_album(py::handle album) {
|
||||
return meta::Album {
|
||||
album["name"].cast<std::string>(),
|
||||
@@ -289,7 +245,7 @@ std::optional<search::SearchResultItem> extract_search_result(py::handle result)
|
||||
result["title"].cast<std::string>(),
|
||||
result["type"].cast<std::string>(),
|
||||
extract_py_list<meta::Artist>(result["artists"]),
|
||||
result["year"].cast<std::optional<std::string>>(),
|
||||
result["year"].cast<std::string>(),
|
||||
result["isExplicit"].cast<bool>()
|
||||
};
|
||||
} else if (resultType == "playlist") {
|
||||
@@ -308,8 +264,7 @@ std::optional<search::SearchResultItem> extract_search_result(py::handle result)
|
||||
};
|
||||
} else {
|
||||
std::cerr << "Warning: Unsupported search result type found" << std::endl;
|
||||
std::cerr << "It's called: " << resultType << std::endl;
|
||||
pyPrintPretty(result);
|
||||
std::cerr << "It's called: " << resultType;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
@@ -322,11 +277,17 @@ YTMusic::YTMusic(
|
||||
const std::string &language)
|
||||
: d(std::make_unique<YTMusicPrivate>())
|
||||
{
|
||||
d->auth = auth;
|
||||
d->user = user;
|
||||
d->requests_session = requests_session;
|
||||
d->proxies = proxies;
|
||||
d->language = language;
|
||||
const auto module = py::module::import("ytmusicapi");
|
||||
d->ytmusic = module.attr("YTMusic")(auth, user, requests_session, proxies, language);
|
||||
|
||||
// Some of the called python code randomly fails if the encoding is not utf8
|
||||
setenv("LC_ALL", "en_US.utf8", true);
|
||||
|
||||
const auto version = module.attr("_version").attr("__version__").cast<std::string>();
|
||||
if (version != TESTED_YTMUSICAPI_VERSION) {
|
||||
std::cerr << "Running with untested version of ytmusicapi." << std::endl;
|
||||
std::cerr << "The currently tested and supported version is " << TESTED_YTMUSICAPI_VERSION << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
YTMusic::~YTMusic() = default;
|
||||
@@ -334,11 +295,10 @@ YTMusic::~YTMusic() = default;
|
||||
std::vector<search::SearchResultItem> YTMusic::search(
|
||||
const std::string &query,
|
||||
const std::optional<std::string> &filter,
|
||||
const std::optional<std::string> &scope,
|
||||
const int limit,
|
||||
const bool ignore_spelling) const
|
||||
{
|
||||
const auto results = d->get_ytmusic().attr("search")("query"_a=query, "filter"_a=filter, "scope"_a=scope, "limit"_a = limit, "ignore_spelling"_a = ignore_spelling).cast<py::list>();
|
||||
const auto results = d->ytmusic.attr("search")(query, filter, limit, ignore_spelling).cast<py::list>();
|
||||
|
||||
std::vector<search::SearchResultItem> output;
|
||||
for (const auto &result : results) {
|
||||
@@ -352,9 +312,9 @@ std::vector<search::SearchResultItem> YTMusic::search(
|
||||
|
||||
artist::Artist YTMusic::get_artist(const std::string &channel_id) const
|
||||
{
|
||||
const auto artist = d->get_ytmusic().attr("get_artist")(channel_id);
|
||||
const auto artist = d->ytmusic.attr("get_artist")(channel_id);
|
||||
return artist::Artist {
|
||||
optional_key<std::string>(artist, "description"),
|
||||
artist["description"].cast<std::optional<std::string>>(),
|
||||
artist["views"].cast<std::optional<std::string>>(),
|
||||
artist["name"].cast<std::string>(),
|
||||
artist["channelId"].cast<std::string>(),
|
||||
@@ -370,29 +330,32 @@ artist::Artist YTMusic::get_artist(const std::string &channel_id) const
|
||||
|
||||
album::Album YTMusic::get_album(const std::string &browseId) const
|
||||
{
|
||||
const auto album = d->get_ytmusic().attr("get_album")(browseId);
|
||||
const auto album = d->ytmusic.attr("get_album")(browseId);
|
||||
|
||||
return {
|
||||
album["title"].cast<std::string>(),
|
||||
album["trackCount"].cast<int>(),
|
||||
album["duration"].cast<std::string>(),
|
||||
album["audioPlaylistId"].cast<std::string>(),
|
||||
album["year"].cast<std::string>(),
|
||||
optional_key<std::string>(album, "description"),
|
||||
album["trackCount"].cast<std::string>(),
|
||||
album["durationMs"].cast<std::string>(),
|
||||
album["playlistId"].cast<std::string>(),
|
||||
[&]() -> album::Album::ReleaseDate {
|
||||
const auto date = album["releaseDate"];
|
||||
return {
|
||||
date["year"].cast<int>(),
|
||||
date["month"].cast<int>(),
|
||||
date["day"].cast<int>()
|
||||
};
|
||||
}(),
|
||||
album["description"].cast<std::string>(),
|
||||
extract_py_list<meta::Thumbnail>(album["thumbnails"]),
|
||||
extract_py_list<album::Track>(album["tracks"]),
|
||||
extract_py_list<meta::Artist>(album["artists"])
|
||||
extract_py_list<album::Track>(album["tracks"])
|
||||
};
|
||||
}
|
||||
|
||||
std::optional<song::Song> YTMusic::get_song(const std::string &video_id) const
|
||||
song::Song YTMusic::get_song(const std::string &video_id) const
|
||||
{
|
||||
const auto song = d->get_ytmusic().attr("get_song")(video_id);
|
||||
const auto song = d->ytmusic.attr("get_song")(video_id);
|
||||
|
||||
if (!song.cast<py::dict>().contains("videoId")) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return song::Song {
|
||||
return {
|
||||
song["videoId"].cast<std::string>(),
|
||||
song["title"].cast<std::string>(),
|
||||
song["lengthSeconds"].cast<std::string>(),
|
||||
@@ -422,7 +385,7 @@ std::optional<song::Song> YTMusic::get_song(const std::string &video_id) const
|
||||
|
||||
playlist::Playlist YTMusic::get_playlist(const std::string &playlist_id, int limit) const
|
||||
{
|
||||
const auto playlist = d->get_ytmusic().attr("get_playlist")(playlist_id, limit);
|
||||
const auto playlist = d->ytmusic.attr("get_playlist")(playlist_id, limit);
|
||||
|
||||
return {
|
||||
playlist["id"].cast<std::string>(),
|
||||
@@ -439,7 +402,7 @@ playlist::Playlist YTMusic::get_playlist(const std::string &playlist_id, int lim
|
||||
|
||||
std::vector<artist::Artist::Album> YTMusic::get_artist_albums(const std::string &channel_id, const std::string ¶ms) const
|
||||
{
|
||||
const auto py_albums = d->get_ytmusic().attr("get_artist_albums")(channel_id, params);
|
||||
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) {
|
||||
@@ -459,7 +422,15 @@ video_info::VideoInfo YTMusic::extract_video_info(const std::string &video_id) c
|
||||
{
|
||||
using namespace pybind11::literals;
|
||||
|
||||
const auto info = d->get_ytdl().attr("extract_info")(video_id, "download"_a=py::bool_(false));
|
||||
// lazy initialization
|
||||
if (d->ytdl.is_none()) {
|
||||
const auto module = py::module::import("youtube_dl");
|
||||
py::dict options;
|
||||
d->ytdl = module.attr("YoutubeDL")(options);
|
||||
}
|
||||
|
||||
const auto info = d->ytdl.attr("extract_info")(video_id, "download"_a=py::bool_(false));
|
||||
//py::print(py::module::import("json").attr("dumps")(info, "indent"_a=4));
|
||||
|
||||
return {
|
||||
info["id"].cast<std::string>(),
|
||||
@@ -474,7 +445,7 @@ watch::Playlist YTMusic::get_watch_playlist(const std::optional<std::string> &vi
|
||||
int limit,
|
||||
const std::optional<std::string> ¶ms) const
|
||||
{
|
||||
const auto playlist = d->get_ytmusic().attr("get_watch_playlist")("videoId"_a = videoId,
|
||||
const auto playlist = d->ytmusic.attr("get_watch_playlist")("videoId"_a = videoId,
|
||||
"playlistId"_a = playlistId,
|
||||
"limit"_a = py::int_(limit),
|
||||
"params"_a = params);
|
||||
|
||||
+12
-15
@@ -67,7 +67,7 @@ struct Album {
|
||||
std::string title;
|
||||
std::string type;
|
||||
std::vector<meta::Artist> artists;
|
||||
std::optional<std::string> year;
|
||||
std::string year;
|
||||
bool is_explicit;
|
||||
};
|
||||
|
||||
@@ -122,7 +122,7 @@ struct Artist {
|
||||
|
||||
struct Single {
|
||||
std::string title;
|
||||
std::vector<meta::Thumbnail> thumbnails;
|
||||
std::vector<meta::Thumbnail> thumnnails;
|
||||
std::string year;
|
||||
std::string browse_id;
|
||||
};
|
||||
@@ -143,12 +143,11 @@ struct Artist {
|
||||
|
||||
namespace album {
|
||||
struct Track {
|
||||
bool is_explicit;
|
||||
std::string index;
|
||||
std::string title;
|
||||
std::vector<meta::Artist> artists;
|
||||
std::optional<std::string> album;
|
||||
std::string artists;
|
||||
std::optional<std::string> video_id;
|
||||
std::optional<std::string> duration;
|
||||
std::optional<std::string> length_ms;
|
||||
std::optional<std::string> like_status;
|
||||
};
|
||||
|
||||
@@ -160,14 +159,13 @@ namespace album {
|
||||
};
|
||||
|
||||
std::string title;
|
||||
int track_count;
|
||||
std::string duration;
|
||||
std::string audio_playlist_id;
|
||||
std::string year;
|
||||
std::optional<std::string> description;
|
||||
std::string track_count;
|
||||
std::string duration_ms;
|
||||
std::string playlist_id;
|
||||
ReleaseDate release_date;
|
||||
std::string description;
|
||||
std::vector<meta::Thumbnail> thumbnails;
|
||||
std::vector<Track> tracks;
|
||||
std::vector<meta::Artist> artists;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -242,7 +240,7 @@ struct VideoInfo {
|
||||
std::string id;
|
||||
std::string title;
|
||||
std::vector<Format> formats;
|
||||
std::string thumbnail;
|
||||
std::string thumnnail;
|
||||
|
||||
// More, but not interesting for us right now
|
||||
};
|
||||
@@ -279,7 +277,6 @@ public:
|
||||
|
||||
std::vector<search::SearchResultItem> search(const std::string &query,
|
||||
const std::optional<std::string> &filter = std::nullopt,
|
||||
const std::optional<std::string> &scope = std::nullopt,
|
||||
const int limit = 20,
|
||||
const bool ignore_spelling = false) const;
|
||||
|
||||
@@ -290,7 +287,7 @@ public:
|
||||
album::Album get_album(const std::string &browse_id) const;
|
||||
|
||||
/// https://ytmusicapi.readthedocs.io/en/latest/reference.html#ytmusicapi.YTMusic.get_song
|
||||
std::optional<song::Song> get_song(const std::string &video_id) const;
|
||||
song::Song get_song(const std::string &video_id) const;
|
||||
|
||||
/// https://ytmusicapi.readthedocs.io/en/latest/reference.html#ytmusicapi.YTMusic.get_playlist
|
||||
playlist::Playlist get_playlist(const std::string &playlist_id, int limit = 100) const;
|
||||
|
||||
Reference in new issue
Block a user