updateMetadata.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <?php
  2. /*
  3. ignore_user_abort(true);
  4. require('functions.php');
  5. // Serien
  6. $apiURL = "http://thetvdb.com/api/084F3E73D176AD88/";
  7. $bannerURL = "http://www.thetvdb.com/banners/";
  8. if(!file_exists("posters")) {
  9. mkdir("posters");
  10. }
  11. // http://www.thetvdb.com/wiki/index.php/Programmers_API
  12. // Step 2 (dev)
  13. $languages = curl_download($apiURL . "languages.xml");
  14. $languages = new SimpleXMLElement($languages);
  15. $german = $languages->xpath('/Languages/Language/abbreviation[.="de"]/parent::*');
  16. $english = $languages->xpath('/Languages/Language/abbreviation[.="en"]/parent::*');
  17. // Step 1
  18. $mirrors = curl_download($apiURL . "mirrors.xml");
  19. $mirrors = new SimpleXMLElement($mirrors);
  20. // xml mirrors
  21. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="1"]/parent::*');
  22. if(sizeof($xmlMirrors < 1)) {
  23. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
  24. if(sizeof($xmlMirrors < 1)) {
  25. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
  26. if(sizeof($xmlMirrors < 1)) {
  27. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  28. }
  29. }
  30. }
  31. // banner mirrors
  32. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="2"]/parent::*');
  33. if(sizeof($bannerMirrors < 1)) {
  34. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
  35. if(sizeof($bannerMirrors < 1)) {
  36. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
  37. if(sizeof($bannerMirrors < 1)) {
  38. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  39. }
  40. }
  41. }
  42. // zip mirrors
  43. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="4"]/parent::*');
  44. if(sizeof($zipMirrors < 1)) {
  45. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
  46. if(sizeof($zipMirrors < 1)) {
  47. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
  48. if(sizeof($zipMirrors < 1)) {
  49. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  50. }
  51. }
  52. }
  53. // Step 2
  54. $serverTime = curl_download("http://thetvdb.com/api/Updates.php?type=none");
  55. $serverTime = new SimpleXMLElement($serverTime);
  56. // Step 3
  57. if(isset($_REQUEST['action']) && $_REQUEST['action'] == "singleDownload") {
  58. $seriesName = $_REQUEST['seriesname'];
  59. $seriesID = $_REQUEST['seriesid'];
  60. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
  61. if(strpos($series, 'Not Found') !== false) {
  62. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
  63. }
  64. $banners = curl_download($apiURL . "series/" . $seriesID . "/banners.xml");
  65. $banners = new SimpleXMLElement($banners);
  66. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  67. if(sizeof($poster) < 1) {
  68. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  69. }
  70. $poster = $poster[0]->BannerPath;
  71. $poster = $bannerURL . $poster;
  72. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  73. if(sizeof($seasons) > 0) {
  74. foreach($seasons as $season) {
  75. $seasonURL = $bannerURL . $season->BannerPath;
  76. file_put_contents("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  77. }
  78. }
  79. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  80. if(sizeof($seasons) > 0) {
  81. foreach($seasons as $season) {
  82. if(file_exists("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg")) {
  83. continue;
  84. }
  85. $seasonURL = $bannerURL . $season->BannerPath;
  86. file_put_contents("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  87. }
  88. }
  89. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $german[0]->abbreviation . ".xml");
  90. $episodes = new SimpleXMLElement($episodes);
  91. if(sizeof($episodes->Episode) > 0) {
  92. foreach($episodes->Episode as $episode) {
  93. if(file_exists("posters/" . $seriesName . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  94. continue;
  95. }
  96. $episodeURL = $bannerURL . $episode->filename;
  97. file_put_contents("posters/" . $seriesName . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  98. }
  99. }
  100. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $english[0]->abbreviation . ".xml");
  101. $episodes = new SimpleXMLElement($episodes);
  102. if(sizeof($episodes->Episode) > 0) {
  103. foreach($episodes->Episode as $episode) {
  104. if(file_exists("posters/" . $seriesName . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  105. continue;
  106. }
  107. $episodeURL = $bannerURL . $episode->filename;
  108. file_put_contents("posters/" . $seriesName . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  109. }
  110. }
  111. $series = new SimpleXMLElement($series);
  112. file_put_contents("posters/" . $seriesName . ".jpg", fopen($poster, 'r'));
  113. echo "Done.";
  114. } else if(!isset($_REQUEST['action'])) {
  115. $list = scandir("/media/Serien");
  116. $list = array_diff($list, array('.', '..'));
  117. foreach($list as $name) {
  118. $object = str_split($name, sizeof($name));
  119. if($object[0] == "." && $object[1] != ".") {
  120. continue;
  121. }
  122. echo $name . "<br>";
  123. if(file_exists("posters/" . $name . ".jpg")) {
  124. echo "skipping..<br><br>";
  125. continue;
  126. }
  127. $series = curl_download("http://thetvdb.com/api/GetSeries.php?seriesname=" . urlencode($name));
  128. $series = new SimpleXMLElement($series);
  129. if(sizeof($series) > 1) {
  130. foreach($series as $serie) {
  131. pa($serie);
  132. echo "<a target=\"_blank\" href=\"?action=singleDownload&seriesname=" . (string) $serie->SeriesName . "&seriesid=" . (string) $serie->seriesid . "\">Load</a><br>";
  133. }
  134. } else {
  135. $seriesID = (string) $series->Series->seriesid[0];
  136. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
  137. if(strpos($series, 'Not Found') !== false) {
  138. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
  139. }
  140. $banners = curl_download($apiURL . "series/" . $seriesID . "/banners.xml");
  141. $banners = new SimpleXMLElement($banners);
  142. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  143. if(sizeof($poster) < 1) {
  144. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  145. }
  146. $poster = $poster[0]->BannerPath;
  147. $poster = $bannerURL . $poster;
  148. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  149. if(sizeof($seasons) > 0) {
  150. foreach($seasons as $season) {
  151. $seasonURL = $bannerURL . $season->BannerPath;
  152. file_put_contents("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  153. }
  154. }
  155. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  156. if(sizeof($seasons) > 0) {
  157. foreach($seasons as $season) {
  158. if(file_exists("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg")) {
  159. continue;
  160. }
  161. $seasonURL = $bannerURL . $season->BannerPath;
  162. file_put_contents("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  163. }
  164. }
  165. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $german[0]->abbreviation . ".xml");
  166. $episodes = new SimpleXMLElement($episodes);
  167. if(sizeof($episodes->Episode) > 0) {
  168. foreach($episodes->Episode as $episode) {
  169. if(file_exists("posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  170. continue;
  171. }
  172. $episodeURL = $bannerURL . $episode->filename;
  173. file_put_contents("posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  174. }
  175. }
  176. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $english[0]->abbreviation . ".xml");
  177. $episodes = new SimpleXMLElement($episodes);
  178. if(sizeof($episodes->Episode) > 0) {
  179. foreach($episodes->Episode as $episode) {
  180. if(file_exists("posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  181. continue;
  182. }
  183. $episodeURL = $bannerURL . $episode->filename;
  184. file_put_contents("posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  185. }
  186. }
  187. $series = new SimpleXMLElement($series);
  188. file_put_contents("posters/" . $name . ".jpg", fopen($poster, 'r'));
  189. }
  190. }
  191. }
  192. */
  193. // Filme
  194. $movieAPIUrl = "https://api.themoviedb.org/3/search/movie?api_key=a39779a38e0619f8ae58b09f64522597&query=";
  195. $moviePosterURL = "https://image.tmdb.org/t/p/original/";
  196. if(isset($_REQUEST['action']) && $_REQUEST['action'] == "singleDownloadMovie") {
  197. $movieName = $_REQUEST['moviename'];
  198. $movieID = $_REQUEST['movieid'];
  199. $movie = curl_download("https://api.themoviedb.org/3/movie/" . $movieID . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de");
  200. if(strpos($movie, 'not be found') !== false) {
  201. echo "something went wrong";
  202. }
  203. $movie = json_decode($movie);
  204. file_put_contents("posters/" . $movieName . ".jpg", fopen($moviePosterURL . $movie->poster_path, 'r'));
  205. echo "Done.";
  206. } else if(!isset($_REQUEST['action'])) {
  207. $list = scandir("/media/Filme");
  208. $list = array_diff($list, array('.', '..'));
  209. foreach($list as $movieName) {
  210. $movieName = explode('.', $movieName);
  211. unset($movieName[sizeof($movieName) - 1]);
  212. unset($movieName[sizeof($movieName) - 1]);
  213. $movieName = implode(' ', $movieName);
  214. $movieName = str_replace(" Directors Cut", "", $movieName);
  215. pa($movieName);
  216. if(file_exists("posters/" . $movieName . ".jpg")) {
  217. echo "skipping..<br><br>";
  218. continue;
  219. }
  220. $movie = json_decode(curl_download($movieAPIUrl . urlencode($movieName)));
  221. if(sizeof($movie->results) > 1) {
  222. foreach($movie->results as $result) {
  223. pa($result);
  224. echo "<a target=\"_blank\" href=\"?action=singleDownloadMovie&moviename=" . $movieName . "&movieid=" . (string) $result->id . "\">Load</a><br>";
  225. }
  226. } else {
  227. $movie = json_decode(curl_download("https://api.themoviedb.org/3/movie/" . (string) $movie->results[0]->id . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de"));
  228. $poster = $moviePosterURL . $movie->poster_path;
  229. file_put_contents("posters/" . $movieName . ".jpg", fopen($poster, 'r'));
  230. }
  231. }
  232. }
  233. /*
  234. ?>
  235. $languages = curl_download($this->apiURL . "languages.xml");
  236. $languages = new SimpleXMLElement($languages);
  237. $german = $languages->xpath('/Languages/Language/abbreviation[.="de"]/parent::*');
  238. $english = $languages->xpath('/Languages/Language/abbreviation[.="en"]/parent::*');
  239. $mirrors = curl_download($this->apiURL . "mirrors.xml");
  240. $mirrors = new SimpleXMLElement($mirrors);
  241. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="1"]/parent::*');
  242. if(sizeof($xmlMirrors < 1)) {
  243. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
  244. if(sizeof($xmlMirrors < 1)) {
  245. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
  246. if(sizeof($xmlMirrors < 1)) {
  247. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  248. }
  249. }
  250. }
  251. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="2"]/parent::*');
  252. if(sizeof($bannerMirrors < 1)) {
  253. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
  254. if(sizeof($bannerMirrors < 1)) {
  255. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
  256. if(sizeof($bannerMirrors < 1)) {
  257. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  258. }
  259. }
  260. }
  261. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="4"]/parent::*');
  262. if(sizeof($zipMirrors < 1)) {
  263. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
  264. if(sizeof($zipMirrors < 1)) {
  265. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
  266. if(sizeof($zipMirrors < 1)) {
  267. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  268. }
  269. }
  270. }
  271. $serverTime = curl_download("http://thetvdb.com/api/Updates.php?type=none");
  272. $serverTime = new SimpleXMLElement($serverTime);
  273. $list = scandir($path);
  274. $list = array_diff($list, array('.', '..', 'formatting.txt'));
  275. foreach($list as $name) {
  276. $object = str_split($name, sizeof($name));
  277. if($object[0] == "." && $object[1] != ".") { // Ignore dotfiles
  278. continue;
  279. }
  280. error_log($name);
  281. $this->outputText .= $name . "<br>" . PHP_EOL;
  282. if(file_exists("img/posters/" . $name . ".jpg")) {
  283. $this->outputText .= "skipping..<br><br>" . PHP_EOL;
  284. continue;
  285. }
  286. $series = curl_download("http://thetvdb.com/api/GetSeries.php?seriesname=" . urlencode($name));
  287. $series = new SimpleXMLElement($series);
  288. if(sizeof($series) > 1) {
  289. foreach($series as $serie) {
  290. $this->outputText .= "<pre>" . print_r($serie, true) . "</pre>" . PHP_EOL;
  291. $this->outputText .= "<a target=\"_blank\" href=\"?action=singleDownload&seriesname=" . (string) $serie->SeriesName . "&seriesid=" . (string) $serie->seriesid . "\">Load</a><br>" . PHP_EOL;
  292. }
  293. } else {
  294. error_log($seriesID);
  295. $seriesID = (string) $series->Series->seriesid[0];
  296. $series = curl_download($this->apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
  297. if(strpos($series, 'Not Found') !== false) {
  298. $series = curl_download($this->apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
  299. }
  300. $banners = curl_download($this->apiURL . "series/" . $seriesID . "/banners.xml");
  301. $banners = new SimpleXMLElement($banners);
  302. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  303. if(sizeof($poster) < 1) {
  304. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  305. }
  306. $poster = $poster[0]->BannerPath;
  307. $poster = $this->bannerURL . $poster;
  308. file_put_contents("img/posters/" . $name . ".jpg", fopen($poster, 'r'));
  309. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  310. if(sizeof($seasons) > 0) {
  311. foreach($seasons as $season) {
  312. $seasonURL = $this->bannerURL . $season->BannerPath;
  313. file_put_contents("img/posters/" . $name . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  314. }
  315. }
  316. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  317. if(sizeof($seasons) > 0) {
  318. foreach($seasons as $season) {
  319. if(file_exists("img/posters/" . $name . "_" . (string) $season->Season[0] . ".jpg")) {
  320. continue;
  321. }
  322. $seasonURL = $this->bannerURL . $season->BannerPath;
  323. file_put_contents("img/posters/" . $name . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  324. }
  325. }
  326. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $german[0]->abbreviation . ".xml");
  327. $episodes = new SimpleXMLElement($episodes);
  328. if(sizeof($episodes->Episode) > 0) {
  329. foreach($episodes->Episode as $episode) {
  330. if(file_exists("img/posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  331. continue;
  332. }
  333. if(!empty($episode->filename)) {
  334. $episodeURL = $this->bannerURL . $episode->filename;
  335. file_put_contents("img/posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  336. }
  337. }
  338. }
  339. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $english[0]->abbreviation . ".xml");
  340. $episodes = new SimpleXMLElement($episodes);
  341. if(sizeof($episodes->Episode) > 0) {
  342. foreach($episodes->Episode as $episode) {
  343. if(file_exists("img/posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  344. continue;
  345. }
  346. if(!empty($episode->filename)) {
  347. $episodeURL = $this->bannerURL . $episode->filename;
  348. file_put_contents("img/posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  349. }
  350. }
  351. }
  352. error_log("serie done");
  353. }
  354. error_log("done");
  355. }