release.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php require_once "../utilities/index.php" ?>
  2. <?php
  3. require_once "../config/config.php";
  4. if (isset($_GET["host"]) && $_GET["host"])
  5. $host = urlencode($_GET["artist"]);
  6. else
  7. $host = urlencode($_GET["artist"]) . ".bandcamp.com";
  8. $ch = curl_init("https://" . $host . "/" . urlencode($_GET["type"]) . "/" . urlencode($_GET["name"]));
  9. if (isset($config["identity"]))
  10. curl_setopt($ch, CURLOPT_COOKIE, "identity=" . $config["identity"]);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  12. $document = new DOMXPath(encode_document(curl_exec($ch)));
  13. $json = json_decode($document->evaluate("//script[@data-tralbum]")->item(0)->getAttribute("data-tralbum"));
  14. $additional = json_decode($document->evaluate("//script[@type=\"application/ld+json\"]")->item(0)->textContent);
  15. if ($json)
  16. $title = $json->current->title;
  17. ?>
  18. <?php require_once "../elements/header.php" ?>
  19. <?php require_once "../elements/sidebar.php" ?>
  20. <?php require_once "../elements/item.php" ?>
  21. <?php
  22. echo_design_style($document);
  23. if ($json) {
  24. echo "<h1>";
  25. echo htmlspecialchars($json->current->title) . " ";
  26. $album = $document->evaluate("//span[@class=\"fromAlbum\"]")->item(0);
  27. if ($album) {
  28. echo "from <a href=\"" . convert_bandcamp_link(prefix_link("/" . $album->parentElement->getAttribute("href"), "artist")) . "\">";
  29. echo htmlspecialchars($album->textContent);
  30. echo "</a> ";
  31. };
  32. echo "by <a href=\"" . convert_bandcamp_link(prefix_link("/", "artist")) . "\">" . htmlspecialchars($json->artist) . "</a>";
  33. echo "</h1>";
  34. echo "<div class=\"subpage\">";
  35. $image = "https://f4.bcbits.com/img/" . $json->art_id . "_4.jpg";
  36. $about = $json->current->about;
  37. if (property_exists($additional, "inAlbum")) {
  38. $description = $additional->inAlbum->albumRelease[0]->additionalProperty;
  39. if ($description) $description = current(array_filter($description, fn($property) => $property->name === 'digital_release_description'));
  40. if ($description) $description = $description->value;
  41. };
  42. $text = $about ?? $description ?? null;
  43. echo_sidebar($image, $text);
  44. echo "<div class=\"tracks\">";
  45. if (count($json->trackinfo)) {
  46. echo "<details" . (isset($_COOKIE["details"]) && !in_array("tracklist", json_decode($_COOKIE["details"])) ? "" : " open") . ">";
  47. echo "<summary>Tracklist</summary>";
  48. echo "<table>";
  49. foreach ($json->trackinfo as $track) {
  50. $link = $track->title_link;
  51. if ($link) {
  52. $link = prefix_link($link, "artist");
  53. $link = convert_bandcamp_link($link);
  54. };
  55. $duration = round($track->duration);
  56. if ($duration)
  57. $duration = floor($duration / 60) . ":" . sprintf("%02d", $duration % 60);
  58. else
  59. $duration = null;
  60. echo "<tr>";
  61. echo "<td>" . ($track->track_num ?? 1) . ".</td>";
  62. echo "<td>";
  63. if ($link) echo "<a href=\"" . $link . "\">";
  64. echo htmlspecialchars($track->title);
  65. if ($link) echo "</a>";
  66. echo "</td>";
  67. echo "<td>" . $duration . "</td>";
  68. echo "</tr>";
  69. if ($track->file) {
  70. $file = $track->file;
  71. $file = get_mangled_object_vars($file);
  72. $file = end($file);
  73. echo "<tr>";
  74. echo "<td></td>";
  75. echo "<td colspan=\"2\">";
  76. echo "<audio src=\"" . convert_bandcamp_link($file) . "\" controls preload=\"none\"></audio>";
  77. echo "</td>";
  78. echo "</tr>";
  79. };
  80. };
  81. echo "</table>";
  82. echo "</details>";
  83. };
  84. $videos = array_filter($json->trackinfo, fn($track) => $track->video_mobile_url);
  85. if ($videos) {
  86. echo "<details" . (isset($_COOKIE["details"]) && in_array("videos", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  87. echo "<summary>Videos</summary>";
  88. foreach ($videos as $video) {
  89. $src = convert_bandcamp_link("https://bandcamp.23video.com" . $video->video_mobile_url);
  90. $poster = convert_bandcamp_link("https://bandcamp.23video.com/" . $video->video_poster_url);
  91. echo "<video src=\"" . $src . "\" poster=\"" . $poster . "\" controls preload=\"none\"></video>";
  92. };
  93. echo "</details>";
  94. };
  95. if (property_exists($json->current, "lyrics"))
  96. $lyrics = $json->current->lyrics;
  97. if (isset($lyrics)) {
  98. echo "<details" . (isset($_COOKIE["details"]) && in_array("lyrics", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  99. echo "<summary>Lyrics</summary>";
  100. echo "<p>" . nl2br(htmlspecialchars($lyrics)) . "</p>";
  101. echo "</details>";
  102. };
  103. echo "<details" . (isset($_COOKIE["details"]) && in_array("credits", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  104. echo "<summary>Credits</summary>";
  105. $credits = $document->evaluate("//div[contains(@class, \"tralbum-credits\")]")->item(0);
  106. $from = $document->evaluate("./a[@href]", $credits)->item(0);
  107. if ($from)
  108. $from->removeAttribute("href");
  109. echo $document->document->saveHTML($credits);
  110. echo "</details>";
  111. if (property_exists($additional, "copyrightNotice")) {
  112. echo "<details" . (isset($_COOKIE["details"]) && in_array("license", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  113. echo "<summary>License</summary>";
  114. if ($additional->copyrightNotice === "All Rights Reserved") {
  115. echo "All rights reserved.";
  116. } elseif ($additional->copyrightNotice === "Various") {
  117. echo "License varies by track. See the invidual track pages for details.";
  118. } else {
  119. $license = str_replace(
  120. ["Attribution", "No-Derivatives", "Non-Commercial", "Share-Alike"],
  121. ["BY", "ND", "NC", "SA"],
  122. str_replace(" ", "-", $additional->copyrightNotice)
  123. );
  124. echo "CC " . $license . " 3.0. ";
  125. echo "<a href=\"https://creativecommons.org/licenses/" . strtolower($license) . "/3.0/\">";
  126. echo "See the Creative Commons website for details.";
  127. echo "</a>";
  128. };
  129. echo "</details>";
  130. };
  131. $tags = $additional->keywords;
  132. echo "<details" . (isset($_COOKIE["details"]) && in_array("tags", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  133. echo "<summary>Tags</summary>";
  134. echo "<ul>";
  135. foreach ($tags as $tag) {
  136. echo "<li>";
  137. echo "<a href=\"" . convert_bandcamp_link("https://bandcamp.com/discover/" . strtolower(htmlspecialchars(str_replace(" ", "-", $tag)))) . "\">";
  138. echo htmlspecialchars($tag);
  139. echo "</a>";
  140. echo "</li>";
  141. };
  142. echo "</ul>";
  143. echo "</details>";
  144. $recommendations = $document->evaluate("//li[contains(@class, \"recommended-album\")]");
  145. if ($recommendations->count()) {
  146. echo "<details" . (isset($_COOKIE["details"]) && in_array("recommendations", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  147. echo "<summary>Recommendations</summary>";
  148. echo "<div class=\"results\">";
  149. foreach ($recommendations as $recommendation) {
  150. $link = convert_bandcamp_link($document->evaluate(".//a[@class=\"album-link\"]", $recommendation)->item(0)->getAttribute("href"));
  151. $image = convert_bandcamp_link(resize_link($document->evaluate(".//img", $recommendation)->item(0)->getAttribute("src"), 3));
  152. $text = $recommendation->getAttribute("data-albumtitle");
  153. $description = "by " . $recommendation->getAttribute("data-artist");
  154. echo_item($link, $image, $text, $description);
  155. };
  156. echo "</div>";
  157. echo "</details>";
  158. };
  159. echo "</div>";
  160. if (isset($additional->publisher->image)) {
  161. $image = $additional->publisher->image;
  162. $image = resize_link($image, 4);
  163. } else
  164. $image = null;
  165. if (isset($additional->publisher->description))
  166. $text = $additional->publisher->description;
  167. else
  168. $text = null;
  169. $links = $document->evaluate("//ol[@id=\"band-links\"]//a");
  170. echo_sidebar($image, $text, $links);
  171. echo "</div>";
  172. } else {
  173. echo_error_message();
  174. };
  175. ?>
  176. <?php require_once "../elements/footer.php" ?>