Getting "get_video_info?video_id" when trying to get title of YouTube video
Posted: 04 Oct 2021 12:38
Hello, thanks for stopping by.
The "get_title()" function in my program is responsible for getting video title. It is used in a loop to return titles of 5 previous tracks, currently played track and 5 tracks after it. Loop is run each time a new track starts to play. The code bellow is written for testing purposes so you could easily check the problem on your PC if you desire so.
The problem occurs slightly less frequently when build type is set to "Release" (add -DCMAKE_BUILD_TYPE=Release when preconfiguring with CMake). On my PC in "Debug" mode code above always show get_video_info?video_id in place of second song's title.
The "get_title()" function in my program is responsible for getting video title. It is used in a loop to return titles of 5 previous tracks, currently played track and 5 tracks after it. Loop is run each time a new track starts to play. The code bellow is written for testing purposes so you could easily check the problem on your PC if you desire so.
Code: Select all
// main.cpp
std::string get_title(
std::string song_mrl
)
{
const char *const arg[] = {"--preferred-resolution=720", "--no-video"};
std::shared_ptr<VLC::Instance> dummy = std::make_shared<VLC::Instance>(VLC::Instance(2, arg));
VLC::Media media = VLC::Media(*dummy, song_mrl, VLC::Media::FromLocation);
media.parseWithOptions(VLC::Media::ParseFlags::Network, -1);
while (media.parsedStatus() != VLC::Media::ParsedStatus::Done) { }
return media.subitems()->itemAtIndex(0)->meta(libvlc_meta_Title);
}
int main()
{
const std::array<const std::string, 3> mrls = {
"https://youtu.be/QzqZ1RY1seQ",
"https://youtu.be/sO8d1CIFV8w",
"https://youtu.be/rtL5oMyBHPs"
};
for (int i = 0; i < 30; i++)
{
std::cout << get_title(mrls[0]) << std::endl;
std::cout << get_title(mrls[1]) << std::endl;
std::cout << get_title(mrls[2]) << std::endl;
std::cout << std::endl;
}
return 0;
}
Code: Select all
# CMakeLIsts.txt
cmake_minimum_required(VERSION 3.18) # probably can be set to lower version, didn't check
project(
vlc_title_test
LANGUAGES CXX C
)
set(LIBVLC_HEADERS /usr/include/vlc )
set(LIBVLC_STATIC /usr/lib64 )
add_library(libvlc SHARED IMPORTED GLOBAL)
set_target_properties(libvlc PROPERTIES
IMPORTED_LOCATION ${LIBVLC_STATIC}/libvlc.so
INTERFACE_INCLUDE_DIRECTORIES ${LIBVLC_HEADERS}
LINKER_LANGUAGE C
)
add_executable(vlc_title_test main.cpp)
set_target_properties(vlc_title_test PROPERTIES
LINKER_LANGUAGE CXX
)
target_link_libraries(vlc_title_test PRIVATE libvlc)