release.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. $title = $json->current->title;
  13. ?>
  14. <?php require_once "../elements/header.php" ?>
  15. <?php require_once "../elements/sidebar.php" ?>
  16. <?php require_once "../utilities/link.php" ?>
  17. <?php
  18. if ($json) {
  19. echo "<h1>";
  20. echo "<a href=\"" . convert_link("https://" . urlencode($_GET["artist"]) . ".bandcamp.com") . "\">" . htmlspecialchars($json->artist) . "</a>: ";
  21. echo htmlspecialchars($json->current->title);
  22. echo "</h1>";
  23. echo "<div class=\"subpage\">";
  24. $image = "https://f4.bcbits.com/img/" . $json->art_id . "_4.jpg";
  25. $about = $json->current->about;
  26. $description = $additional->inAlbum->albumRelease[0]->additionalProperty;
  27. if ($description) $description = current(array_filter($description, fn($property) => $property->name === 'digital_release_description'));
  28. if ($description) $description = $description->value;
  29. $text = $about ?? $description;
  30. echo_sidebar($image, $text);
  31. echo "<div class=\"tracks\">";
  32. echo "<table>";
  33. foreach ($json->trackinfo as $track) {
  34. $link = $track->title_link;
  35. if ($link) {
  36. $link = prefix_link($link, "artist");
  37. $link = convert_link($link);
  38. };
  39. $duration = round($track->duration);
  40. if ($duration)
  41. $duration = floor($duration / 60) . ":" . sprintf("%02d", $duration % 60);
  42. else
  43. $duration = null;
  44. echo "<tr>";
  45. echo "<td>" . ($track->track_num ?? 1) . ".</td>";
  46. echo "<td>";
  47. if ($link) echo "<a href=\"" . $link . "\">";
  48. echo $track->title;
  49. if ($link) echo "</a>";
  50. echo "</td>";
  51. echo "<td>" . $duration . "</td>";
  52. echo "</tr>";
  53. if ($track->file) {
  54. $file = $track->file;
  55. $file = get_mangled_object_vars($file);
  56. $file = end($file);
  57. echo "<tr>";
  58. echo "<td></td>";
  59. echo "<td colspan=\"2\">";
  60. echo "<audio src=\"" . convert_link($file) . "\" controls preload=\"none\"></audio>";
  61. echo "</td>";
  62. echo "</tr>";
  63. };
  64. };
  65. echo "</table>";
  66. $lyrics = $json->current->lyrics;
  67. if ($lyrics) echo "<p>" . nl2br($json->current->lyrics) . "</p>";
  68. echo "</div>";
  69. $image = $document->find(".bio-pic a")->attr("href");
  70. $image = resize_link($image, 4);
  71. if (isset($additional->publisher->description))
  72. $text = $additional->publisher->description;
  73. else
  74. $text = null;
  75. $links = $document->find("#band-links li a");
  76. echo_sidebar($image, $text, $links);
  77. echo "</div>";
  78. } else {
  79. echo "<span>No results.</span>";
  80. };
  81. ?>
  82. <?php require_once "../elements/footer.php" ?>