1
0

release.php 4.0 KB

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