Subversion Repositories cheapmusic

Rev

Rev 136 | Rev 138 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 - 1
<?php
20 - 2
error_reporting(E_ALL);
10 - 3
 
4
// BUGBUG {"message": "You are making requests too quickly."}
137 - 5
function findDiscogsMaster() {
10 - 6
    $vendors = Vendors::getInstance();
7
    $config = $vendors->getVendor(Vendors::DISCOGS);
45 - 8
    $maxMasterCount = $config['maxMasters'];
13 - 9
 
10 - 10
    $_SESSION["discogs"] = "";
137 - 11
    $stxt = $_SESSION["searchTerm"];
10 - 12
 
81 - 13
    $params = [];
14
    $params["token"] = $config['token'];
137 - 15
    $params["type"] = "All";
46 - 16
 
137 - 17
    if (!empty($_SESSION["advSearch"])) {
18
        $stxt = '';
19
        if (!empty($_SESSION["advSearch"]["Title"])) {
20
            $params["release_title"] = $_SESSION["advSearch"]["Title"];
21
            $stxt .= $_SESSION["advSearch"]["Title"];
65 - 22
        }
137 - 23
        if (!empty($_SESSION["advSearch"]["Artist"])) {
24
            $params["artist"] = $_SESSION["advSearch"]["Artist"];
25
            $stxt .= $_SESSION["advSearch"]["Artist"];
46 - 26
        }
137 - 27
        if (!empty($_SESSION["advSearch"]["Track"])) {
28
            $params["track"] = $_SESSION["advSearch"]["Track"];
29
            $stxt .= $_SESSION["advSearch"]["Track"];
30
        }
31
        if (!empty($_SESSION["advSearch"]["Barcode"])) {
32
            $params["barcode"] = $_SESSION["advSearch"]["Barcode"];
33
            $stxt .= $_SESSION["advSearch"]["Barcode"];
34
        }
35
        if (!empty($_SESSION["advSearch"]["Format"])) {
36
            $params["format"] = $_SESSION["advSearch"]["Format"];
37
            $stxt .= $_SESSION["advSearch"]["Format"];
38
        }
39
        if (!empty($_SESSION["advSearch"]["Catno"])) {
40
            $params["catno"] = $_SESSION["advSearch"]["Catno"];
41
            $stxt .= $_SESSION["advSearch"]["Catno"];
42
        }
43
        if (!empty($_SESSION["advSearch"]["Label"])) {
44
            $params["label"] = $_SESSION["advSearch"]["Label"];
45
            $stxt .= $_SESSION["advSearch"]["Label"];
46
        }
47
        if (!empty($_SESSION["advSearch"]["Country"])) {
48
            $params["country"] = $_SESSION["advSearch"]["Country"];
49
            $stxt .= $_SESSION["advSearch"]["Country"];
50
        }
51
        if (!empty($_SESSION["advSearch"]["Year"])) {
52
            $params["year"] = $_SESSION["advSearch"]["Year"];
53
            $stxt .= $_SESSION["advSearch"]["Year"];
54
        }
55
    } else {
56
        $params["query"] = ($stxt == "***RANDOM***" ? mt_rand($config['minRelease'], $config['maxRelease']) : $stxt);
65 - 57
    }
10 - 58
 
81 - 59
    $pairs = array();
60
    foreach ($params as $key => $value) {
61
        array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
62
    }
63
    $canonical_query_string = join("&", $pairs);
64
 
65
    $url = "https://api.discogs.com/database/search?" . $canonical_query_string;
127 - 66
    $searchResp = ($stxt == "***RANDOM***" ? false : getSearchCache("Discogs", $stxt, ""));
99 - 67
    if ($searchResp === false) {
68
        $searchResp = getUrl($url, $config['userAgent']);
127 - 69
        if ($stxt != "***RANDOM***") {
70
            saveSearchCache("Discogs", $stxt, "", $searchResp);
104 - 71
        }
99 - 72
    }
65 - 73
    $searchResp = utf8_encode($searchResp);
74
    $searchResp = json_decode($searchResp);
10 - 75
 
43 - 76
    if (empty($searchResp)) {
77
        return;
78
    }
79
 
10 - 80
    if (!empty($searchResp->{'message'})) {
81
        if ($searchResp->{'message'} == "You are making requests too quickly.") {
96 - 82
            my_error_log("Discogs: You are making requests too quickly.");
10 - 83
            return;
84
        }
14 - 85
        return;
10 - 86
    }
87
 
88
    if ($searchResp->{'pagination'}->{'items'} < 1) {
127 - 89
        if ($stxt == "***RANDOM***") { // must find something
45 - 90
            findDiscogsMaster("***RANDOM***", !empty($_SESSION['sessData']['userLoggedIn']));
38 - 91
        }
92
 
10 - 93
        return;
94
    }
95
 
127 - 96
    $xh = new Html;
97
    $xh->init($_SESSION["htmlIndent"]);
13 - 98
 
127 - 99
    $xh->add_attribute("class", "container-fluid bg-light");
100
    $xh->tag('div');
101
    $xh->add_attribute("class", "text-center py-2");
102
    $xh->tag('h2', ($stxt == "***RANDOM***" ? "Random" : "Matching") . " Albums");
134 - 103
    $xh->add_attribute("id", "discogsDeckForm");
127 - 104
    $xh->add_attribute("method", "post");
105
    $xh->add_attribute("action", "/index.php");
106
    $xh->tag('form');
107
    $xh->insert_code(inputSessionTab());
108
    $xh->insert_code(inputNonce());
109
    $xh->add_attribute("id", "discogsTitle");
110
    $xh->add_attribute("type", "hidden");
111
    $xh->add_attribute("name", "discogsTitle");
112
    $xh->add_attribute("value", "");
113
    $xh->single_tag('input');
114
    $xh->add_attribute("id", "discogsArtist");
115
    $xh->add_attribute("type", "hidden");
116
    $xh->add_attribute("name", "discogsArtist");
117
    $xh->add_attribute("value", "");
118
    $xh->single_tag('input');
119
    $xh->add_attribute("id", "discogsBarcode");
120
    $xh->add_attribute("type", "hidden");
121
    $xh->add_attribute("name", "discogsBarcode");
122
    $xh->add_attribute("value", "");
123
    $xh->single_tag('input');
134 - 124
    $xh->add_attribute("type", "hidden");
125
    $xh->add_attribute("name", "submitBtn");
126
    $xh->add_attribute("value", "discogsSearch");
127
    $xh->single_tag('input');
127 - 128
    $xh->add_attribute("id", "discogsDeck");
129
    $xh->add_attribute("class", "card-deck");
130
    $xh->tag('div');
131
 
10 - 132
    $masterCount = 0;
133
    $processedMasters = [];
129 - 134
    $searchUrls = [];
135
    $masterResps_cache = [];
10 - 136
    foreach ($searchResp->{'results'} as $searchey => $searchValue) {
78 - 137
// bugbug foreach ($searchResp->{'releases'} as $searchey => $searchValue) {
137 - 138
        if (!in_array($searchValue->{'type'}, array("master", "release")) && (empty($_SESSION["advSearch"]["Barcode"]))) {
10 - 139
            continue;
140
        }
141
 
137 - 142
        if (empty($_SESSION["advSearch"]["Barcode"]) && $searchValue->{'type'} == "release" && $searchValue->{'master_id'} > 0) {
10 - 143
            continue;
144
        }
57 - 145
 
137 - 146
        if (skipDuplicateMaster($searchValue, $processedMasters)) {
47 - 147
            continue;
148
        }
10 - 149
 
50 - 150
        if (++$masterCount > $maxMasterCount) {
151
            break;
152
        }
153
 
137 - 154
        $processedMasters[] = array( 'id' => $searchValue->{'master_id'}, "title" => $searchValue->{'title'}, "year" => $searchValue->{'year'} ?? 0 );
155
 
99 - 156
        $searchUrl = $searchValue->{'master_id'} != 0 ? $searchValue->{'master_url'} : $searchValue->{'resource_url'};
132 - 157
 
129 - 158
        $searchType[$searchUrl] = $searchValue->{'type'};
159
        $searchThumb[$searchUrl] = $searchValue->{'thumb'};
160
        $searchCoverImage[$searchUrl] = $searchValue->{'cover_image'};
132 - 161
 
129 - 162
        $masterResps_cache[$searchUrl] = getSearchCache("Discogs", $searchUrl, "");
163
        if ($masterResps_cache[$searchUrl] === false) {
164
            $searchUrls[] = $searchUrl;
165
            unset($masterResps_cache[$searchUrl]);
99 - 166
        }
129 - 167
    }
10 - 168
 
129 - 169
    $masterResps = [];
170
    if (count($searchUrls) > 0) {
171
        $masterResps = getMultiUrl($searchUrls, $config['userAgent']);
172
    }
17 - 173
 
129 - 174
    foreach($masterResps as $key => $html) {
175
        saveSearchCache("Discogs", $key, "", $html);
176
    }
10 - 177
 
129 - 178
    foreach($masterResps_cache as $key => $html) {
179
        $masterResps[$key] = $html;
180
    }
181
    unset($masterResps_cache);
182
 
183
    $masterCount = 0;
184
    foreach($masterResps as $key => $html) {
185
        $html = utf8_encode($html);
186
        $html = json_decode($html);
187
 
188
        if (!empty($html->{'message'})) {
189
            my_error_log("Discogs: " . $html->{'message'});
190
        } else if (!empty($html)) {
130 - 191
            $xh->insert_code(processMaster($html, $searchType[$key], $searchThumb[$key], $searchCoverImage[$key], ++$masterCount));
17 - 192
        }
10 - 193
    }
132 - 194
 
81 - 195
    if ($masterCount == 0) {
136 - 196
        $xh->reset();
81 - 197
    } else {
127 - 198
        $xh->close(); // div
199
        $xh->close(); // form
200
        $xh->close(); // div
132 - 201
 
130 - 202
        $xh->insert_code(discogsEvents());
120 - 203
 
127 - 204
        if ($stxt == "***RANDOM***") {
205
            $xh->add_attribute("class", "container-fluid text-center");
206
            $xh->tag('div');
207
              $xh->add_attribute("method", "post");
208
              $xh->add_attribute("action", "/index.php");
209
              $xh->tag('form');
210
                $xh->insert_code(inputSessionTab());
211
                $xh->insert_code(inputSearchTerm());
212
                $xh->insert_code(inputNonce());
213
                $xh->add_attribute("id", "randomBtn");
214
                $xh->add_attribute("type", "submit");
215
                $xh->add_attribute("class", "btn btn-success m-2 rounded");
134 - 216
                $xh->add_attribute("name", "submitBtn");
127 - 217
                $xh->add_attribute("value", "random");
218
                $xh->tag('button', "More Random Album Suggestions");
219
              $xh->close(); // form
220
            $xh->close(); // div
130 - 221
            $xh->add_attribute("nonce", "xxxNONCExxx");
222
            $xh->tag('script');
137 - 223
                $str  = my_trim('document.addEventListener("DOMContentLoaded", function() {');
224
                $str .= my_trim('    document.getElementById("randomBtn").addEventListener("click", function(event) {');
225
                $str .= my_trim('        window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Random Album", "eventAction" : "Click", "eventLabel" : "More"});');
226
                $str .= my_trim('    });');
227
                $str .= my_trim('});');
130 - 228
            $xh->insert_code($str);
229
            $xh->close(); // script
81 - 230
        }
38 - 231
    }
10 - 232
 
127 - 233
    $_SESSION["discogs"] = $xh->flush();
234
    //error_log(print_r($_SESSION["discogs"], 1));
235
 
10 - 236
    return;
237
}
238
 
