release.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. require_once "../config/config.php";
  3. require_once "../utilities/dom.php";
  4. require_once "../modules/querypath/src/qp.php";
  5. $ch = curl_init("https://" . urlencode($_GET["artist"]) . ".bandcamp.com/" . urlencode($_GET["type"]) . "/" . urlencode($_GET["name"]));
  6. if (isset($config["identity"]))
  7. curl_setopt($ch, CURLOPT_COOKIE, "identity=" . $config["identity"]);
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  9. $document = htmlqp(encode_document(curl_exec($ch)));
  10. $json = json_decode($document->find("script[data-tralbum]")->attr("data-tralbum"));
  11. $additional = json_decode($document->find("script[type=\"application/ld+json\"]")->text());
  12. $recommendations = $document->find("li.recommended-album");
  13. $title = $json->current->title;
  14. ?>
  15. <?php require_once "../elements/header.php" ?>
  16. <?php require_once "../elements/sidebar.php" ?>
  17. <?php require_once "../elements/item.php" ?>
  18. <?php require_once "../utilities/link.php" ?>
  19. <?php
  20. if ($json) {
  21. echo "<h1>";
  22. echo "<a href=\"" . convert_link("https://" . urlencode($_GET["artist"]) . ".bandcamp.com") . "\">" . htmlspecialchars($json->artist) . "</a>: ";
  23. echo htmlspecialchars($json->current->title);
  24. echo "</h1>";
  25. echo "<div class=\"subpage\">";
  26. $image = "https://f4.bcbits.com/img/" . $json->art_id . "_4.jpg";
  27. $about = $json->current->about;
  28. $description = $additional->inAlbum->albumRelease[0]->additionalProperty;
  29. if ($description) $description = current(array_filter($description, fn($property) => $property->name === 'digital_release_description'));
  30. if ($description) $description = $description->value;
  31. $text = $about ?? $description;
  32. echo_sidebar($image, $text);
  33. echo "<div class=\"tracks\">";
  34. echo "<table>";
  35. foreach ($json->trackinfo as $track) {
  36. $link = $track->title_link;
  37. if ($link) {
  38. $link = prefix_link($link, "artist");
  39. $link = convert_link($link);
  40. };
  41. $duration = round($track->duration);
  42. if ($duration)
  43. $duration = floor($duration / 60) . ":" . sprintf("%02d", $duration % 60);
  44. else
  45. $duration = null;
  46. echo "<tr>";
  47. echo "<td>" . ($track->track_num ?? 1) . ".</td>";
  48. echo "<td>";
  49. if ($link) echo "<a href=\"" . $link . "\">";
  50. echo $track->title;
  51. if ($link) echo "</a>";
  52. echo "</td>";
  53. echo "<td>" . $duration . "</td>";
  54. echo "</tr>";
  55. if ($track->file) {
  56. $file = $track->file;
  57. $file = get_mangled_object_vars($file);
  58. $file = end($file);
  59. echo "<tr>";
  60. echo "<td></td>";
  61. echo "<td colspan=\"2\">";
  62. echo "<audio src=\"" . convert_link($file) . "\" controls preload=\"none\"></audio>";
  63. echo "</td>";
  64. echo "</tr>";
  65. };
  66. };
  67. echo "</table>";
  68. $lyrics = $json->current->lyrics;
  69. if ($lyrics) echo "<p>" . nl2br($json->current->lyrics) . "</p>";
  70. echo "<p><b>Recommendations:</b></p>";
  71. echo "<div class=\"recommendations\">";
  72. foreach ($recommendations as $ra){
  73. $image = convert_link(resize_link($ra->find("img.album-art")->attr("src"), 3));
  74. echo_item(convert_link($ra->find("a.album-link")->attr("href")), $image, "<br>" . $ra->attr("data-albumtitle"), "by " . $ra->attr("data-artist"));
  75. }
  76. echo "</div>";
  77. echo "</div>";
  78. $image = $document->find(".bio-pic a")->attr("href");
  79. $image = resize_link($image, 4);
  80. if (isset($additional->publisher->description))
  81. $text = $additional->publisher->description;
  82. else
  83. $text = null;
  84. $links = $document->find("#band-links li a");
  85. echo_sidebar($image, $text, $links);
  86. echo "</div>";
  87. } else {
  88. echo "<span>No results.</span>";
  89. };
  90. ?>
  91. <?php require_once "../elements/footer.php" ?>