Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
setvisible committed May 8, 2023
2 parents 47857c5 + 739fd29 commit fc73a08
Show file tree
Hide file tree
Showing 14 changed files with 353 additions and 70 deletions.
12 changes: 12 additions & 0 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static const QString REGISTRY_STREAM_SHORTCUT = "StreamShortcutEnabled";

// Tab Network
static const QString REGISTRY_MAX_SIMULTANEOUS = "MaxSimultaneous";
static const QString REGISTRY_CONCURRENT_FRAG = "ConcurrentFragments";
static const QString REGISTRY_CUSTOM_BATCH = "CustomBatchEnabled";
static const QString REGISTRY_CUSTOM_BATCH_BL = "CustomBatchButtonLabel";
static const QString REGISTRY_CUSTOM_BATCH_RGE = "CustomBatchRange";
Expand Down Expand Up @@ -125,6 +126,7 @@ Settings::Settings(QObject *parent) : AbstractSettings(parent)

// Tab Network
addDefaultSettingInt(REGISTRY_MAX_SIMULTANEOUS, 4);
addDefaultSettingInt(REGISTRY_CONCURRENT_FRAG, DEFAULT_CONCURRENT_FRAGMENTS);
addDefaultSettingBool(REGISTRY_CUSTOM_BATCH, true);
addDefaultSettingString(REGISTRY_CUSTOM_BATCH_BL, QLatin1String("1 -> 25"));
addDefaultSettingString(REGISTRY_CUSTOM_BATCH_RGE, QLatin1String("[1:25]"));
Expand Down Expand Up @@ -370,6 +372,16 @@ void Settings::setMaxSimultaneousDownloads(int number)
setSettingInt(REGISTRY_MAX_SIMULTANEOUS, number);
}

int Settings::concurrentFragments() const
{
return getSettingInt(REGISTRY_CONCURRENT_FRAG);
}

void Settings::setConcurrentFragments(int fragments)
{
setSettingInt(REGISTRY_CONCURRENT_FRAG, fragments);
}

bool Settings::isCustomBatchEnabled() const
{
return getSettingBool(REGISTRY_CUSTOM_BATCH);
Expand Down
3 changes: 3 additions & 0 deletions src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class Settings : public AbstractSettings
int maxSimultaneousDownloads() const;
void setMaxSimultaneousDownloads(int number);

int concurrentFragments() const;
void setConcurrentFragments(int fragments);

bool isCustomBatchEnabled() const;
void setCustomBatchEnabled(bool enabled);

Expand Down
98 changes: 84 additions & 14 deletions src/core/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static const QString C_DOWNLOAD_next_section = QLatin1String("Destination:");


static QString s_youtubedl_version = QString();
static int s_youtubedl_concurrent_fragments = 0;
static bool s_youtubedl_last_modified_time_enabled = true;
static QString s_youtubedl_user_agent = QString();
static int s_youtubedl_socket_type = 0;
Expand Down Expand Up @@ -126,6 +127,11 @@ QString Stream::website()
return C_WEBSITE_URL;
}

void Stream::setConcurrentFragments(int fragments)
{
s_youtubedl_concurrent_fragments = fragments > 0 ? fragments : 0;
}

