Skip to content

Commit

Permalink
- Fix signature decoder
Browse files Browse the repository at this point in the history
- Update google login button appearance
- Update langs
- Update youtube-dl
  • Loading branch information
Adrian committed Jan 23, 2020
1 parent 513bd97 commit acbfa72
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 30 deletions.
6 changes: 3 additions & 3 deletions AIMPYouTube.rc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDR_CONNECTRES1 CONNECTRESP "Resources\\connect_status.html"

LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDB_WHITELOGO PNG "Resources\\white_logo.png"
IDB_GOOGLEBTN PNG "Resources\\google_btn.png"

LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDB_ORANGELOGO PNG "Resources\\orange_logo.png"
IDB_GOOGLEFONT TTF "Resources\\Roboto-Medium.ttf"

LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDB_ICON PNG "Resources\\icon.png"
Expand Down Expand Up @@ -73,7 +73,7 @@ FONT 8, "Tahoma", 400, 0, 0
CONTROL "", IDC_YTDLTIMEOUTSPIN, UPDOWN_CLASS, UDS_ARROWKEYS | UDS_AUTOBUDDY | UDS_HOTTRACK | UDS_SETBUDDYINT, 87, 212, 11, 15, WS_EX_LEFT | WS_TABSTOP
AUTOCHECKBOX "Always use youtube-dl", IDC_YTDLFORCE, 15, 183, 250, 8, 0, WS_EX_LEFT | WS_TABSTOP
EDITTEXT IDC_YTDLPARAMS, 58, 195, 137, 14, ES_AUTOHSCROLL, WS_EX_LEFT
LTEXT "aimp_YouTube v1.3", IDC_VERSION, 30, 244, 285, 8, SS_LEFT | SS_NOTIFY, WS_EX_LEFT
LTEXT "aimp_YouTube v1.4", IDC_VERSION, 30, 244, 285, 8, SS_LEFT | SS_NOTIFY, WS_EX_LEFT
}


