Skip to content

Commit

Permalink
V2022.10.3-beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Oct 17, 2022
1 parent a0315e7 commit 81b3d16
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 17 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('org.nickvision.tubeconverter', ['cpp', 'c'], version: '2022.10.2', meson_version: '>= 0.59.0', default_options: ['warning_level=3', 'werror=false', 'cpp_std=c++20'])
project('org.nickvision.tubeconverter', ['cpp', 'c'], version: '2022.10.3', meson_version: '>= 0.59.0', default_options: ['warning_level=3', 'werror=false', 'cpp_std=c++20'])

gnome = import('gnome')

Expand Down
2 changes: 1 addition & 1 deletion org.nickvision.tubeconverter.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"type": "git",
"url": "https://github.com/nlogozzo/NickvisionTubeConverter.git",
"tag": "2022.10.2"
"tag": "2022.10.3-beta1"
}
]
}
Expand Down
7 changes: 2 additions & 5 deletions org.nickvision.tubeconverter.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@
<binary>org.nickvision.tubeconverter</binary>
</provides>
<releases>
<release version="2022.10.2" date="2022-10-15">
<release version="2022.10.3-beta1" date="2022-10-16">
<description>
<p>- New application icon (Thanks @martin-desktops!)</p>
<p>- Implemented proper stop function for download</p>
<p>- 'New Filename' is now allowed to be empty. If it is empty, the video title will be used</p>
<p>- Improved video url checking</p>
<p>- Added a preference to embed metadata in a download</p>
</description>
</release>
</releases>
Expand Down
5 changes: 5 additions & 0 deletions src/controllers/mainwindowcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ void MainWindowController::startup()
}
}

bool MainWindowController::getEmbedMetadata() const
{
return m_configuration.getEmbedMetadata();
}

