release.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 . "_10.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. $link = prefix_link($link, "artist");
  36. $link = convert_link($link);
  37. $duration = round($track->duration);
  38. $duration = floor($duration / 60) . ":" . sprintf("%02d", $duration % 60);
  39. echo "<tr>";
  40. echo "<td>" . ($track->track_num ?? 1) . ".</td>";
  41. echo "<td><a href=\"" . $link . "\">" . $track->title . "</a></td>";
  42. echo "<td>" . $duration . "</td>";
  43. echo "</tr>";
  44. if ($track->file) {
  45. $file = $track->file;
  46. $file = get_mangled_object_vars($file);
  47. $file = end($file);
  48. echo "<tr>";
  49. echo "<td></td>";
  50. echo "<td colspan=\"2\">";
  51. echo "<audio src=\"" . convert_link($file) . "\" controls preload=\"none\"></audio>";
  52. echo "</td>";
  53. echo "</tr>";
  54. };
  55. };
  56. echo "</table>";
  57. $lyrics = $json->current->lyrics;
  58. if ($lyrics) echo "<p>" . nl2br($json->current->lyrics) . "</p>";
  59. echo "</div>";
  60. $image = $document->find(".bio-pic a")->attr("href");
  61. if (isset($additional->publisher->description))
  62. $text = $additional->publisher->description;
  63. else
  64. $text = null;
  65. $links = $document->find("#band-links li a");
  66. echo_sidebar($image, $text, $links);
  67. echo "</div>";
  68. } else {
  69. echo "<span>No results.</span>";
  70. };
  71. ?>
  72. <?php require_once "../elements/footer.php" ?>