Subversion Repositories cheapmusic

Rev

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