130 - 239
function discogsEvents() {
127 - 240
    $xh = new Html;
241
    $xh->init($_SESSION["htmlIndent"]);
130 - 242
 
243
    $xh->add_attribute("nonce", "xxxNONCExxx");
244
    $xh->tag('script');
137 - 245
        $str  = my_trim('document.addEventListener("DOMContentLoaded", function() {');
246
        $str .= my_trim('  document.getElementById("discogsDeckForm").addEventListener("submit", function(event) {');
247
        $str .= my_trim('      if (window.google_tag_manager && window.ga && ga.create) {');
248
        $str .= my_trim('          event.preventDefault();');
249
        $str .= my_trim('          var title = document.getElementById("discogsTitle").value;');
250
        $str .= my_trim('          var artist = document.getElementById("discogsArtist").value;');
251
        $str .= my_trim('          window.dataLayer.push({ "event" : "search", "search_term" : title + " by " + (artist.length == 0 ? "Various Artists" : artist), "eventCallback": function () {event.target.submit();}});');
252
        $str .= my_trim('      }');
253
        $str .= my_trim('  });');
254
        $str .= my_trim('  document.getElementById("discogsDeck").addEventListener("click", function(event) {');
255
        $str .= my_trim('       var e = event.target.closest("button") || event.target.closest("a");');
256
        $str .= my_trim('       if (e && e.id.startsWith("discogsSearch")) {');
257
        $str .= my_trim('           document.getElementById("discogsTitle").value = e.getAttribute("data-title");');
258
        $str .= my_trim('           document.getElementById("discogsArtist").value = e.getAttribute("data-artist");');
259
        $str .= my_trim('           document.getElementById("discogsBarcode").value = e.getAttribute("data-barcode");');
260
        $str .= my_trim('           progressBar(e.getAttribute("data-search-title"));');
261
        $str .= my_trim('       } else if (e && e.id.startsWith("wl")) {');
262
        $str .= my_trim('           var user = e.getAttribute("data-user");');
263
        $str .= my_trim('           var cnt = e.getAttribute("data-cnt");');
264
        $str .= my_trim('           var wl = e.getAttribute("data-wl");');
265
        $str .= my_trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Bookmark", "eventAction" : "Add", "eventLabel" : ""});');
266
        $str .= my_trim('           addWishlist(user, e, cnt, wl);');
267
        $str .= my_trim('       } else if (e && e.id.startsWith("discogsInfo")) {');
268
        $str .= my_trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Album Info", "eventAction" : "Click", "eventLabel" : ""});');
269
        $str .= my_trim('       } else if (e && e.id.startsWith("discogsVideo")) {');
270
        $str .= my_trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Video Info", "eventAction" : "Click", "eventLabel" : ""});');
271
        $str .= my_trim('       } else if (e && e.id.startsWith("discogsRedirect")) {');
272
        $str .= my_trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Discogs", "eventAction" : "Click", "eventLabel" : "Detailed Data"});');
273
        $str .= my_trim('       } else if (e && e.id.startsWith("discogsYTRedirect")) {');
274
        $str .= my_trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Video", "eventAction" : "Play", "eventLabel" : "Youtube"});');
275
        $str .= my_trim('       }');
276
        $str .= my_trim('  });');
277
        $str .= my_trim('});');
130 - 278
    $xh->insert_code($str);
279
    $xh->close(); // script
132 - 280
 
130 - 281
    $html = $xh->flush();
282
    //error_log(print_r($html, 1));
283
 
284
    return $html;
285
}
286
 
