release.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. echo "<video src=\"" . $src . "\" poster=\"" . $poster . "\" controls preload=\"none\"></video>";
  95. };
  96. echo "</details>";
  97. };
  98. if (property_exists($json->current, "lyrics"))
  99. $lyrics = $json->current->lyrics;
  100. if (isset($lyrics)) {
  101. echo "<details" . (isset($_COOKIE["details"]) && in_array("lyrics", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  102. echo "<summary>Lyrics</summary>";
  103. echo "<p>" . nl2br(htmlspecialchars($lyrics)) . "</p>";
  104. echo "</details>";
  105. };
  106. echo "<details" . (isset($_COOKIE["details"]) && in_array("credits", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  107. echo "<summary>Credits</summary>";
  108. $credits = $document->evaluate("//div[contains(@class, \"tralbum-credits\")]")->item(0);
  109. $from = $document->evaluate("./a[@href]", $credits)->item(0);
  110. if ($from)
  111. $from->removeAttribute("href");
  112. echo $document->document->saveHTML($credits);
  113. echo "</details>";
  114. if (property_exists($additional, "copyrightNotice")) {
  115. echo "<details" . (isset($_COOKIE["details"]) && in_array("license", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  116. echo "<summary>License</summary>";
  117. if ($additional->copyrightNotice === "All Rights Reserved") {
  118. echo "All rights reserved.";
  119. } elseif ($additional->copyrightNotice === "Various") {
  120. echo "License varies by track. See the invidual track pages for details.";
  121. } else {
  122. $license = str_replace(
  123. ["Attribution", "No-Derivatives", "Non-Commercial", "Share-Alike"],
  124. ["BY", "ND", "NC", "SA"],
  125. str_replace(" ", "-", $additional->copyrightNotice)
  126. );
  127. echo "CC " . $license . " 3.0. ";
  128. echo "<a href=\"https://creativecommons.org/licenses/" . strtolower($license) . "/3.0/\">";
  129. echo "See the Creative Commons website for details.";
  130. echo "</a>";
  131. };
  132. echo "</details>";
  133. };
  134. $tags = $additional->keywords;
  135. echo "<details" . (isset($_COOKIE["details"]) && in_array("tags", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  136. echo "<summary>Tags</summary>";
  137. echo "<ul>";
  138. foreach ($tags as $tag) {
  139. echo "<li>";
  140. echo "<a href=\"" . convert_bandcamp_link("https://bandcamp.com/discover/" . strtolower(htmlspecialchars(str_replace(" ", "-", $tag)))) . "\">";
  141. echo htmlspecialchars($tag);
  142. echo "</a>";
  143. echo "</li>";
  144. };
  145. echo "</ul>";
  146. echo "</details>";
  147. $recommendations = $document->evaluate("//li[contains(@class, \"recommended-album\")]");
  148. if ($recommendations->count()) {
  149. echo "<details" . (isset($_COOKIE["details"]) && in_array("recommendations", json_decode($_COOKIE["details"])) ? " open" : "") . ">";
  150. echo "<summary>Recommendations</summary>";
  151. echo "<div class=\"results\">";
  152. foreach ($recommendations as $recommendation) {
  153. $link = convert_bandcamp_link($document->evaluate(".//a[@class=\"album-link\"]", $recommendation)->item(0)->getAttribute("href"));
  154. $image = convert_bandcamp_link(resize_link($document->evaluate(".//img", $recommendation)->item(0)->getAttribute("src"), 3));
  155. $text = $recommendation->getAttribute("data-albumtitle");
  156. $description = "by " . $recommendation->getAttribute("data-artist");
  157. echo_item($link, $image, $text, $description);
  158. };
  159. echo "</div>";
  160. echo "</details>";
  161. };
  162. echo "</div>";
  163. if (isset($additional->publisher->image)) {
  164. $image = $additional->publisher->image;
  165. $image = resize_link($image, 4);
  166. } else
  167. $image = null;
  168. if (isset($additional->publisher->description))
  169. $text = $additional->publisher->description;
  170. else
  171. $text = null;
  172. $links = $document->evaluate("//ol[@id=\"band-links\"]//a");
  173. echo_sidebar($image, $text, $links);
  174. echo "</div>";
  175. } else {
  176. echo_error_message();
  177. };
  178. ?>
  179. <?php require_once "../elements/footer.php" ?>