artist.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php require_once "../utilities/index.php" ?>
  2. <?php
  3. if (isset($_GET["host"]) && $_GET["host"])
  4. $host = urlencode($_GET["name"]);
  5. else
  6. $host = urlencode($_GET["name"]) . ".bandcamp.com";
  7. $ch = curl_init("https://" . $host . "/music");
  8. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
  9. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  10. $document = new DOMXPath(encode_document(curl_exec($ch)));
  11. $redirect = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
  12. if ($redirect) {
  13. header("Location: " . convert_bandcamp_link($redirect));
  14. exit();
  15. };
  16. $title = $document->evaluate("//p[@id=\"band-name-location\"]//span[@class=\"title\"]")->item(0)->textContent;
  17. $items = json_decode($document->evaluate("//ol[@id=\"music-grid\"]")->item(0)->getAttribute("data-client-items"), true);
  18. ?>
  19. <?php require_once "../elements/header.php" ?>
  20. <?php require_once "../elements/item.php" ?>
  21. <?php require_once "../elements/sidebar.php" ?>
  22. <?php
  23. echo_design_style($document);
  24. if ($document->evaluate("//p[@id=\"band-name-location\"]//span[@class=\"title\"]")->count())
  25. echo "<h1>" . htmlspecialchars($document->evaluate("//p[@id=\"band-name-location\"]//span[@class=\"title\"]")->item(0)->textContent) . "</h1>";
  26. $releases = $document->evaluate("//ol[@id=\"music-grid\"]//li");
  27. if (!$releases->count() && !isset($items))
  28. echo_error_message();
  29. echo "<div class=\"page\">";
  30. echo "<div class=\"results\">";
  31. foreach ($releases as $release) {
  32. $title = preg_split("/\n[\n\s]+/", trim($document->evaluate(".//p[@class=\"title\"]", $release)->item(0)->textContent));
  33. unset($text);
  34. if (array_key_exists(1, $title)) $text = "by " . htmlspecialchars($title[1]);
  35. $image = $document->evaluate(".//img", $release)->item(0);
  36. $image = $image->hasAttribute("data-original") ? $image->getAttribute("data-original") : $image->getAttribute("src");
  37. $image = resize_link($image, 3);
  38. $image = convert_bandcamp_link($image);
  39. $link = $document->evaluate(".//a", $release)->item(0)->getAttribute("href");
  40. $link = prefix_link($link, "name");
  41. $link = convert_bandcamp_link($link);
  42. echo_item($link, $image, htmlspecialchars($title[0]), $text ?? null);
  43. };
  44. if (isset($items)) {
  45. foreach ($items as $item) {
  46. $title = $item["title"];
  47. unset($text);
  48. if (array_key_exists("artist", $item)) $text = "by " . $item["artist"];
  49. $image = $item["art_id"];
  50. $image = "https://f4.bcbits.com/img/a" . $image . "_0.jpg";
  51. $image = resize_link($image, 3);
  52. $image = convert_bandcamp_link($image);
  53. $link = prefix_link($item["page_url"], "name");
  54. $link = convert_bandcamp_link($link);
  55. echo_item($link, $image, htmlspecialchars($title), $text ?? null);
  56. };
  57. };
  58. echo "</div>";
  59. $image = $document->evaluate("//div[contains(@class, \"bio-pic\")]//a")->item(0)->getAttribute("href");
  60. $image = resize_link($image, 4);
  61. $description = $document->evaluate("//meta[@property=\"og:description\"]")->item(0)->getAttribute("content");
  62. $links = $document->evaluate("//ol[@id=\"band-links\"]//a");
  63. echo_sidebar($image, $description, $links);
  64. echo "</div>";
  65. ?>
  66. <?php require_once "../elements/footer.php" ?>