287
function processMaster($master, $type, $thumbnail, $coverImage, $cnt) {
288
    $xh = new Html;
289
    $xh->init($_SESSION["htmlIndent"]);
127 - 290
    $xhmod = new Html;
291
    $xhmod->init($_SESSION["htmlIndent"]);
292
 
10 - 293
    $artists = [];
294
    foreach ($master->{'artists'} as $key => $value) {
20 - 295
        $artists[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
10 - 296
    }
297
 
298
    $genres = [];
299
    foreach ($master->{'genres'} as $key => $value) {
65 - 300
        $genres[] = (string)$value;
10 - 301
    }
302
 
20 - 303
    $labels = [];
304
    if (isset($master->{'labels'})) {
305
        foreach ($master->{'labels'} as $key => $value) {
306
            $labels[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
307
        }
308
    }
309
 
310
    $formats = [];
311
    if (isset($master->{'formats'})) {
312
        foreach ($master->{'formats'} as $key => $value) {
313
            $formats[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
314
        }
315
    }
38 - 316
 
20 - 317
    $country = '';
318
    if (isset($master->{'country'})) {
319
        $country = (string)$master->{'country'};
320
    }
321
 
127 - 322
    $xh->add_attribute("class", "card mx-auto discogs-card");
323
    $xh->tag('div');
324
 
325
    $xh->add_attribute("class", "card-header bg-secondary d-flex");
326
    $xh->tag('div');
17 - 327
    $searchArtists = "";
20 - 328
    if (count($artists) < 5) {
47 - 329
        $wlArtists = join(", ", $artists);
65 - 330
        if ($artists[0] != 'Various') {
331
            $searchArtists = join(" ", $artists);
332
        }
333
    }
334
    else {
47 - 335
        $wlArtists = "Various Artists";
14 - 336
    }
127 - 337
    $xh->add_attribute("class", "card-title font-weight-bold small flex-grow-1");
338
    $xh->tag('p', htmlentities((string)$master->{'title'}) . " by " . htmlentities($wlArtists));
339
    $xh->close(); // div
132 - 340
 
72 - 341
    if (empty($thumbnail) || preg_match("/spacer.gif$/", $thumbnail)) {
14 - 342
        $thumbnail = "images/no-image-available.jpg";
343
    }
127 - 344
    $xh->add_attribute("class", "card-body d-flex justify-content-center align-items-center p-1 m-0");
345
    $xh->tag('div');
137 - 346
    $xh->add_attribute("class", "btn p-0 m-0 lazyload lazypreload");
347
    $xh->add_attribute("src", $thumbnail);
127 - 348
    $xh->add_attribute("data-toggle", "modal");
349
    $xh->add_attribute("data-target", "#masterModal" . $cnt);
350
    $xh->add_attribute("title", "Album Information");
351
    $xh->add_attribute("data-toggle2", "tooltip");
352
    $xh->add_attribute("alt", "Discogs Cover Thumbnail");
353
    $xh->single_tag('img');
354
    $xh->close(); // div
355
    $xh->add_attribute("class", "card-footer bg-secondary p-0 m-0");
356
    $xh->tag('div');
357
    $xh->add_attribute("class", "container clearfix p-0 m-0");
358
    $xh->tag('div');
359
    $xh->add_attribute("class", "float-left btn-group-sm");
360
    $xh->tag('span');
130 - 361
    $xh->add_attribute("id", "discogsInfo" . $cnt);
127 - 362
    $xh->add_attribute("type", "button");
363
    $xh->add_attribute("class", "btn btn-info btn-sm");
364
    $xh->add_attribute("data-toggle", "modal");
365
    $xh->add_attribute("data-target", "#masterModal" . $cnt);
366
    $xh->add_attribute("title", "Album Information");
367
    $xh->add_attribute("aria-label", "Album Information");
368
    $xh->add_attribute("data-toggle2", "tooltip");
369
    $xh->tag('button');
370
    $xh->add_attribute("class", "material-icons");
371
    $xh->tag('i', "info_outline");
372
    $xh->close(); // button
45 - 373
 
374
    if (isset($master->{'videos'})) {
127 - 375
        $xh->tag('span', " ");
130 - 376
        $xh->add_attribute("id", "discogsVideo" . $cnt);
127 - 377
        $xh->add_attribute("type", "button");
378
        $xh->add_attribute("class", "btn btn-info btn-sm");
379
        $xh->add_attribute("data-toggle", "modal");
380
        $xh->add_attribute("data-target", "#videoModal" . $cnt);
381
        $xh->add_attribute("title", "Videos");
382
        $xh->add_attribute("aria-label", "Music videos");
383
        $xh->add_attribute("data-toggle2", "tooltip");
384
        $xh->tag('button');
385
        $xh->add_attribute("class", "material-icons");
386
        $xh->tag('i', "videocam");
387
        $xh->close(); // button
388
 
389
        $xhmod->add_attribute("id", "videoModal" . $cnt);
390
        $xhmod->add_attribute("class", "modal");
391
        $xhmod->tag('div');
392
        $xhmod->add_attribute("class", "modal-dialog");
393
        $xhmod->tag('div');
394
        $xhmod->add_attribute("class", "modal-content");
395
        $xhmod->tag('div');
396
        $xhmod->add_attribute("class", "modal-header bg-secondary");
397
        $xhmod->tag('div');
57 - 398
        if (count($artists) < 5) {
127 - 399
            $str = htmlentities(join(", ", $artists));
65 - 400
        }
401
        else {
127 - 402
            $str = "Various Artists";
57 - 403
        }
127 - 404
        $xhmod->add_attribute("class", "modal-title mx-auto display-6");
405
        $xhmod->tag('p', htmlentities((string)$master->{'title'}) . " by " . $str);
57 - 406
 
127 - 407
        $xhmod->add_attribute("type", "button");
408
        $xhmod->add_attribute("class", "close");
409
        $xhmod->add_attribute("data-dismiss", "modal");
410
        $xhmod->tag('button');
411
        $xhmod->add_attribute("class", "material-icons btn-dismiss");
412
        $xhmod->tag('i', "cancel_presentation");
413
        $xhmod->close(); // button
414
        $xhmod->close(); // div
57 - 415
 
127 - 416
        $xhmod->add_attribute("class", "modal-body mx-auto");
417
        $xhmod->tag('div');
418
        $xhmod->add_attribute("class", "display-6");
419
        $xhmod->tag('p', "Videos");
420
        $xhmod->add_attribute("class", "list-group");
421
        $xhmod->tag('ul');
422
 
45 - 423
        foreach ($master->{'videos'} as $video) {
127 - 424
            $xhmod->add_attribute("class", "list-group-item");
425
            $xhmod->tag('li');
426
            $xhmod->add_attribute("class", "row");
427
            $xhmod->tag('div');
428
            $xhmod->add_attribute("class", "col-1");
429
            $xhmod->tag('div');
430
            $xhmod->add_attribute("class", "svg-yt");
431
            $xhmod->add_attribute("viewBox", "0 0 24 24");
432
            $xhmod->tag('svg');
433
            $xhmod->add_attribute("fill", "currentColor");
434
            $xhmod->add_attribute("d", "M10,15L15.19,12L10,9V15M21.56,7.17C21.69,7.64 21.78,8.27 21.84,9.07C21.91,9.87 21.94,10.56 21.94,11.16L22,12C22,14.19 21.84,15.8 21.56,16.83C21.31,17.73 20.73,18.31 19.83,18.56C19.36,18.69 18.5,18.78 17.18,18.84C15.88,18.91 14.69,18.94 13.59,18.94L12,19C7.81,19 5.2,18.84 4.17,18.56C3.27,18.31 2.69,17.73 2.44,16.83C2.31,16.36 2.22,15.73 2.16,14.93C2.09,14.13 2.06,13.44 2.06,12.84L2,12C2,9.81 2.16,8.2 2.44,7.17C2.69,6.27 3.27,5.69 4.17,5.44C4.64,5.31 5.5,5.22 6.82,5.16C8.12,5.09 9.31,5.06 10.41,5.06L12,5C16.19,5 18.8,5.16 19.83,5.44C20.73,5.69 21.31,6.27 21.56,7.17Z");
435
            $xhmod->single_tag('path');
436
            $xhmod->close(); // svg
437
            $xhmod->close(); // div
438
            $xhmod->add_attribute("class", "col");
439
            $xhmod->tag('div');
440
            $xhmod->add_attribute("href", $video->uri);
134 - 441
            $xhmod->add_attribute("id", "discogsYTRedirect" . $cnt);
127 - 442
            $xhmod->add_attribute("target", "_blank");
443
            $xhmod->add_attribute("rel", "noreferrer noopener");
444
            $xhmod->add_attribute("class", "btn btn-light btn-link text-left");
445
            $xhmod->add_attribute("role", "button");
446
            $xhmod->tag('a', htmlentities($video->title) . " [" . gmdate('H:i:s', $video->duration) . "]");
447
            $xhmod->close(); // div
448
            $xhmod->close(); // div
449
            $xhmod->close(); // li
57 - 450
            // bugbug too many videos don't run embedded
451
            // $videoParam = basename($video->uri);
452
            // $videoIdx = strpos($videoParam, "=") + 1;
56 - 453
            // $str .= "<iframe width=\"280\" height=\"158\" src=\"https://www.youtube-nocookie.com/embed/" . substr($videoParam, $videoIdx) . "?rel=0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>";
132 - 454
 
45 - 455
        }
57 - 456
 
127 - 457
        $xhmod->close(); // ul
458
        $xhmod->close(); // div
459
        $xhmod->add_attribute("class", "modal-footer bg-secondary justify-content-between");
460
        $xhmod->tag('div');
461
        $xhmod->add_attribute("class", "font-weight-lighter small");
462
        $xhmod->tag('span');
463
        $xhmod->tag('span', "Data provided by ");
464
 
134 - 465
        $xhmod->add_attribute("id", "discogsRedirect2" . $cnt);
127 - 466
        $xhmod->add_attribute("href", (string)$master->{'uri'});
467
        $xhmod->add_attribute("target", "_blank");
468
        $xhmod->add_attribute("rel", "noreferrer noopener");
469
        $xhmod->tag('a', "Discogs");
470
        $xhmod->close(); // span
471
 
472
        $xhmod->add_attribute("class", "float-right");
473
        $xhmod->tag('span');
474
        $xhmod->add_attribute("type", "button");
475
        $xhmod->add_attribute("class", "btn btn-danger");
476
        $xhmod->add_attribute("data-dismiss", "modal");
477
        $xhmod->tag('button', "Close");
478
        $xhmod->close(); // span
479
        $xhmod->close(); // div
480
        $xhmod->close(); // div
481
        $xhmod->close(); // div
482
        $xhmod->close(); // div
45 - 483
    }
484
 
127 - 485
    $xh->close(); // span
62 - 486
 
127 - 487
    $xh->add_attribute("class", "float-right btn-group-sm");
488
    $xh->tag('span');
45 - 489
 
50 - 490
    $barcode = "";
137 - 491
    if (empty($_SESSION["advSearch"]["Barcode"]) && !empty($master->{'identifiers'})) {
50 - 492
        foreach ($master->{'identifiers'} as $identifier) {
493
            if ($identifier->{'type'} == 'Barcode') {
494
                $tmpBarcode = preg_replace("/[^0-9]/", "", $identifier->{'value'});
495
                $barcodeType = clsLibGTIN::GTINCheck($tmpBarcode, false, 1);
496
                if (!empty($barcodeType)) {
65 - 497
                    $barcode = $tmpBarcode;
50 - 498
                }
499
            }
500
        }
65 - 501
    }
137 - 502
    else if (!empty($_SESSION["advSearch"]["Barcode"])) {
503
        $barcode = $_SESSION["advSearch"]["Barcode"];
50 - 504
    }
505
 
46 - 506
    if (isLoggedIn() && !checkWishlist($type, $master->{'id'})) {
65 - 507
        $wlArr = array(
508
            ($type == "master" ? 'mid' : 'rid') => $master->{'id'},
509
            'title' => (string)$master->{'title'},
510
            'artist' => $wlArtists,
511
            'barcode' => $barcode,
512
            'thumbnail' => $thumbnail,
513
            'url' => (string)$master->{'uri'}
514
        );
46 - 515
        $wl = base64_encode(json_encode($wlArr));
127 - 516
 
517
        $xh->add_attribute("id", "wl" . $cnt . "Btn");
518
        $xh->add_attribute("type", "button");
519
        $xh->add_attribute("class", "btn btn-info btn-sm");
520
        $xh->add_attribute("title", "Add to Wishlist");
521
        $xh->add_attribute("aria-label", "Add to Wishlist");
522
        $xh->add_attribute("data-toggle", "tooltip");
130 - 523
        $xh->add_attribute("data-user", $_SESSION['sessData']['userID']);
524
        $xh->add_attribute("data-cnt", $cnt);
525
        $xh->add_attribute("data-wl", $wl);
127 - 526
        $xh->tag('button');
527
        $xh->add_attribute("class", "material-icons");
528
        $xh->tag('i', "bookmark");
529
        $xh->close(); // button
45 - 530
    }
531
 
125 - 532
    $searchTitle = 'Searching for:<br><br><strong>' . htmlentities((string)$master->{'title'}) . ' by ' . (empty($searchArtists) ? 'Various Artists' : htmlentities($searchArtists)) . '</strong>';
50 - 533
    if (!empty($barcode)) {
534
        $searchTitle .= " (" . displayBarcode($barcode) . ")";
535
    }
536
 
127 - 537
    $xh->tag('span', " ");
538
    $xh->add_attribute("id", "discogsSearch" . $cnt . "Btn");
539
    $xh->add_attribute("type", "submit");
134 - 540
    $xh->add_attribute("name", "submitBtn");
127 - 541
    $xh->add_attribute("value", "discogsSearch");
542
    $xh->add_attribute("class", "btn btn-success btn-sm");
543
    $xh->add_attribute("title", "Search for Store Offers");
544
    $xh->add_attribute("aria-label", "Search for Store Offers");
545
    $xh->add_attribute("data-toggle", "tooltip");
130 - 546
    $xh->add_attribute("data-title", htmlentities((string)$master->{"title"}));
547
    $xh->add_attribute("data-artist", htmlentities($searchArtists));
548
    $xh->add_attribute("data-barcode", $barcode);
549
    $xh->add_attribute("data-search-title", $searchTitle);
127 - 550
    $xh->tag('button');
551
    $xh->add_attribute("class", "material-icons");
552
    $xh->tag('i', "search");
553
    $xh->close(); // button
554
    $xh->close(); // span
555
    $xh->close(); // div
132 - 556
 
127 - 557
    $xh->add_attribute("id", "wishlistAdd" . $cnt);
558
    $xh->tag('span', "");
559
    $xh->close(); // div
14 - 560
 
127 - 561
    $xhmod->add_attribute("id", "masterModal" . $cnt);
562
    $xhmod->add_attribute("class", "modal");
563
    $xhmod->tag('div');
564
    $xhmod->add_attribute("class", "modal-dialog");
565
    $xhmod->tag('div');
566
    $xhmod->add_attribute("class", "modal-content");
567
    $xhmod->tag('div');
568
    $xhmod->add_attribute("class", "modal-header bg-secondary");
569
    $xhmod->tag('div');
20 - 570
    if (count($artists) < 5) {
127 - 571
        $str = htmlentities(join(", ", $artists));
65 - 572
    }
573
    else {
127 - 574
        $str = "Various Artists";
14 - 575
    }
127 - 576
    $xhmod->add_attribute("class", "modal-title mx-auto display-6");
577
    $xhmod->tag('p', htmlentities((string)$master->{'title'}) . " by " . $str);
578
    $xhmod->add_attribute("type", "button");
579
    $xhmod->add_attribute("class", "close");
580
    $xhmod->add_attribute("data-dismiss", "modal");
581
    $xhmod->tag('button');
582
    $xhmod->add_attribute("class", "material-icons btn-dismiss");
583
    $xhmod->tag('i', "cancel_presentation");
584
    $xhmod->close(); // button
585
    $xhmod->close(); // div
14 - 586
 
127 - 587
    $xhmod->add_attribute("class", "modal-body mx-auto");
588
    $xhmod->tag('div');
14 - 589
 
72 - 590
    if (!empty($coverImage) && !preg_match("/spacer.gif$/", $coverImage)) {
127 - 591
        $xhmod->add_attribute("class", "responsive-image mx-auto mb-4 lazyload");
592
        $xhmod->add_attribute("src", $coverImage);
593
        $xhmod->add_attribute("alt", "Discogs Cover");
594
        $xhmod->single_tag('img');
43 - 595
    }
596
 
127 - 597
    $xhmod->add_attribute("class", "table-borderless table-condensed small mx-auto");
598
    $xhmod->tag('table');
14 - 599
 
127 - 600
    $xhmod->tag('tr');
601
    $xhmod->add_attribute("class", "px-1");
602
    $xhmod->tag('td', "Title:");
603
    $xhmod->add_attribute("class", "px-1");
604
    $xhmod->tag('td', htmlentities((string)$master->{'title'}));
605
    $xhmod->close(); // tr
14 - 606
 
127 - 607
    $xhmod->tag('tr');
608
    $xhmod->add_attribute("class", "px-1");
609
    $xhmod->tag('td', "Artist:");
610
    $xhmod->add_attribute("class", "px-1");
611
    $xhmod->tag('td', htmlentities(join(", ", $artists)));
612
    $xhmod->close(); // tr
613
 
50 - 614
    if (!empty($barcode)) {
127 - 615
        $xhmod->tag('tr');
616
        $xhmod->add_attribute("class", "px-1");
617
        $xhmod->tag('td', "Barcode:");
618
        $xhmod->add_attribute("class", "px-1");
619
        $xhmod->tag('td', displayBarcode($barcode));
620
        $xhmod->close(); // tr
50 - 621
    }
622
 
20 - 623
    if (!empty($labels)) {
127 - 624
        $xhmod->tag('tr');
625
        $xhmod->add_attribute("class", "px-1");
626
        $xhmod->tag('td', "Label:");
627
        $xhmod->add_attribute("class", "px-1");
628
        $xhmod->tag('td', htmlentities($labels[0]));
629
        $xhmod->close(); // tr
20 - 630
    }
631
 
632
    if (!empty($formats)) {
127 - 633
        $xhmod->tag('tr');
634
        $xhmod->add_attribute("class", "px-1");
635
        $xhmod->tag('td', "Format:");
636
        $xhmod->add_attribute("class", "px-1");
637
        $xhmod->tag('td', htmlentities(join(", ", $formats)));
638
        $xhmod->close(); // tr
20 - 639
    }
640
 
641
    if (!empty($country)) {
127 - 642
        $xhmod->tag('tr');
643
        $xhmod->add_attribute("class", "px-1");
644
        $xhmod->tag('td', "Country:");
645
        $xhmod->add_attribute("class", "px-1");
646
        $xhmod->tag('td', htmlentities($country));
647
        $xhmod->close(); // tr
20 - 648
    }
649
 
14 - 650
    if ($master->{'year'} > 0) {
127 - 651
        $xhmod->tag('tr');
652
        $xhmod->add_attribute("class", "px-1");
653
        $xhmod->tag('td', "Year:");
654
        $xhmod->add_attribute("class", "px-1");
655
        $xhmod->tag('td', htmlentities((string)$master->{'year'}));
656
        $xhmod->close(); // tr
14 - 657
    }
658
 
127 - 659
    $xhmod->tag('tr');
660
    $xhmod->add_attribute("class", "px-1");
661
    $xhmod->tag('td', "Genre:");
662
    $xhmod->add_attribute("class", "px-1");
663
    $xhmod->tag('td', htmlentities(join(", ", $genres)));
664
    $xhmod->close(); // tr
14 - 665
 
10 - 666
    if (isset($master->{'styles'})) {
667
        $styles = [];
668
        foreach ($master->{'styles'} as $key => $value) {
669
            $styles[] = $value;
670
        }
127 - 671
        $xhmod->tag('tr');
672
        $xhmod->add_attribute("class", "px-1");
673
        $xhmod->tag('td', "Style:");
674
        $xhmod->add_attribute("class", "px-1");
675
        $xhmod->tag('td', htmlentities(join(", ", $styles)));
676
        $xhmod->close(); // tr
10 - 677
    }
14 - 678
 
679
    if (is_array($master->{'tracklist'})) {
127 - 680
        $xhmod->tag('tr');
681
        $xhmod->add_attribute("class", "px-1");
682
        $xhmod->add_attribute("colspan", "2");
683
        $xhmod->tag('td', "Tracks:");
684
        $xhmod->close(); // tr
685
 
686
        $xhmod->tag('tr');
687
        $xhmod->add_attribute("class", "px-1");
688
        $xhmod->add_attribute("colspan", "2");
689
        $xhmod->tag('td');
690
        $xhmod->add_attribute("class", "pl-3 pt-0 small list-unstyled");
691
        $xhmod->tag('ul');
14 - 692
        foreach ($master->{'tracklist'} as $key => $value) {
20 - 693
            if ((string)$value->{'type_'} == "heading") {
127 - 694
                $xhmod->add_attribute("class", "font-weight-bold");
695
                $xhmod->tag('li', htmlentities((string)$value->{'title'}));
65 - 696
            }
697
            else if ((string)$value->{'type_'} == "index") {
127 - 698
                $xhmod->add_attribute("class", "font-italic");
699
                $xhmod->tag('li');
700
                $xhmod->add_attribute("class", "font-italic");
701
                $xhmod->tag('span', htmlentities((string)$value->{'title'}));
14 - 702
                foreach ($value->{'sub_tracks'} as $subkey => $subvalue) {
127 - 703
                    $xhmod->add_attribute("class", "pl-3 pt-0 list-unstyled");
704
                    $xhmod->tag('ul');
705
                    $xhmod->insert_code(processTrack($subvalue, false));
706
                    $xhmod->close(); // ul
17 - 707
                }
127 - 708
                $xhmod->close(); // li
65 - 709
            }
710
            else if ((string)$value->{'type_'} == "track") {
127 - 711
                $xhmod->insert_code(processTrack($value, true));
14 - 712
            }
713
        }
127 - 714
        $xhmod->close(); // ul
715
        $xhmod->close(); // td
716
        $xhmod->close(); // tr
17 - 717
    }
14 - 718
 
127 - 719
    $xhmod->close(); // table
720
    $xhmod->close(); // div
721
    $xhmod->add_attribute("class", "modal-footer bg-secondary justify-content-between");
722
    $xhmod->tag('div');
723
    $xhmod->tag('span');
724
    $xhmod->tag('span', "Data provided by ");
134 - 725
    $xhmod->add_attribute("id", "discogsRedirect" . $cnt);
127 - 726
    $xhmod->add_attribute("href", (string)$master->{'uri'});
727
    $xhmod->add_attribute("target", "_blank");
728
    $xhmod->add_attribute("rel", "noreferrer noopener");
729
    $xhmod->tag('a', "Discogs");
730
    $xhmod->close(); // span
731
    $xhmod->add_attribute("class", "float-right");
732
    $xhmod->tag('span');
733
    $xhmod->add_attribute("type", "button");
734
    $xhmod->add_attribute("class", "btn btn-danger");
735
    $xhmod->add_attribute("data-dismiss", "modal");
736
    $xhmod->tag('button', "Close");
737
    $xhmod->close(); // span
738
    $xhmod->close(); // div
739
    $xhmod->close(); // div
740
    $xhmod->close(); // div
741
    $xhmod->close(); // div
10 - 742
 
127 - 743
    $html = $xhmod->flush();
744
    //error_log(print_r($html, 1));
745
 
746
    $xh->insert_code($html);
747
    $xh->close(); // div
748
 
749
    $html = $xh->flush();
750
    //error_log(print_r($html, 1));
751
 
752
    return $html;
14 - 753
}
10 - 754
 
14 - 755
function processTrack($value, $posFlag) {
127 - 756
    $xh = new Html;
757
    $xh->init($_SESSION["htmlIndent"]);
758
 
759
    $str = "";
760
 
14 - 761
    if ($posFlag && !empty($value->{'position'})) {
20 - 762
        if (!preg_match("/^[a-zA-Z][0-9]/", (string)$value->{'position'}) && !preg_match("/^[a-zA-Z]$/", (string)$value->{'position'})) {
763
            $str .= (string)$value->{'position'} . '. ';
10 - 764
        }
14 - 765
    }
17 - 766
 
20 - 767
    $str .= (string)$value->{'title'};
10 - 768
 
14 - 769
    $trackArtists = [];
770
    if (isset($value->{'artists'})) {
771
        foreach ($value->{'artists'} as $taKey => $taValue) {
20 - 772
            $trackArtists[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$taValue->{'name'}));
10 - 773
        }
14 - 774
        if (count($trackArtists)) {
775
            $str .= " - " . join(", ", $trackArtists);
776
        }
777
    }
10 - 778
 
14 - 779
    if (!empty($value->{'duration'})) {
20 - 780
        $str .= " [" . (string)$value->{'duration'} . "]";
10 - 781
    }
13 - 782
 
127 - 783
    $xh->tag('li', $str);
14 - 784
 
127 - 785
    $html = $xh->flush();
786
    //error_log(print_r($html, 1));
787
 
788
    return $html;
14 - 789
}
137 - 790
 
791
function skipDuplicateMaster($master, $processedMasters) {
792
    if ($master->{'master_id'} > 0 && in_array($master->{'master_id'}, array_column($processedMasters, "id"))) {
793
        return true;
794
    }
795
 
796
    foreach ($processedMasters as $v) {
797
        $s1 = strtolower($master->{'title'});
798
        $s2 = strtolower($v['title']);
799
        $sim = similar_text($s1, $s2, $perc);
800
        if ($perc > 85.00 && $master->{'year'} == $v["year"]) {
801
//error_log($master->{'title'} . " === " . $v['title']);
802
//error_log("similarity: $sim (" . number_format($perc, 2) . "%)");
803
            return true;
804
        }
805
    }
806
 
807
    return false;
808
}