Browse Source

Add artist page

Sunny 2 years ago
parent
commit
e95aa887ab
3 changed files with 40 additions and 3 deletions
  1. 3 0
      .gitmodules
  2. 36 3
      artist.php
  3. 1 0
      modules/querypath

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "modules/querypath"]
+	path = modules/querypath
+	url = https://github.com/technosophos/querypath.git

+ 36 - 3
artist.php

@@ -1,10 +1,43 @@
 <?php
-  $document = new DOMDocument();
-  $document->loadHTML(file_get_contents("https://" . urlencode($_GET["name"]) . ".bandcamp.com"));
+  require "modules/querypath/src/qp.php";
 
-  $title = htmlspecialchars($document->getElementsByTagName("meta")->item(4)->getAttribute("content"));
+  $document = htmlqp(file_get_contents("https://" . urlencode($_GET["name"]) . ".bandcamp.com"));
+
+  $title = $document->find("#band-name-location .title")->text();
 ?>
 
 <?php include "elements/header.php" ?>
 
+<?php
+  echo "<div class=results>";
+
+  foreach ($document->find("#music-grid li") as $release) {
+    $title = preg_split("/\n[\n\s]+/", trim($release->find(".title")->text()));
+
+    $image = $release->find("img");
+    if ($image->hasAttr("data-original"))
+      $image = $image->attr("data-original");
+    else
+      $image = $image->attr("src");
+    $image = "image.php?file=" . basename($image);
+
+    echo "<a href=https://" . urlencode($_GET["name"]) . ".bandcamp.com" . $release->find("a")->attr("href") . ">";
+    echo "<div>";
+    echo "<img src=" . $image . ">";
+    echo "<p>";
+    echo htmlspecialchars($title[0]);
+    if (isset($title[1])) {
+      echo "<br>";
+      echo "<small>";
+      echo "by " . htmlspecialchars($title[1]);
+      echo "</small>";
+    };
+    echo "</p>";
+    echo "</div>";
+    echo "</a>";
+  };
+
+  echo "</div>";
+?>
+
 <?php include "elements/footer.php" ?>

+ 1 - 0
modules/querypath

@@ -0,0 +1 @@
+Subproject commit b0279de7837d199e10b779ed98e2201d8a10e61f