Expand Down
2 changes: 1 addition & 1 deletion Langs/english.lng
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PlaylistName=Playlist name (optional)
[YouTube.Options]
Title=YouTube
Account=YouTube account
ConnectButton=Connect|Disconnect
ConnectButton=# with Google|Sign out
General=General
MonitorURLs=Monitor added URLs
MonitorUserPlaylists=Monitor user's playlists
Expand Down
2 changes: 1 addition & 1 deletion Langs/polish.lng
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PlaylistName=Nazwa playlisty (opcjonalnie)
[YouTube.Options]
Title=YouTube
Account=Konto YouTube
ConnectButton=Zaloguj się|Wyloguj się
ConnectButton=Zaloguj się z Google|Wyloguj się
General=Ogólne
MonitorURLs=Monitoruj dodane adresy
MonitorUserPlaylists=Monitoruj playlisty użytkownika
Expand Down
2 changes: 1 addition & 1 deletion Langs/ukrainian.lng
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[FILE]
[FILE]
Author=Олександр (6c6c6) [http://localize.org.ua/]
Name=Ukrainian (UK)
VersionID=0
Expand Down
54 changes: 34 additions & 20 deletions OptionsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,30 +307,30 @@ void GetRoundRectPath(Gdiplus::GraphicsPath *pPath, Gdiplus::Rect r, int dia) {
LRESULT CALLBACK OptionsDialog::ButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
using namespace Gdiplus;
struct PaintData {
GdiPlusImageLoader Logo;
std::wstring Text;
Font Font;
Pen BorderPen;
ARGB Gradient[2];
SolidBrush TextColor;
Pen LinePen;
int LogoOffset;
int Margin;
int Height;
};

static PaintData connect { { IDB_WHITELOGO, L"PNG" }, {}, { L"Tahoma", 10, FontStyleBold }, 0xffd05300, { 0xffdc4a33, 0xffcd4127 }, 0xffffffff, 0xffc83f27, 39, 66, 35 };
static PaintData disconnect { { IDB_ORANGELOGO, L"PNG" }, {}, { L"Tahoma", 10 }, 0xffbfbfbf, { 0xffffffff, 0xfff1f1f1 }, 0xff333333, 0xffe4e4e4, 33, 56, 27 };
static PrivateFontCollection pfc;

static PaintData connect { {}, { L"Roboto Medium", 14, FontStyleBold, UnitPixel, &pfc }, 0x8a000000, 33, 72, 46 };
static PaintData disconnect { {}, { L"Roboto Medium", 14, FontStyleBold, UnitPixel, &pfc }, 0x8a000000, 33, 72, 46 };

static GdiPlusImageLoader BtnBackground { IDB_GOOGLEBTN, L"PNG" };

static PaintData *currentBtn = nullptr;
static OptionsDialog *dialog = nullptr;
static bool mouseOver = false;
static bool customFocus = false;
static bool connected = false;

static Rect r;
static Rect r, outer;
static RectF layoutRect;
static SolidBrush focusBrush(0x11000000);
static SolidBrush focusBrush(0x0A000000);
static Gdiplus::GraphicsPath borderPath;
static Gdiplus::StringFormat format;

Expand All @@ -339,6 +339,13 @@ LRESULT CALLBACK OptionsDialog::ButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam,
dialog = (OptionsDialog *)dwRefData;
format.SetAlignment(StringAlignmentCenter);
format.SetLineAlignment(StringAlignmentCenter);
if (HRSRC hResource = ::FindResource(g_hInst, MAKEINTRESOURCE(IDB_GOOGLEFONT), L"TTF")) {
if (DWORD dataSize = ::SizeofResource(g_hInst, hResource)) {
if (void *pResourceData = ::LockResource(::LoadResource(g_hInst, hResource))) {
pfc.AddMemoryFont(pResourceData, dataSize);
}
}
}
} break;
case WM_MOUSELEAVE: mouseOver = false; break;
case WM_MOUSEMOVE: mouseOver = true; break;
Expand All @@ -362,35 +369,42 @@ LRESULT CALLBACK OptionsDialog::ButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam,
currentBtn = &connect;
}
Gdiplus::Graphics(hWnd).MeasureString(currentBtn->Text.c_str(), currentBtn->Text.size(), &currentBtn->Font, PointF(0, 0), &textRect);
r.Width = textRect.Width + currentBtn->Margin;
r.Height = currentBtn->Height;
outer.Width = textRect.Width + currentBtn->Margin;
outer.Height = currentBtn->Height;
r.X = 3;
r.Y = 3;
r.Width = outer.Width - 6;
r.Height = outer.Height - 6;
if (connected) {
SetWindowPos(hWnd, NULL, rc.right - r.Width - 10, rc.bottom - r.Height - 10, r.Width, r.Height, SWP_NOZORDER);
SetWindowPos(hWnd, NULL, rc.right - outer.Width - 10, rc.bottom - outer.Height - 10, outer.Width, outer.Height, SWP_NOZORDER);
} else {
SetWindowPos(hWnd, NULL, rc.left + ((rc.right - rc.left) - r.Width) / 2, rc.top + ((rc.bottom - rc.top) - r.Height) / 2, r.Width, r.Height, SWP_NOZORDER);
SetWindowPos(hWnd, NULL, rc.left + ((rc.right - rc.left) - outer.Width) / 2, rc.top + ((rc.bottom - rc.top) - outer.Height) / 2, outer.Width, outer.Height, SWP_NOZORDER);
}

GetRoundRectPath(&borderPath, r, 4);
layoutRect = RectF(currentBtn->LogoOffset, 0, r.Width - currentBtn->LogoOffset, r.Height);
layoutRect = RectF(currentBtn->LogoOffset, 3, r.Width - currentBtn->LogoOffset, r.Height);
GetRoundRectPath(&borderPath, r, 6);
} break;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
Gdiplus::Graphics g(hdc);
g.Clear(0xfff0f0f0);

