File indexing completed on 2025-02-23 04:29:35
0001 // SPDX-FileCopyrightText: 2021 Jonah BrĂ¼chert <jbb@kaidan.im> 0002 // 0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 0005 #include <ytmusic.h> 0006 0007 #include <iostream> 0008 0009 int main() { 0010 const auto ytm = YTMusic(); 0011 const auto results = ytm.search("Systemabsturz"); 0012 0013 std::cout << "Found " << results.size() << " results." << std::endl; 0014 0015 for (const auto &result : results) { 0016 std::visit([&](auto&& arg) { 0017 using T = std::decay_t<decltype(arg)>; 0018 if constexpr (std::is_same_v<T, search::Album>) { 0019 std::cout << arg.title << std::endl; 0020 if (arg.browse_id) { 0021 const album::Album album = ytm.get_album(*arg.browse_id); 0022 for (const auto &track : album.tracks) { 0023 if (track.video_id.has_value()) { 0024 ytm.extract_video_info(*track.video_id); 0025 } 0026 } 0027 } 0028 } else if constexpr (std::is_same_v<T, search::Artist>) { 0029 std::cout << arg.artist << std::endl; 0030 const artist::Artist artist = ytm.get_artist(arg.browse_id); 0031 if (artist.albums->params) { 0032 const auto albums = ytm.get_artist_albums(artist.channel_id, *artist.albums->params); 0033 } else { 0034 std::cerr << " ! Album params not available" << std::endl; 0035 } 0036 } else if constexpr (std::is_same_v<T, search::Playlist>) { 0037 std::cout << arg.title << std::endl; 0038 ytm.get_playlist(arg.browse_id); 0039 } else if constexpr (std::is_same_v<T, search::Song>) { 0040 if (!ytm.get_song(arg.video_id)) { 0041 std::cout << "Song info was empty" << std::endl; 0042 } 0043 ytm.extract_video_info(arg.video_id); 0044 ytm.get_watch_playlist(arg.video_id); 0045 std::cout << arg.title << std::endl; 0046 } else if constexpr (std::is_same_v<T, search::Video>) { 0047 std::cout << arg.title << std::endl; 0048 } else if constexpr (std::is_same_v<T, search::TopResult>) { 0049 if (arg.title) { 0050 std::cout << *arg.title << std::endl; 0051 } 0052 if (arg.video_id) { 0053 ytm.extract_video_info(*arg.video_id); 0054 auto playlist = ytm.get_watch_playlist(*arg.video_id); 0055 if (playlist.lyrics) { 0056 ytm.get_lyrics(*playlist.lyrics); 0057 } 0058 } else if (!arg.artists.empty()) { 0059 for (const meta::Artist &artist : arg.artists) { 0060 if (artist.id) { 0061 ytm.get_artist(*artist.id); 0062 } 0063 } 0064 } 0065 } else { 0066 std::cout << "non exaustive visitor" << std::endl; 0067 } 0068 }, result); 0069 } 0070 0071 std::flush(std::cout); 0072 }