Browse Source

Use random user agent

Thanks to https://github.com/Miserlou/SoundScrape/issues/174.
Sunny 2 years ago
parent
commit
0cc138dd0a
3 changed files with 6 additions and 0 deletions
  1. 3 0
      .gitmodules
  2. 1 0
      modules/random-user-agent
  3. 2 0
      pages/release.php

+ 3 - 0
.gitmodules

@@ -4,3 +4,6 @@
 [submodule "modules/querypath"]
 	path = modules/querypath
 	url = https://github.com/technosophos/querypath.git
+[submodule "modules/random-user-agent"]
+	path = modules/random-user-agent
+	url = https://github.com/joecampo/random-user-agent.git

+ 1 - 0
modules/random-user-agent

@@ -0,0 +1 @@
+Subproject commit 4a88bd90f66ca398b050b19848e3c6ea143ce8a0

+ 2 - 0
pages/release.php

@@ -2,9 +2,11 @@
   require_once "../config/config.php";
   require_once "../utilities/dom.php";
   require_once "../modules/querypath/src/qp.php";
+  require_once "../modules/random-user-agent/src/UserAgent.php";
 
   $ch = curl_init("https://" . urlencode($_GET["artist"]) . ".bandcamp.com/" . urlencode($_GET["type"]) . "/" . urlencode($_GET["name"]));
 
+  curl_setopt($ch, CURLOPT_USERAGENT, \Campo\UserAgent::random());
   if (isset($config["identity"]))
     curl_setopt($ch, CURLOPT_COOKIE, "identity=" . $config["identity"]);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);