Skip to content

Commit

Permalink
Настройка "Preferred audio format" работает для встроенного парсера Y…
Browse files Browse the repository at this point in the history
…ouTube.
  • Loading branch information
v0lt committed Dec 9, 2024
1 parent f82185e commit 091c8cb
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 43 deletions.
29 changes: 19 additions & 10 deletions src/apps/mplayerc/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,13 @@ void CAppSettings::ResetSettings()

strLastOpenFilterDir.Empty();

bYoutubePageParser = true;
YoutubeFormat.vfmt = 0;
YoutubeFormat.res = 720;
YoutubeFormat.fps60 = false;
YoutubeFormat.hdr = false;
strYoutubeAudioLang = CPPageYoutube::GetDefaultLanguageCode();
bYoutubePageParser = true;
YoutubeFormat.vfmt = Youtube::y_mp4_avc;
YoutubeFormat.res = 720;
YoutubeFormat.fps60 = false;
YoutubeFormat.hdr = false;
YoutubeFormat.afmt = Youtube::y_mp4_aac;
strYoutubeAudioLang = CPPageYoutube::GetDefaultLanguageCode();
bYoutubeLoadPlaylist = false;

bYDLEnable = true;
Expand Down Expand Up @@ -1496,10 +1497,10 @@ void CAppSettings::LoadSettings(bool bForce/* = false*/)
// OnlineServices
profile.ReadBool(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_PAGEPARSER, bYoutubePageParser);
str.Empty();
profile.ReadString(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_FORMAT, str);
profile.ReadString(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_VIDEOFORMAT, str);
YoutubeFormat.vfmt =
(str == L"WEBM") ? Youtube::y_webm_vp9
: (str == L"AV1") ? Youtube::y_mp4_av1
(str == L"WEBM-VP9") ? Youtube::y_webm_vp9
: (str == L"MP4-AV1") ? Youtube::y_mp4_av1
: Youtube::y_mp4_avc;
profile.ReadInt(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_RESOLUTION, YoutubeFormat.res);
YoutubeFormat.res = discard(YoutubeFormat.res, 720, s_CommonVideoHeights);
Expand All @@ -1509,6 +1510,11 @@ void CAppSettings::LoadSettings(bool bForce/* = false*/)
} else {
YoutubeFormat.hdr = false;
}
str.Empty();
profile.ReadString(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_AUDIOFORMAT, str);
YoutubeFormat.afmt =
(str == L"OPUS") ? Youtube::y_webm_opus
: Youtube::y_mp4_aac;
profile.ReadString(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_AUDIOLANGUAGE, strYoutubeAudioLang);
strYoutubeAudioLang.Trim();
profile.ReadBool(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_LOAD_PLAYLIST, bYoutubeLoadPlaylist);
Expand Down Expand Up @@ -2001,13 +2007,16 @@ void CAppSettings::SaveSettings()

// OnlineServices
profile.WriteBool(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_PAGEPARSER, bYoutubePageParser);
profile.WriteString(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_FORMAT,
profile.WriteString(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_VIDEOFORMAT,
(YoutubeFormat.vfmt == Youtube::y_webm_vp9) ? L"WEBM"
: (YoutubeFormat.vfmt == Youtube::y_mp4_av1) ? L"AV1"
: L"MP4");
profile.WriteInt(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_RESOLUTION, YoutubeFormat.res);
profile.WriteBool(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_60FPS, YoutubeFormat.fps60);
profile.WriteBool(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_HDR, YoutubeFormat.hdr);
profile.WriteString(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_AUDIOFORMAT,
(YoutubeFormat.afmt == Youtube::y_webm_opus) ? L"OPUS"
: L"AAC");
profile.WriteString(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_AUDIOLANGUAGE, strYoutubeAudioLang);
profile.WriteBool(IDS_R_ONLINESERVICES, IDS_RS_YOUTUBE_LOAD_PLAYLIST, bYoutubeLoadPlaylist);
profile.WriteBool(IDS_R_ONLINESERVICES, IDS_RS_YDL_ENABLE, bYDLEnable);
Expand Down
1 change: 1 addition & 0 deletions src/apps/mplayerc/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ class CAppSettings
int res;
bool fps60;
bool hdr;
int afmt;
} YoutubeFormat;
CStringW strYoutubeAudioLang;
bool bYoutubeLoadPlaylist;
Expand Down
12 changes: 7 additions & 5 deletions src/apps/mplayerc/PPageYouTube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ BOOL CPPageYoutube::OnInitDialog()
m_chk60fps.SetCheck(s.YoutubeFormat.fps60 ? BST_CHECKED : BST_UNCHECKED);
m_chkHdr.SetCheck(s.YoutubeFormat.hdr ? BST_CHECKED : BST_UNCHECKED);

