Skip to content

Commit

Permalink
Shared - Handle Audio Description Languages Separately (#810)
Browse files Browse the repository at this point in the history
* Shared - Handle Audio Description Languages Separately

* Shared - Cleanup
  • Loading branch information
nlogozzo authored Sep 4, 2024
1 parent dca9000 commit f0d07fd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
11 changes: 0 additions & 11 deletions libparabolic/include/models/media.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ namespace Nickvision::TubeConverter::Shared::Models
* @param resolution The video resolution to add
*/
void addVideoResolution(const VideoResolution& resolution);
/**
* @brief Gets the playlist position of the media.
* @return The playlist position of the media
*/
const std::optional<unsigned int>& getPlaylistPosition() const;
/**
* @brief Sets the playlist position of the media.
* @param position The playlist position to set
*/
void setPlaylistPosition(const std::optional<unsigned int>& position);
/**
* @brief Gets whether the media has subtitles.
* @return True if has subtitles, else false
Expand All @@ -108,7 +98,6 @@ namespace Nickvision::TubeConverter::Shared::Models
MediaType m_type;
std::vector<std::string> m_audioLanguages;
std::vector<VideoResolution> m_videoResolutions;
std::optional<unsigned int> m_playlistPosition;
bool m_hasSubtitles;
};
}
Expand Down
2 changes: 1 addition & 1 deletion libparabolic/src/controllers/mainwindowcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Nickvision::TubeConverter::Shared::Controllers
m_appInfo.setVersion({ "2024.9.0-beta1" });
m_appInfo.setShortName(_("Parabolic"));
m_appInfo.setDescription(_("Download web video and audio"));
m_appInfo.setChangelog("- Parabolic has been rewritten in C++ for faster performance\n- The length of the kept download history can now be changed in the app's preferences\n- Cookies can now be fetched from a selected browser in Preferences instead of selecting a TXT cookies file\n- Parabolic's Keyring module was rewritten. As a result, all keyrings have been reset and will need to be reconfigured\n- Fixed validation issues with various sites\n- Fixed an issue where a specified video password was not being used\n- Redesigned user interface\n- Updated yt-dlp");
m_appInfo.setChangelog("- Parabolic has been rewritten in C++ for faster performance\n- The length of the kept download history can now be changed in the app's preferences\n- Cookies can now be fetched from a selected browser in Preferences instead of selecting a TXT cookies file\n- Parabolic's Keyring module was rewritten. As a result, all keyrings have been reset and will need to be reconfigured\n- Parabolic will now correctly recognize audio languages with audio description and handle them separately from audio languages without audio description\n- Fixed validation issues with various sites\n- Fixed an issue where a specified video password was not being used\n- Redesigned user interface\n- Updated yt-dlp");
m_appInfo.setSourceRepo("https://github.com/NickvisionApps/Parabolic");
m_appInfo.setIssueTracker("https://github.com/NickvisionApps/Parabolic/issues/new");
m_appInfo.setSupportUrl("https://github.com/NickvisionApps/Parabolic/discussions");
Expand Down
29 changes: 25 additions & 4 deletions libparabolic/src/models/downloadoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ namespace Nickvision::TubeConverter::Shared::Models
if(downloaderOptions.getRemoveSourceData())
{
arguments.push_back("--parse-metadata");
arguments.push_back(":(?P<meta_comment>):(?P<meta_description>):(?P<meta_synopsis>):(?P<meta_purl>):(?P<meta_track>)");
arguments.push_back(":(?P<meta_comment>):(?P<meta_description>):(?P<meta_synopsis>):(?P<meta_purl>)");
}
}
if(downloaderOptions.getEmbedChapters())
Expand Down Expand Up @@ -319,7 +319,16 @@ namespace Nickvision::TubeConverter::Shared::Models
if(!m_audioLanguage.empty())
{
arguments.push_back("--format");
arguments.push_back("ba[language=" + m_audioLanguage + "]/b");
size_t find{ m_audioLanguage.find(" (audio_description)") };
if(find == std::string::npos)
{
arguments.push_back("(ba[language=" + m_audioLanguage + "]/b)[format_id!*=?audiodesc]");
}
else
{
std::string language{ m_audioLanguage.substr(0, find) };
arguments.push_back("(ba[language=" + language + "]/b)[format_id*=?audiodesc]");
}
}
}
else if(m_fileType.isVideo())
Expand All @@ -333,24 +342,36 @@ namespace Nickvision::TubeConverter::Shared::Models
arguments.push_back("--format");
if(!resolution.isBest())
{
size_t find{ m_audioLanguage.find(" (audio_description)") };
if(m_audioLanguage.empty())
{
arguments.push_back("bv[height<=" + std::to_string(resolution.getHeight()) + "][width<=" + std::to_string(resolution.getWidth()) + "]+ba/b");
}
else if(find == std::string::npos)
{
arguments.push_back("(bv[height<=" + std::to_string(resolution.getHeight()) + "][width<=" + std::to_string(resolution.getWidth()) + "]+ba[language= " + m_audioLanguage + "]/b)[format_id!*=?audiodesc]");
}
else
{
arguments.push_back("bv[height<=" + std::to_string(resolution.getHeight()) + "][width<=" + std::to_string(resolution.getWidth()) + "]+ba[language= " + m_audioLanguage + "]/b");
std::string language{ m_audioLanguage.substr(0, find) };
arguments.push_back("(bv[height<=" + std::to_string(resolution.getHeight()) + "][width<=" + std::to_string(resolution.getWidth()) + "]+ba[language= " + language + "]/b)[format_id*=?audiodesc]");
}
}
else
{
size_t find{ m_audioLanguage.find(" (audio_description)") };
if(m_audioLanguage.empty())
{
arguments.push_back("bv+ba/b");
}
else if(find == std::string::npos)
{
arguments.push_back("(bv+ba[language= " + m_audioLanguage + "]/b)[format_id!*=?audiodesc]");
}
else
{
arguments.push_back("bv+ba[language= " + m_audioLanguage + "]/b");
std::string language{ m_audioLanguage.substr(0, find) };
arguments.push_back("(bv+ba[language= " + language + "]/b)[format_id*=?audiodesc]");
}
}

Expand Down
18 changes: 5 additions & 13 deletions libparabolic/src/models/media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ namespace Nickvision::TubeConverter::Shared::Models
m_title{ title },
m_timeFrame{ std::chrono::seconds(0), duration },
m_type{ type },
m_playlistPosition{ std::nullopt },
m_hasSubtitles{ false }
{

}

Media::Media(boost::json::object info)
: m_timeFrame{ std::chrono::seconds(0), std::chrono::seconds(0) },
m_playlistPosition{ std::nullopt },
m_hasSubtitles{ false }
{
if(info.empty())
Expand Down Expand Up @@ -82,6 +80,11 @@ namespace Nickvision::TubeConverter::Shared::Models
std::string language{ obj["language"].is_string() ? obj["language"].as_string() : "" };
if(!language.empty() && language != "none")
{
std::string format_id{ obj["format_id"].is_string() ? obj["format_id"].as_string() : "" };
if(!format_id.empty() && format_id.find("audiodesc") != std::string::npos)
{
language += " (audio_description)";
}
if(std::find(m_audioLanguages.begin(), m_audioLanguages.end(), language) == m_audioLanguages.end())
{
m_audioLanguages.push_back(language);
Expand Down Expand Up @@ -167,16 +170,6 @@ namespace Nickvision::TubeConverter::Shared::Models
m_videoResolutions.push_back(resolution);
}

const std::optional<unsigned int>& Media::getPlaylistPosition() const
{
return m_playlistPosition;
}

void Media::setPlaylistPosition(const std::optional<unsigned int>& position)
{
m_playlistPosition = position;
}

bool Media::hasSubtitles() const
{
return m_hasSubtitles;
Expand Down Expand Up @@ -206,7 +199,6 @@ namespace Nickvision::TubeConverter::Shared::Models
os << resolution << ", ";
}
os << std::endl;
os << "Playlist Position: " << media.m_playlistPosition.value_or(0) << std::endl;
os << "Has Subtitles: " << (media.m_hasSubtitles ? "Yes" : "No");
return os;
}
Expand Down
2 changes: 0 additions & 2 deletions libparabolic/src/models/urlinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Nickvision::TubeConverter::Shared::Models
if(!entries.empty())
{
m_isPlaylist = true;
int i{ 1 };
for(const boost::json::value& entry : entries)
{
if(!entry.is_object())
Expand All @@ -25,7 +24,6 @@ namespace Nickvision::TubeConverter::Shared::Models
boost::json::object obj = entry.as_object();
obj["limit_characters"] = info["limit_characters"];
m_media.push_back({ obj });
i++;
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<p>- The length of the kept download history can now be changed in the app's preferences</p>
<p>- Cookies can now be fetched from a selected browser in Preferences instead of selecting a TXT cookies file</p>
<p>- Parabolic's Keyring module was rewritten. As a result, all keyrings have been reset and will need to be reconfigured</p>
<p>- Parabolic will now correctly recognize audio languages with audio description and handle them separately from audio languages without audio description</p>
<p>- Fixed validation issues with various sites</p>
<p>- Fixed an issue where a specified video password was not being used</p>
<p>- Redesigned user interface</p>
Expand Down

0 comments on commit f0d07fd

Please sign in to comment.