Skip to content

Commit ac5fb91

Browse files
committed
YT_DLP: определяем текущее видео в плейлисте.
1 parent 4f191e9 commit ac5fb91

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/apps/mplayerc/PlayerYtDlp.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ bool YT_DLP::CheckNonYtPlaylistURL(CString url)
426426
return false;
427427
}
428428

429-
bool YT_DLP::Parse_Playlist(const CStringW& url, CFileItemList& playlist, int& idx_CurrentPlay)
429+
bool YT_DLP::Parse_Playlist(const CStringW& pls_url, CFileItemList& playlist, int& idx_CurrentPlay)
430430
{
431431
// get a copy of the settings
432432

@@ -440,7 +440,7 @@ bool YT_DLP::Parse_Playlist(const CStringW& url, CFileItemList& playlist, int& i
440440
// run yt-dlp.exe
441441

442442
CStringA buf_out;
443-
bool ok = RunYtDlp(ydl_path, L"--flat-playlist --dump-single-json", url, buf_out);
443+
bool ok = RunYtDlp(ydl_path, L"--flat-playlist --dump-single-json", pls_url, buf_out);
444444
if (!ok) {
445445
return false;
446446
}
@@ -457,12 +457,24 @@ bool YT_DLP::Parse_Playlist(const CStringW& url, CFileItemList& playlist, int& i
457457
return false;
458458
}
459459

460+
playlist.clear();
461+
idx_CurrentPlay = -1;
462+
460463
for (const auto& entry : entries->GetArray()) {
461464
CStringW url;
462465
if (!getJsonValue(entry, "url", url)) {
463466
continue;
464467
}
465468

469+
if (idx_CurrentPlay < 0) {
470+
CStringW id;
471+
if (getJsonValue(entry, "id", id)) {
472+
if (pls_url.Find(id) > 0) {
473+
idx_CurrentPlay = (int)playlist.size();
474+
}
475+
}
476+
}
477+
466478
CStringW title;
467479
getJsonValue(entry, "title", title);
468480
int duration = 0;
@@ -471,7 +483,14 @@ bool YT_DLP::Parse_Playlist(const CStringW& url, CFileItemList& playlist, int& i
471483
playlist.emplace_back(url, title, UNITS * duration);
472484
}
473485

474-
return playlist.size() > 0;
486+
if (playlist.size()) {
487+
if (idx_CurrentPlay < 0) {
488+
idx_CurrentPlay = 0;
489+
}
490+
return true;
491+
}
492+
493+
return false;
475494
}
476495

477496
bool YT_DLP::SetFormats(const rapidjson::Document& doc)

src/apps/mplayerc/PlayerYtDlp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class YT_DLP
9999
static LPCWSTR CheckVideoURL(CStringW url);
100100
static bool YT_DLP::CheckNonYtPlaylistURL(CString url);
101101

102-
static bool Parse_Playlist(const CStringW& url, CFileItemList& playlist, int& idx_CurrentPlay);
102+
static bool Parse_Playlist(const CStringW& pls_url, CFileItemList& playlist, int& idx_CurrentPlay);
103103

104104
public:
105105
CStringW mAuthor;

0 commit comments

Comments
 (0)