//m_cbAudioFormat.AddString(L"AAC");
//m_cbAudioFormat.AddString(L"Opus");
m_cbAudioFormat.AddString(L"AAC");
m_cbAudioFormat.AddString(L"Opus");
m_cbAudioFormat.SetCurSel(s.YoutubeFormat.afmt - Youtube::y_mp4_aac);

static std::vector<CStringW> langNames;
if (langNames.empty()) {
Expand Down Expand Up @@ -190,10 +191,11 @@ BOOL CPPageYoutube::OnApply()
CAppSettings& s = AfxGetAppSettings();

s.bYoutubePageParser = !!m_chkPageParser.GetCheck();
s.YoutubeFormat.vfmt = m_cbVideoFormat.GetCurSel();
s.YoutubeFormat.vfmt = m_cbVideoFormat.GetCurSel();
s.YoutubeFormat.res = GetCurItemData(m_cbResolution);
s.YoutubeFormat.fps60 = !!m_chk60fps.GetCheck();
s.YoutubeFormat.hdr = !!m_chkHdr.GetCheck();
s.YoutubeFormat.afmt = m_cbAudioFormat.GetCurSel() + Youtube::y_mp4_aac;
if (m_cbAudioLang.GetCurSel() >= 0) {
s.strYoutubeAudioLang = m_langcodes[m_cbAudioLang.GetCurSel()];
} else {
Expand Down Expand Up @@ -238,8 +240,8 @@ void CPPageYoutube::OnCheckPageParser()
if (bEnable) {
OnCheck60fps();
}
GetDlgItem(IDC_STATIC3)->EnableWindow(FALSE);
m_cbAudioFormat.EnableWindow(FALSE);
GetDlgItem(IDC_STATIC3)->EnableWindow(bEnable);
m_cbAudioFormat.EnableWindow(bEnable);
GetDlgItem(IDC_STATIC4)->EnableWindow(bEnable);
m_cbAudioLang.EnableWindow(bEnable);

Expand Down
25 changes: 13 additions & 12 deletions src/apps/mplayerc/PlayerYouTube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,16 @@ namespace Youtube
if (k_aac < 0 && format == y_mp4_aac) {
k_aac = i;
}
else if (k_opus < 0 && format == y_webm_aud) {
else if (k_opus < 0 && format == y_webm_opus) {
k_opus = i;
}
}

size_t k = 0;
if (s.YoutubeFormat.vfmt == y_mp4_avc || s.YoutubeFormat.vfmt == y_mp4_av1) {
if (s.YoutubeFormat.afmt == y_mp4_aac) {
k = (k_aac >= 0) ? k_aac : (k_opus >= 0) ? k_opus : 0;
}
else if (s.YoutubeFormat.vfmt == y_webm_vp9) {
else if (s.YoutubeFormat.afmt == y_webm_opus) {
k = (k_opus >= 0) ? k_opus : (k_aac >= 0) ? k_aac : 0;
}
final_item = &youtubeAudioUrllist[k];
Expand Down Expand Up @@ -862,12 +862,12 @@ namespace Youtube
item.url = url;

switch (audioprofile->format) {
case y_mp4_aac: item.title = L"MP4/AAC"; break;
case y_webm_aud: item.title = L"WebM/Opus"; break;
case y_mp4_ac3: item.title = L"MP4/AC3"; break;
case y_mp4_eac3: item.title = L"MP4/E-AC3"; break;
case y_mp4_dtse: item.title = L"MP4/DTS-Express"; break;
default: item.title = L"unknown"; break;
case y_mp4_aac: item.title = L"MP4/AAC"; break;
case y_webm_opus: item.title = L"WebM/Opus"; break;
case y_mp4_ac3: item.title = L"MP4/AC3"; break;
case y_mp4_eac3: item.title = L"MP4/E-AC3"; break;
case y_mp4_dtse: item.title = L"MP4/DTS-Express"; break;
default: item.title = L"unknown"; break;
}
item.title.AppendFormat(L" %dkbit/s", audioprofile->quality);

Expand Down Expand Up @@ -1442,7 +1442,7 @@ namespace Youtube
}
}
for (const auto& item : youtubeAudioUrllist) {
if (item.profile->format == Youtube::y_webm_aud) {
if (item.profile->format == Youtube::y_webm_opus) {
youtubeUrllist.emplace_back(item);
break;
}
Expand Down Expand Up @@ -1838,12 +1838,13 @@ namespace Youtube

const YoutubeUrllistItem* GetAudioUrl(const YoutubeProfile* vprofile, const YoutubeUrllist& youtubeAudioUrllist)
{
const CAppSettings& s = AfxGetAppSettings();
const YoutubeUrllistItem* audio_item = nullptr;

if (youtubeAudioUrllist.size()) {
for (const auto& item : youtubeAudioUrllist) {
if ((vprofile->format == y_mp4_avc || vprofile->format == y_mp4_av1) && item.profile->format == y_mp4_aac
|| (vprofile->format != y_mp4_avc && vprofile->format != y_mp4_av1) && item.profile->format != y_mp4_aac) {
if (s.YoutubeFormat.afmt == y_mp4_aac && item.profile->format == y_mp4_aac
|| s.YoutubeFormat.afmt == y_webm_opus && item.profile->format == y_webm_opus) {
audio_item = &item;
if (vprofile->type != y_video || vprofile->quality > 360) {
break;
Expand Down
26 changes: 11 additions & 15 deletions src/apps/mplayerc/PlayerYouTube.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ namespace Youtube

// audiofile
y_mp4_aac,
y_webm_aud,
y_webm_opus,
y_mp4_ac3,
y_mp4_eac3,
y_mp4_dtse

// flv, 3gp are not used.
};

enum ytype {
Expand Down Expand Up @@ -128,22 +126,20 @@ namespace Youtube

static const YoutubeProfile YAudioProfiles[] = {
// AAC
{258, y_mp4_aac, y_audio, 384, L"m4a"},
{256, y_mp4_aac, y_audio, 192, L"m4a"},
{140, y_mp4_aac, y_audio, 128, L"m4a"},
{139, y_mp4_aac, y_audio, 48, L"m4a"}, // may be outdated and no longer supported
{258, y_mp4_aac, y_audio, 384, L"m4a"},
{256, y_mp4_aac, y_audio, 192, L"m4a"},
{140, y_mp4_aac, y_audio, 128, L"m4a"},
{139, y_mp4_aac, y_audio, 48, L"m4a"}, // may be outdated and no longer supported
// Opus
{251, y_webm_aud, y_audio, 160, L"mka"},
{250, y_webm_aud, y_audio, 70, L"mka"},
{249, y_webm_aud, y_audio, 50, L"mka"},
// Vorbis
//{249, y_webm_aud, y_audio, 128, L"webm", false, false},
{251, y_webm_opus, y_audio, 160, L"mka"},
{250, y_webm_opus, y_audio, 70, L"mka"},
{249, y_webm_opus, y_audio, 50, L"mka"},
// AC3
{380, y_mp4_ac3, y_audio, 384, L"m4a"},
{380, y_mp4_ac3, y_audio, 384, L"m4a"},
// E-AC3
{328, y_mp4_eac3, y_audio, 384, L"m4a"},
{328, y_mp4_eac3, y_audio, 384, L"m4a"},
// DTS-Express
{325, y_mp4_dtse, y_audio, 384, L"m4a"},
{325, y_mp4_dtse, y_audio, 384, L"m4a"},
};

struct YoutubeFields {
Expand Down
3 changes: 2 additions & 1 deletion src/apps/mplayerc/SettingsDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@
#define IDS_R_ONLINESERVICES L"OnlineServices"
#define IDS_R_YOUTUBECACHE L"OnlineServices\\YoutubeCache"
#define IDS_RS_YOUTUBE_PAGEPARSER L"YoutubePageParser"
#define IDS_RS_YOUTUBE_FORMAT L"YoutubeFormat"
#define IDS_RS_YOUTUBE_VIDEOFORMAT L"YoutubeVideoFormat"
#define IDS_RS_YOUTUBE_RESOLUTION L"YoutubeResolution"
#define IDS_RS_YOUTUBE_60FPS L"Youtube60fps"
#define IDS_RS_YOUTUBE_HDR L"YoutubeHDR"
#define IDS_RS_YOUTUBE_AUDIOFORMAT L"YoutubeAudioFormat"
#define IDS_RS_YOUTUBE_AUDIOLANGUAGE L"YoutubeAudioLanguage"
#define IDS_RS_YOUTUBE_LOAD_PLAYLIST L"YoutubeLoadPlaylist"
#define IDS_RS_YDL_ENABLE L"YDLEnable"
Expand Down

0 comments on commit 091c8cb

Please sign in to comment.