void Stream::setLastModifiedTimeEnabled(bool enabled)
{
s_youtubedl_last_modified_time_enabled = enabled;
Expand Down Expand Up @@ -370,6 +376,7 @@ QStringList Stream::arguments() const
}
}
if (m_config.chapter.writeChapters) {
/// \todo implement chapters writing
}
if (m_config.thumbnail.writeDefaultThumbnail) {
arguments << QLatin1String("--write-thumbnail");
Expand All @@ -390,6 +397,10 @@ QStringList Stream::arguments() const
arguments << QLatin1String("--format") << m_selectedFormatId.toString();

/* Global settings */
if (s_youtubedl_concurrent_fragments > 1) {
arguments << QLatin1String("--concurrent-fragments")
<< QString::number(s_youtubedl_concurrent_fragments);
}
if (!s_youtubedl_last_modified_time_enabled) {
arguments << QLatin1String("--no-mtime");
}
Expand Down Expand Up @@ -525,7 +536,9 @@ void Stream::parseStandardOutput(const QString &msg)
tokens.at(2) == QLatin1String("of")) {

auto percentToken = tokens.at(1);
auto sizeToken = tokens.at(3);
auto sizeToken = (tokens.at(3) != QLatin1String("~"))
? tokens.at(3)
: tokens.at(4);

auto percent = Format::parsePercentDecimal(percentToken);
if (percent < 0) {
Expand Down Expand Up @@ -924,7 +937,18 @@ StreamObject StreamAssetDownloader::parseDumpItemStdOut(const QByteArray &bytes)
}
QJsonObject json = loadDoc.object();
data.id = json[QLatin1String("id")].toString();
data.defaultTitle = json[QLatin1String("title")].toString();

auto title = json[QLatin1String("title")].toString();
if (title.isEmpty()) {
title = json[QLatin1String("alt_title")].toString();
}
if (title.isEmpty()) {
title = json[QLatin1String("fulltitle")].toString();
}
if (title.isEmpty()) {
title = json[QLatin1String("track")].toString();
}
data.title = title;

QJsonArray jsonFormats = json[QLatin1String("formats")].toArray();
foreach (auto jsonFormat, jsonFormats) {
Expand Down Expand Up @@ -952,13 +976,32 @@ StreamObject StreamAssetDownloader::parseDumpItemStdOut(const QByteArray &bytes)
format.vcodec = jsonFmt[QLatin1String("vcodec")].toString();

format.filesize = jsonFmt[QLatin1String("filesize")].toInt();

if (!(format.filesize > 0)) {
format.filesize = jsonFmt[QLatin1String("filesize_approx")].toInt();
}
data.formats << format;
}

data.defaultSuffix = json[QLatin1String("ext")].toString();
data.thumbnail = json[QLatin1String("thumbnail")].toString();
data.description = json[QLatin1String("description")].toString();

auto artist = json[QLatin1String("artist")].toString();
if (artist.isEmpty()) {
artist = json[QLatin1String("creator")].toString();
}
data.artist = artist;

data.album = json[QLatin1String("album")].toString();

auto release_year = json[QLatin1String("release_year")].toInt();
if (release_year > 0) {
data.release_year = QString("%0").arg(QString::number(release_year));
} else {
data.release_year = json[QLatin1String("release_date")].toString();
}

data.thumbnail = json[QLatin1String("thumbnail")].toString();

// Subtitles and Automatic Captions have the same format
{
QJsonObject jsonSubtitles = json[QLatin1String("subtitles")].toObject();
Expand All @@ -972,15 +1015,29 @@ StreamObject StreamAssetDownloader::parseDumpItemStdOut(const QByteArray &bytes)
data.webpage_url = json[QLatin1String("webpage_url")].toString();

//-----
// Specific extractors
// Specific Extractors
data.originalFilename = json[QLatin1String("_filename")].toString();
data.fulltitle = json[QLatin1String("fulltitle")].toString();
data.extractor = json[QLatin1String("extractor")].toString();
data.extractor_key = json[QLatin1String("extractor_key")].toString();
data.defaultFormatId = StreamFormatId(json[QLatin1String("format_id")].toString());

data.playlist = json[QLatin1String("playlist")].toString();
data.playlist_index = json[QLatin1String("playlist_index")].toString();
auto playlist_index = json[QLatin1String("playlist_index")].toInt();
auto playlist_autonumber= json[QLatin1String("playlist_autonumber")].toInt();
auto playlist_count = json[QLatin1String("playlist_count")].toInt();
auto n_entries = json[QLatin1String("n_entries")].toInt();

if (!(playlist_index > 0)) {
playlist_index = playlist_autonumber;
}
if (!(playlist_count > 0)) {
playlist_count = n_entries;
}
if (playlist_index > 0) {
auto digits = QString::number(playlist_count).count();
data.playlist_index = QString("%0").arg(QString::number(playlist_index), digits, QLatin1Char('0'));
}

obj.setError(StreamObject::NoError);
obj.setData(data);
return obj;
Expand Down Expand Up @@ -1076,8 +1133,8 @@ StreamObject StreamAssetDownloader::createStreamObject(const StreamFlatListItem
/// \todo replace with ErrorGeoRestriction instead?
si.setError(StreamObject::ErrorUnavailable);
}
if (si.data().defaultTitle.isEmpty()) {
si.data().defaultTitle = flatItem.title;
if (si.data().title.isEmpty()) {
si.data().title = flatItem.title;
}
if (si.data().webpage_url.isEmpty()) {
si.data().webpage_url = flatItem.url; /// \todo fix incomplete URL
Expand Down Expand Up @@ -1506,14 +1563,26 @@ qint64 StreamObject::guestimateFullSize(const StreamFormatId &formatId) const
return estimatedSize;
}

QString StreamObject::defaultTitle() const
{
auto title = m_data.title;
if (!m_data.artist.isEmpty() && !title.contains(m_data.artist, Qt::CaseInsensitive)) {
title.prepend(QString("%0 - ").arg(m_data.artist));
}
if (!m_data.release_year.isEmpty() && !title.contains(m_data.release_year, Qt::CaseInsensitive)) {
title.append(QString(" (%0)").arg(m_data.release_year));
}
return title;
}

QString StreamObject::title() const
{
return m_userTitle.isEmpty() ? m_data.defaultTitle : m_userTitle;
return m_userTitle.isEmpty() ? defaultTitle() : m_userTitle;
}

void StreamObject::setTitle(const QString &title)
{
m_userTitle = (title == m_data.defaultTitle) ? QString() : title;
m_userTitle = (title == defaultTitle()) ? QString() : title;
}

QString StreamObject::fullFileName() const
Expand Down Expand Up @@ -1671,11 +1740,12 @@ QString StreamObject::Data::debug_description() const
descr.append(QString("StreamObject::Data '%0' [%1] (%2, %3)").arg(
originalFilename,
webpage_url,
QString("%0, %1, %2, %3, %4").arg(
fulltitle,
defaultTitle,
QString("%0, %1, %2, %3, %4, %5").arg(
title,
defaultSuffix,
description,
artist,
release_year,
thumbnail),
QString("%0, %1, %2, %3, %4").arg(
extractor,
Expand Down
17 changes: 12 additions & 5 deletions src/core/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@ class StreamObject
&& originalFilename == other.originalFilename
&& subtitles == other.subtitles
&& webpage_url == other.webpage_url
&& fulltitle == other.fulltitle
&& defaultTitle == other.defaultTitle
&& title == other.title
&& defaultSuffix == other.defaultSuffix
&& description == other.description
&& artist == other.artist
&& album == other.album
&& release_year == other.release_year
&& thumbnail == other.thumbnail
&& extractor == other.extractor
&& extractor_key == other.extractor_key
Expand All @@ -237,15 +239,17 @@ class StreamObject
QList<Subtitle> subtitles;

QString webpage_url; // (string): URL to the video webpage
QString fulltitle; // (string): Video title
QString defaultTitle; // (string): Video title
QString title; // (string): Video title
QString defaultSuffix; // (string): Video filename suffix (complete extension)
QString description; // (string): Video description
QString artist; // (string): Artist(s) of the track
QString album; // (string): Title of the album the track belongs to
QString release_year; // (numeric): Year (YYYY) when the album was released
QString thumbnail; // (string): thumbnail URL
QString extractor; // (string): Name of the extractor
QString extractor_key; // (string): Key name of the extractor
StreamFormatId defaultFormatId; // (string): Format code specified by --format
QList<Format> formats; // List of available formats, ordered from worst to best quality
QList<Format> formats; // List of available formats, ordered from worst to best quality
QString playlist; // (string): Name or id of the playlist that contains the video
QString playlist_index; // (numeric): Index of the video in the playlist padded with leading zeros according to the total length of the playlist
};
Expand Down Expand Up @@ -402,6 +406,8 @@ class StreamObject
qint64 guestimateFullSize() const;
qint64 guestimateFullSize(const StreamFormatId &formatId) const;

QString defaultTitle() const;

QString title() const;
void setTitle(const QString &title);

Expand Down Expand Up @@ -448,6 +454,7 @@ class Stream : public QObject

static QString version();
static QString website();
static void setConcurrentFragments(int fragments);
static void setLastModifiedTimeEnabled(bool enabled);
static void setUserAgent(const QString &userAgent);
static void setConnectionProtocol(int index);
Expand Down
1 change: 1 addition & 0 deletions src/core/streammanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void StreamManager::setSettings(Settings *settings)
void StreamManager::onSettingsChanged()
{
if (m_settings) {
Stream::setConcurrentFragments(m_settings->concurrentFragments());
Stream::setLastModifiedTimeEnabled(m_settings->isRemoteLastModifiedTimeEnabled());
Stream::setUserAgent(m_settings->httpUserAgent());
Stream::setConnectionProtocol(m_settings->connectionProtocol());
Expand Down
20 changes: 8 additions & 12 deletions src/dialogs/batchrenamedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,23 @@ void BatchRenameDialog::renameToDefault()

void BatchRenameDialog::renameToEnumeration()
{
const int count = m_items.count();
const int from = ui->startSpinBox->value();
const int by = ui->incrementSpinBox->value();
auto count = m_items.count();
auto from = ui->startSpinBox->value();
auto by = ui->incrementSpinBox->value();

int digits = 0;
auto digits = 0;
if (ui->fillRadioButton->isChecked()) {
int last = from + count * by;
QString lastName = QString("%0").arg(last);
digits = lastName.count();
auto last = from + count * by;
digits = QString::number(last).count();

} else if (ui->customFillRadioButton->isChecked()) {
digits = ui->digitSpinBox->value();
}

int i = from;
auto i = from;
foreach (auto item, m_items) {
auto downloadItem = dynamic_cast<DownloadItem*>(item);
QString newName = QString("%0").arg(i);
if (digits > newName.count()) {
newName = newName.rightJustified(digits, QChar('0'));
}
auto newName = QString("%0").arg(QString::number(i), digits, QLatin1Char('0'));
rename(downloadItem, newName);
i += by;
}
Expand Down
23 changes: 22 additions & 1 deletion src/dialogs/preferencedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void PreferenceDialog::connectUi()

// Tab Network
connect(ui->maxSimultaneousDownloadSlider, SIGNAL(valueChanged(int)), this, SLOT(maxSimultaneousDownloadSlided(int)));
connect(ui->concurrentFragmentSlider, SIGNAL(valueChanged(int)), this, SLOT(concurrentFragmentSlided(int)));

connect(ui->proxyTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyTypeChanged(int)));
connect(ui->proxyAuthCheckBox, SIGNAL(toggled(bool)), this, SLOT(proxyAuthToggled(bool)));
Expand Down Expand Up @@ -280,6 +281,7 @@ void PreferenceDialog::restylizeUi()
// Restylize icons
const QMap<QLabel*, QString> map = {
{ui->streamHelp, "help"},
{ui->concurrentFragmentHelp, "help"},
{ui->httpUserAgentHelp, "help"},
{ui->httpReferringPageHelp, "help"}
};
Expand Down Expand Up @@ -396,7 +398,12 @@ void PreferenceDialog::themeChanged()
******************************************************************************/
void PreferenceDialog::maxSimultaneousDownloadSlided(int value)
{
ui->maxSimultaneousDownloadLabel->setText(QString::number(value));
ui->maxSimultaneousDownloadValue->setText(QString::number(value));
}

void PreferenceDialog::concurrentFragmentSlided(int value)
{
ui->concurrentFragmentValue->setText(QString::number(value));
}

void PreferenceDialog::proxyTypeChanged(int index)
Expand Down Expand Up @@ -487,6 +494,7 @@ void PreferenceDialog::read()

// Tab Network
ui->maxSimultaneousDownloadSlider->setValue(m_settings->maxSimultaneousDownloads());
ui->concurrentFragmentSlider->setValue(m_settings->concurrentFragments());

ui->customBatchGroupBox->setChecked(m_settings->isCustomBatchEnabled());
ui->customBatchButtonLabelLineEdit->setText(m_settings->customBatchButtonLabel());
Expand Down Expand Up @@ -567,6 +575,7 @@ void PreferenceDialog::write()

// Tab Network
m_settings->setMaxSimultaneousDownloads(ui->maxSimultaneousDownloadSlider->value());
m_settings->setConcurrentFragments(ui->concurrentFragmentSlider->value());

m_settings->setCustomBatchEnabled(ui->customBatchGroupBox->isChecked());
m_settings->setCustomBatchButtonLabel(ui->customBatchButtonLabelLineEdit->text());
Expand Down Expand Up @@ -700,6 +709,18 @@ void PreferenceDialog::setupStreamToolTip()
}
tooltip += "</body></html>";
ui->streamHelp->setToolTip(tooltip);

ui->concurrentFragmentHelp->setToolTip(
QString("<html><head/><body><p>%0</p></body></html>").arg(
tr("Servers might split large files into multiple fragments, "
"to optimize downloads. "
"This option enables multi-threaded fragment downloads: "
"Select the number of fragments that should be downloaded concurrently. "
"Note that the concurrency makes download faster (when available), "
"but the progress status and estimated time could be inaccurate (by design). "
"Choose between precision and speed. "
"Recommended value depends on your connection and machine. "
"20 is a good start. To disable it, set it to 1.")));
}

void PreferenceDialog::setupHttpToolTips()
Expand Down
Loading

0 comments on commit fc73a08

Please sign in to comment.