bool MainWindowController::getIsDownloadsRunning() const
{
for(const std::shared_ptr<Download>& download : m_downloads)
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/mainwindowcontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ namespace NickvisionTubeConverter::Controllers
* Runs startup functions
*/
void startup();
/**
* Gets whether or not to embed metadata in a download
*
* @returns True to embed, else false
*/
bool getEmbedMetadata() const;
/**
* Gets whether or not downloads are running
*
Expand Down
10 changes: 10 additions & 0 deletions src/controllers/preferencesdialogcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ void PreferencesDialogController::setTheme(int theme)
m_configuration.setTheme(static_cast<Theme>(theme));
}

bool PreferencesDialogController::getEmbedMetadata() const
{
return m_configuration.getEmbedMetadata();
}

void PreferencesDialogController::setEmbedMetadata(bool embedMetadata)
{
m_configuration.setEmbedMetadata(embedMetadata);
}

void PreferencesDialogController::saveConfiguration() const
{
m_configuration.save();
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/preferencesdialogcontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ namespace NickvisionTubeConverter::Controllers
* @param theme The new theme as an int
*/
void setTheme(int theme);
/**
* Gets whether or not to embed metadata in a download
*
* @returns True to embed, else false
*/
bool getEmbedMetadata() const;
/**
* Sets whether or not to embed metadata in a download
*
* @param embedMetadata True to embed, else false
*/
void setEmbedMetadata(bool embedMetadata);
/**
* Saves the configuration file
*/
Expand Down
14 changes: 13 additions & 1 deletion src/models/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using namespace NickvisionTubeConverter::Models;

Configuration::Configuration() : m_configDir{ std::string(g_get_user_config_dir()) + "/Nickvision/NickvisionTubeConverter/" }, m_theme{ Theme::System }, m_previousSaveFolder { "" }, m_previousFileType{ MediaFileType::MP4 }
Configuration::Configuration() : m_configDir{ std::string(g_get_user_config_dir()) + "/Nickvision/NickvisionTubeConverter/" }, m_theme{ Theme::System }, m_previousSaveFolder { "" }, m_previousFileType{ MediaFileType::MP4 }, m_embedMetadata{ true }
{
if(!std::filesystem::exists(m_configDir))
{
Expand All @@ -20,6 +20,7 @@ Configuration::Configuration() : m_configDir{ std::string(g_get_user_config_dir(
m_theme = static_cast<Theme>(json.get("Theme", 0).asInt());
m_previousSaveFolder = json.get("PreviousSaveFolder", "").asString();
m_previousFileType = static_cast<MediaFileType::Value>(json.get("PreviousFileType", 0).asInt());
m_embedMetadata = json.get("EmbedMetadata", true).asBool();
}
}

Expand Down Expand Up @@ -53,6 +54,16 @@ void Configuration::setPreviousFileType(const MediaFileType& previousFileType)
m_previousFileType = previousFileType;
}

bool Configuration::getEmbedMetadata() const
{
return m_embedMetadata;
}

void Configuration::setEmbedMetadata(bool embedMetadata)
{
m_embedMetadata = embedMetadata;
}

void Configuration::save() const
{
std::ofstream configFile{ m_configDir + "config.json" };
Expand All @@ -62,6 +73,7 @@ void Configuration::save() const
json["Theme"] = static_cast<int>(m_theme);
json["PreviousSaveFolder"] = m_previousSaveFolder;
json["PreviousFileType"] = static_cast<int>(m_previousFileType);
json["EmbedMetadata"] = m_embedMetadata;
configFile << json;
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/models/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ namespace NickvisionTubeConverter::Models
* @param previousFileType The new previous file type
*/
void setPreviousFileType(const MediaFileType& previousFileType);
/**
* Gets whether or not to embed metadata in a download
*
* @returns True to embed, else false
*/
bool getEmbedMetadata() const;
/**
* Sets whether or not to embed metadata in a download
*
* @param embedMetadata True to embed, else false
*/
void setEmbedMetadata(bool embedMetadata);
/**
* Saves the configuration to disk
*/
Expand All @@ -71,5 +83,6 @@ namespace NickvisionTubeConverter::Models
Theme m_theme;
std::string m_previousSaveFolder;
MediaFileType m_previousFileType;
bool m_embedMetadata;
};
}
6 changes: 5 additions & 1 deletion src/models/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ bool Download::getIsDone()
return m_isDone;
}

bool Download::download()
bool Download::download(bool embedMetadata)
{
std::string cmd{ "" };
if (getMediaFileType().isVideo())
Expand All @@ -154,6 +154,10 @@ bool Download::download()
{
cmd = "yt-dlp --extract-audio --audio-format " + getMediaFileType().toString() + " --audio-quality " + (getQuality() == Quality::Best ? "0" : getQuality() == Quality::Good ? "5" : "10") + " \"" + getVideoUrl() + "\" -o \"" + getSavePathWithoutExtension() + ".%(ext)s\"";
}
if(embedMetadata)
{
cmd += " --add-metadata --embed-thumbnail";
}
setLog("URL: " + getVideoUrl() + "\nPath: " + getSavePath() + "\nQuality: " + std::to_string(static_cast<int>(getQuality())) + "\n\n");
std::array<char, 128> buffer;
FILE* fp{ popen2(cmd, "r", m_pid) };
Expand Down
3 changes: 2 additions & 1 deletion src/models/download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ namespace NickvisionTubeConverter::Models
/**
* Downloads the video
*
* @param embedMetadata Whether or not to embed metadata into the download file
* @returns True if successful, else false
*/
bool download();
bool download(bool embedMetadata);
/**
* Stops the download
*/
Expand Down
4 changes: 2 additions & 2 deletions src/ui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Application::Application(const std::string& id, GApplicationFlags flags) : m_adw
m_appInfo.setName("Nickvision Tube Converter");
m_appInfo.setShortName("Tube Converter");
m_appInfo.setDescription("An easy-to-use YouTube video downloader.");
m_appInfo.setVersion("2022.10.2");
m_appInfo.setChangelog("<ul><li>New application icon (Thanks @martin-desktops!)</li><li>Implemented proper stop function for download</li><li>'New Filename' is now allowed to be empty. If it is empty, the video title will be used</li><li>Improved video url checking</li></ul>");
m_appInfo.setVersion("2022.10.3-beta1");
m_appInfo.setChangelog("<ul><li>Added a preference to embed metadata in a download</li></ul>");
m_appInfo.setGitHubRepo("https://github.com/nlogozzo/NickvisionTubeConverter");
m_appInfo.setIssueTracker("https://github.com/nlogozzo/NickvisionTubeConverter/issues/new");
m_appInfo.setSupportUrl("https://github.com/nlogozzo/NickvisionTubeConverter/discussions");
Expand Down
4 changes: 2 additions & 2 deletions src/ui/controls/downloadrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ GtkWidget* DownloadRow::gobj()
return m_gobj;
}

void DownloadRow::start()
void DownloadRow::start(bool embedMetadata)
{
std::future<bool> result{ std::async(std::launch::async, [&]() -> bool { return m_download->download(); }) };
std::future<bool> result{ std::async(std::launch::async, [&, embedMetadata]() -> bool { return m_download->download(embedMetadata); }) };
std::future_status status{ std::future_status::timeout };
gtk_style_context_add_class(gtk_widget_get_style_context(m_imgStatus), "accent");
while(status != std::future_status::ready)
Expand Down
4 changes: 3 additions & 1 deletion src/ui/controls/downloadrow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ namespace NickvisionTubeConverter::UI::Controls
GtkWidget* gobj();
/**
* Starts the Download managed by the row
*
* @param embedMetadata Whether or not to embed metadata in a download
*/
void start();
void start(bool embedMetadata);

private:
std::shared_ptr<NickvisionTubeConverter::Models::Download> m_download;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using namespace NickvisionTubeConverter::UI::Views;
MainWindow::MainWindow(GtkApplication* application, const MainWindowController& controller) : m_controller{ controller }, m_gobj{ adw_application_window_new(application) }
{
//Window Settings
gtk_window_set_default_size(GTK_WINDOW(m_gobj), 800, 600);
gtk_window_set_default_size(GTK_WINDOW(m_gobj), 900, 700);
if(m_controller.getIsDevVersion())
{
gtk_style_context_add_class(gtk_widget_get_style_context(m_gobj), "devel");
Expand Down Expand Up @@ -136,7 +136,7 @@ void MainWindow::onAddDownload()
std::unique_ptr<DownloadRow> row{ std::make_unique<DownloadRow>(GTK_WINDOW(m_gobj), download) };
m_controller.addDownload(download);
adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_grpDownloads), row->gobj());
row->start();
row->start(m_controller.getEmbedMetadata());
m_downloadRows.push_back(std::move(row));
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/ui/views/preferencesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,31 @@ PreferencesDialog::PreferencesDialog(GtkWindow* parent, const PreferencesDialogC
adw_action_row_set_subtitle(ADW_ACTION_ROW(m_rowTheme), "A theme change will be applied once the dialog is closed.");
adw_combo_row_set_model(ADW_COMBO_ROW(m_rowTheme), G_LIST_MODEL(gtk_string_list_new(new const char*[4]{ "System", "Light", "Dark", nullptr })));
adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_grpUserInterface), m_rowTheme);
//Converter Group
m_grpConverter = adw_preferences_group_new();
adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpConverter), "Converter");
adw_preferences_group_set_description(ADW_PREFERENCES_GROUP(m_grpConverter), "Customize converter settings.");
//Embed Metadata Row
m_rowEmbedMetadata = adw_action_row_new();
m_switchEmbedMetadata = gtk_switch_new();
gtk_widget_set_valign(m_switchEmbedMetadata, GTK_ALIGN_CENTER);
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowEmbedMetadata), "Embed Metadata");
adw_action_row_set_subtitle(ADW_ACTION_ROW(m_rowEmbedMetadata), "If checked, video metadata will be included in the downloaded file.");
adw_action_row_add_suffix(ADW_ACTION_ROW(m_rowEmbedMetadata), m_switchEmbedMetadata);
adw_action_row_set_activatable_widget(ADW_ACTION_ROW(m_rowEmbedMetadata), m_switchEmbedMetadata);
adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_grpConverter), m_rowEmbedMetadata);
//Page
m_page = adw_preferences_page_new();
adw_preferences_page_add(ADW_PREFERENCES_PAGE(m_page), ADW_PREFERENCES_GROUP(m_grpUserInterface));
adw_preferences_page_add(ADW_PREFERENCES_PAGE(m_page), ADW_PREFERENCES_GROUP(m_grpConverter));
//Main Box
m_mainBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_append(GTK_BOX(m_mainBox), m_headerBar);
gtk_box_append(GTK_BOX(m_mainBox), m_page);
adw_window_set_content(ADW_WINDOW(m_gobj), m_mainBox);
//Load Configuration
adw_combo_row_set_selected(ADW_COMBO_ROW(m_rowTheme), m_controller.getThemeAsInt());
gtk_switch_set_active(GTK_SWITCH(m_switchEmbedMetadata), m_controller.getEmbedMetadata());
}

GtkWidget* PreferencesDialog::gobj()
Expand All @@ -49,6 +64,7 @@ void PreferencesDialog::run()
g_main_context_iteration(g_main_context_default(), false);
}
m_controller.setTheme(adw_combo_row_get_selected(ADW_COMBO_ROW(m_rowTheme)));
m_controller.setEmbedMetadata(gtk_switch_get_active(GTK_SWITCH(m_switchEmbedMetadata)));
m_controller.saveConfiguration();
if(m_controller.getThemeAsInt() == 0)
{
Expand Down
3 changes: 3 additions & 0 deletions src/ui/views/preferencesdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ namespace NickvisionTubeConverter::UI::Views
GtkWidget* m_page{ nullptr };
GtkWidget* m_grpUserInterface{ nullptr };
GtkWidget* m_rowTheme{ nullptr };
GtkWidget* m_grpConverter{ nullptr };
GtkWidget* m_rowEmbedMetadata{ nullptr };
GtkWidget* m_switchEmbedMetadata{ nullptr };
};
}

0 comments on commit 81b3d16

Please sign in to comment.