g.DrawImage(BtnBackground, Gdiplus::RectF(0, 0, 54, outer.Height), 0, 0, 108, 92, Gdiplus::UnitPixel); // left side
g.DrawImage(BtnBackground, Gdiplus::RectF(54, 0, outer.Width - 54 - 8, outer.Height), 108, 0, 5, 92, Gdiplus::UnitPixel); // middle stretch
g.DrawImage(BtnBackground, Gdiplus::RectF(outer.Width - 8, 0, 8, outer.Height), 108, 0, 16, 92, Gdiplus::UnitPixel); // right side

LinearGradientBrush linGrBrush(Point(0, 0), Point(0, r.Height), currentBtn->Gradient[mouseOver ? 1 : 0], currentBtn->Gradient[mouseOver ? 0 : 1]);
g.FillPath(&linGrBrush, &borderPath);
if (customFocus)
if (customFocus || mouseOver)
g.FillPath(&focusBrush, &borderPath);

g.DrawImage(currentBtn->Logo, 10, 7, currentBtn->Logo->GetWidth(), currentBtn->Logo->GetHeight());
g.DrawLine(&currentBtn->LinePen, currentBtn->LogoOffset, 0, currentBtn->LogoOffset, r.Height);
g.SetTextRenderingHint(TextRenderingHintAntiAlias);
g.DrawString(currentBtn->Text.c_str(), currentBtn->Text.size(), &currentBtn->Font, layoutRect, &format, &currentBtn->TextColor);
g.DrawPath(&currentBtn->BorderPen, &borderPath);

EndPaint(hWnd, &ps);
return TRUE;
}
case WM_ERASEBKGND:
return TRUE;
case WM_SETCURSOR:
SetCursor(LoadCursor(NULL, IDC_HAND));
return TRUE;
Expand Down
Binary file added Resources/Roboto-Medium.ttf
Binary file not shown.
Binary file removed Resources/google-official.png
Binary file not shown.
Binary file added Resources/google_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Resources/orange_logo.png
Binary file not shown.
Binary file removed Resources/white_logo.png
Binary file not shown.
4 changes: 3 additions & 1 deletion YouTubeAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ void YouTubeAPI::LoadSignatureDecoder() {

// Taken from youtube-dl
// https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L1342
std::vector<std::regex> patterns {
static std::vector<std::regex> patterns {
std::regex(R"PATTERN(\b([a-zA-Z0-9$]{2})\s*=\s*function\(\s*a\s*\)\s*\{\s*a\s*=\s*a\.split\(\s*""\s*\))PATTERN"),
std::regex(R"PATTERN(\b[a-d]\s*&&\s*\([a-d]\s*=\s*([a-zA-Z0-9$]+)\(\s*decodeURIComponent\s*\([a-d]\)\),\s*[a-d]\.set\([^,]+\s*,\s*enc)PATTERN"),
std::regex(R"PATTERN(\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*([a-zA-Z0-9$]+)\()PATTERN"),
std::regex(R"PATTERN(\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*([a-zA-Z0-9$]+)\()PATTERN"),
std::regex(R"PATTERN(([a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*\{\s*a\s*=\s*a\.split\(\s*""\s*\))PATTERN")
Expand Down
4 changes: 3 additions & 1 deletion YouTubeDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ std::wstring YouTubeDL::GetStreamUrl(const std::wstring &id) {
const auto error = readPipe(pipeReadErr);

if (exitCode || result.empty()) {
Tools::ShowLastError(L"YouTubeDL::GetStreamUrl(): " + error);
if (!error.empty())
Tools::ShowLastError(L"YouTubeDL::GetStreamUrl(): " + error);

static bool updated = false;
if (!updated) {
updated = true;
Expand Down
4 changes: 2 additions & 2 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#endif

#define IDD_SETTINGS 101
#define IDB_WHITELOGO 106
#define IDB_ORANGELOGO 107
#define IDB_GOOGLEBTN 106
#define IDB_GOOGLEFONT 107
#define IDC_VERSION 108
#define IDB_ICON 110
#define IDD_ADDURL 112
Expand Down
Binary file modified youtube-dl.exe
Binary file not shown.

0 comments on commit acbfa72

Please # to comment.