Skip to content

Commit d2a0b18

Browse files
author
Alexander Grahn
committed
fix search string parsing
1 parent 7165480 commit d2a0b18

2 files changed

Lines changed: 26 additions & 22 deletions

File tree

js/main.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ var toggleQuant = function(t, h) {
12481248
//arg 3: list id,
12491249
//arg 4: loop start, arg 4: loop end time
12501250
//arg 5: playback speed
1251-
var loadYT = function(vid, plist, lid, ta, tb, r, lType = "playlist") {
1251+
var loadYT = function(vid, plist, lid, ta, tb, r, lType) {
12521252
initYT(); //initialize player-specific functions
12531253
resetUI();
12541254
//remove previous player, if there is one
@@ -1270,23 +1270,20 @@ var loadYT = function(vid, plist, lid, ta, tb, r, lType = "playlist") {
12701270
let ytDiv = document.createElement("div");
12711271
ytDiv.id = "ytDiv";
12721272
myResizable.appendChild(ytDiv);
1273-
//create new YT player iframe, replacing ytDiv
1274-
ytPlayer = new YT.Player("ytDiv", {
1275-
videoId: vid && vid.substring(0, 4) === "vid:" ? vid.substring(4) : vid,
1273+
let playerVars = {
1274+
"autoplay": 1,
1275+
"modestbranding": 1,
1276+
"fs": 0,
1277+
"rel": 0
1278+
}
1279+
if (vid && vid.substring(0, 4) === "idx:") playerVars["index"] = vid.substring(4);
1280+
if (lid) playerVars["list"] = lid;
1281+
if (lType) playerVars["listType"] = lType;
1282+
if (plist) playerVars["playlist"] = plist;
1283+
let playerParams = {
12761284
width: playerWidth,
12771285
height: $("#myResizable").height(),
1278-
playerVars: {
1279-
index: vid && vid.substring(0, 4) === "idx:" ? vid.substring(4) : null,
1280-
list: lid,
1281-
listType: lType,
1282-
playlist: plist,
1283-
//loop: 1, //loop over playlist
1284-
//playlist: vid && !plist && !lid ? vid.substring(4) : plist, //loop single video
1285-
autoplay: 1,
1286-
modestbranding: 1,
1287-
fs: 0, //no fullscreen button
1288-
rel: 0, //no related videos at the end
1289-
},
1286+
playerVars: playerVars,
12901287
events: {
12911288
"onReady": function(e) {
12921289
if (searchStr) {
@@ -1316,11 +1313,15 @@ var loadYT = function(vid, plist, lid, ta, tb, r, lType = "playlist") {
13161313
"onError": function(e) {
13171314
console.log("Error: " + e.data);
13181315
resetUI();
1319-
if (lid && lType === "playlist") loadYT(vid, null, lid, ta, tb, r, "user_uploads");
1320-
else loadYT(null, null, null, null, null, null);
1316+
if (lid && lType === "playlist") { // instead, try with "user_uploads" as list type
1317+
loadYT(vid, null, lid, ta, tb, r, "user_uploads");
1318+
}
13211319
}
13221320
}
1323-
});
1321+
}
1322+
if (vid && vid.substring(0, 4) === "vid:") playerParams["videoId"] = vid.substring(4);
1323+
//create new YT player iframe, replacing ytDiv
1324+
ytPlayer = new YT.Player("ytDiv", playerParams);
13241325
}
13251326

13261327
var onYouTubeIframeAPIReady = function() {
@@ -1414,8 +1415,7 @@ var saveId = function(id) {
14141415
}
14151416

14161417
var queryYT = function(qu) {
1417-
let vid, plist, lid, lType = "playlist",
1418-
audioOnly = null;
1418+
let vid, plist, lid, lType, audioOnly = null;
14191419
let q = "?" + qu;
14201420
if (
14211421
!qu.match(/videoid|listid|playlist|index/) &&
@@ -1424,6 +1424,7 @@ var queryYT = function(qu) {
14241424
vid = qu.trim().match(/^[0-9a-zA-Z_-]{11}$/);
14251425
if (vid) vid = "vid:" + vid[0];
14261426
lid = qu.trim().match(/^[0-9A-Za-z_-]{12,}$/);
1427+
if (lid) lType = "playlist";
14271428
if (!lid) {
14281429
lid = qu.trim().match(/(?<=^@)[0-9A-Za-z_.-]{3,30}$/); //handle?
14291430
if (lid) lType = "user_uploads";
@@ -1438,6 +1439,7 @@ var queryYT = function(qu) {
14381439
if (vid) vid = "idx:" + vid[0];
14391440
}
14401441
lid = qu.match(/(?<=[?&]list=)[0-9A-Za-z_.-]{3,}/);
1442+
if (lid) lType = "playlist";
14411443
if (!lid) {
14421444
lid = qu.match(/(?<=\/@)[0-9A-Za-z_.-]{3,30}/);
14431445
if (lid) lType = "user_uploads";
@@ -1451,6 +1453,7 @@ var queryYT = function(qu) {
14511453
if (vid) vid = "idx:" + vid[0];
14521454
}
14531455
lid = q.match(/(?<=[?&]listid=)[0-9A-Za-z_-]{12,}/);
1456+
if (lid) lType = "playlist";
14541457
if (!lid) {
14551458
lid = q.match(/(?<=[?&]listid=@)[0-9A-Za-z_.-]{3,30}/);
14561459
if (lid) lType = "user_uploads";
@@ -1486,7 +1489,8 @@ var queryYT = function(qu) {
14861489
lid ? lid[0] : null,
14871490
ta ? ta[0] : null,
14881491
tb ? tb[0] : null,
1489-
r, lType
1492+
r,
1493+
lType ? lType : null
14901494
);
14911495
}
14921496
}

zip/ABLoopPlayer.zip

-5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)