release.php 8.3 KB

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