updateMetadata.php 12 KB

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