updateMetadata.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. require('functions.php');
  3. // Serien
  4. $apiURL = "http://thetvdb.com/api/084F3E73D176AD88/";
  5. $bannerURL = "http://www.thetvdb.com/banners/";
  6. if(!file_exists("posters")) {
  7. mkdir("posters");
  8. }
  9. // http://www.thetvdb.com/wiki/index.php/Programmers_API
  10. // Step 2 (dev)
  11. $languages = curl_download($apiURL . "languages.xml");
  12. $languages = new SimpleXMLElement($languages);
  13. $german = $languages->xpath('/Languages/Language/abbreviation[.="de"]/parent::*');
  14. $english = $languages->xpath('/Languages/Language/abbreviation[.="en"]/parent::*');
  15. // Step 1
  16. $mirrors = curl_download($apiURL . "mirrors.xml");
  17. $mirrors = new SimpleXMLElement($mirrors);
  18. // xml mirrors
  19. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="1"]/parent::*');
  20. if(sizeof($xmlMirrors < 1)) {
  21. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
  22. if(sizeof($xmlMirrors < 1)) {
  23. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
  24. if(sizeof($xmlMirrors < 1)) {
  25. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  26. }
  27. }
  28. }
  29. // banner mirrors
  30. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="2"]/parent::*');
  31. if(sizeof($bannerMirrors < 1)) {
  32. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
  33. if(sizeof($bannerMirrors < 1)) {
  34. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
  35. if(sizeof($bannerMirrors < 1)) {
  36. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  37. }
  38. }
  39. }
  40. // zip mirrors
  41. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="4"]/parent::*');
  42. if(sizeof($zipMirrors < 1)) {
  43. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
  44. if(sizeof($zipMirrors < 1)) {
  45. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
  46. if(sizeof($zipMirrors < 1)) {
  47. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  48. }
  49. }
  50. }
  51. // Step 2
  52. $serverTime = curl_download("http://thetvdb.com/api/Updates.php?type=none");
  53. $serverTime = new SimpleXMLElement($serverTime);
  54. // Step 3
  55. if(isset($_REQUEST['action']) && $_REQUEST['action'] == "singleDownload") {
  56. $seriesName = $_REQUEST['seriesname'];
  57. $seriesID = $_REQUEST['seriesid'];
  58. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
  59. if(strpos($series, 'Not Found') !== false) {
  60. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
  61. }
  62. $banners = curl_download($apiURL . "series/" . $seriesID . "/banners.xml");
  63. $banners = new SimpleXMLElement($banners);
  64. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  65. if(sizeof($poster) < 1) {
  66. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  67. }
  68. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  69. if(sizeof($seasons) > 0) {
  70. foreach($seasons as $season) {
  71. $seasonURL = $bannerURL . $season->BannerPath;
  72. file_put_contents("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  73. }
  74. }
  75. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  76. if(sizeof($seasons) > 0) {
  77. foreach($seasons as $season) {
  78. if(file_exists("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg")) {
  79. continue;
  80. }
  81. $seasonURL = $bannerURL . $season->BannerPath;
  82. file_put_contents("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  83. }
  84. }
  85. $series = new SimpleXMLElement($series);
  86. $poster = $poster[0]->BannerPath;
  87. $poster = $bannerURL . $poster;
  88. file_put_contents("posters/" . $seriesName . ".jpg", fopen($poster, 'r'));
  89. echo "Done.";
  90. } else if(!isset($_REQUEST['action'])) {
  91. $list = scandir("/media/Serien");
  92. $list = array_diff($list, array('.', '..'));
  93. foreach($list as $name) {
  94. echo $name . "<br>";
  95. if(file_exists("posters/" . $name . ".jpg")) {
  96. echo "skipping..<br><br>";
  97. continue;
  98. }
  99. $series = curl_download("http://thetvdb.com/api/GetSeries.php?seriesname=" . urlencode($name));
  100. $series = new SimpleXMLElement($series);
  101. if(sizeof($series) > 1) {
  102. foreach($series as $serie) {
  103. pa($serie);
  104. echo "<a target=\"_blank\" href=\"?action=singleDownload&seriesname=" . (string) $serie->SeriesName . "&seriesid=" . (string) $serie->seriesid . "\">Load</a><br>";
  105. }
  106. } else {
  107. $seriesID = (string) $series->Series->seriesid[0];
  108. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
  109. if(strpos($series, 'Not Found') !== false) {
  110. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
  111. }
  112. $banners = curl_download($apiURL . "series/" . $seriesID . "/banners.xml");
  113. $banners = new SimpleXMLElement($banners);
  114. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  115. if(sizeof($poster) < 1) {
  116. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  117. }
  118. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  119. if(sizeof($seasons) > 0) {
  120. foreach($seasons as $season) {
  121. $seasonURL = $bannerURL . $season->BannerPath;
  122. file_put_contents("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  123. }
  124. }
  125. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  126. if(sizeof($seasons) > 0) {
  127. foreach($seasons as $season) {
  128. if(file_exists("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg")) {
  129. continue;
  130. }
  131. $seasonURL = $bannerURL . $season->BannerPath;
  132. file_put_contents("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  133. }
  134. }
  135. $series = new SimpleXMLElement($series);
  136. $poster = $poster[0]->BannerPath;
  137. $poster = $bannerURL . $poster;
  138. file_put_contents("posters/" . $name . ".jpg", fopen($poster, 'r'));
  139. }
  140. }
  141. }
  142. // Filme
  143. $movieAPIUrl = "https://api.themoviedb.org/3/search/movie?api_key=a39779a38e0619f8ae58b09f64522597&query=";
  144. $moviePosterURL = "https://image.tmdb.org/t/p/original/";
  145. if(isset($_REQUEST['action']) && $_REQUEST['action'] == "singleDownloadMovie") {
  146. $movieName = $_REQUEST['moviename'];
  147. $movieID = $_REQUEST['movieid'];
  148. $movie = curl_download("https://api.themoviedb.org/3/movie/" . $movieID . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de");
  149. if(strpos($movie, 'not be found') !== false) {
  150. echo "something went wrong";
  151. }
  152. $movie = json_decode($movie);
  153. file_put_contents("posters/" . $movieName . ".jpg", fopen($moviePosterURL . $movie->poster_path, 'r'));
  154. echo "Done.";
  155. } else if(!isset($_REQUEST['action'])) {
  156. $list = scandir("/media/Filme");
  157. $list = array_diff($list, array('.', '..'));
  158. foreach($list as $movieName) {
  159. $movieName = explode('.', $movieName);
  160. unset($movieName[sizeof($movieName) - 1]);
  161. unset($movieName[sizeof($movieName) - 1]);
  162. $movieName = implode(' ', $movieName);
  163. $movieName = str_replace(" Directors Cut", "", $movieName);
  164. pa($movieName);
  165. if(file_exists("posters/" . $movieName . ".jpg")) {
  166. echo "skipping..<br><br>";
  167. continue;
  168. }
  169. $movie = json_decode(curl_download($movieAPIUrl . urlencode($movieName)));
  170. if(sizeof($movie->results) > 1) {
  171. foreach($movie->results as $result) {
  172. pa($result);
  173. echo "<a target=\"_blank\" href=\"?action=singleDownloadMovie&moviename=" . $movieName . "&movieid=" . (string) $result->id . "\">Load</a><br>";
  174. }
  175. } else {
  176. $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"));
  177. $poster = $moviePosterURL . $movie->poster_path;
  178. file_put_contents("posters/" . $movieName . ".jpg", fopen($poster, 'r'));
  179. }
  180. }
  181. }
  182. ?>