updateMetadata.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. $poster = $poster[0]->BannerPath;
  69. $poster = $bannerURL . $poster;
  70. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  71. if(sizeof($seasons) > 0) {
  72. foreach($seasons as $season) {
  73. $seasonURL = $bannerURL . $season->BannerPath;
  74. file_put_contents("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  75. }
  76. }
  77. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  78. if(sizeof($seasons) > 0) {
  79. foreach($seasons as $season) {
  80. if(file_exists("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg")) {
  81. continue;
  82. }
  83. $seasonURL = $bannerURL . $season->BannerPath;
  84. file_put_contents("posters/" . $seriesName . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  85. }
  86. }
  87. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $german[0]->abbreviation . ".xml");
  88. $episodes = new SimpleXMLElement($episodes);
  89. if(sizeof($episodes->Episode) > 0) {
  90. foreach($episodes->Episode as $episode) {
  91. if(file_exists("posters/" . $seriesName . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  92. continue;
  93. }
  94. $episodeURL = $bannerURL . $episode->filename;
  95. file_put_contents("posters/" . $seriesName . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  96. }
  97. }
  98. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $english[0]->abbreviation . ".xml");
  99. $episodes = new SimpleXMLElement($episodes);
  100. if(sizeof($episodes->Episode) > 0) {
  101. foreach($episodes->Episode as $episode) {
  102. if(file_exists("posters/" . $seriesName . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  103. continue;
  104. }
  105. $episodeURL = $bannerURL . $episode->filename;
  106. file_put_contents("posters/" . $seriesName . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  107. }
  108. }
  109. $series = new SimpleXMLElement($series);
  110. file_put_contents("posters/" . $seriesName . ".jpg", fopen($poster, 'r'));
  111. echo "Done.";
  112. } else if(!isset($_REQUEST['action'])) {
  113. $list = scandir("/media/Serien");
  114. $list = array_diff($list, array('.', '..'));
  115. foreach($list as $name) {
  116. $object = str_split($name, sizeof($name));
  117. if($object[0] == "." && $object[1] != ".") {
  118. continue;
  119. }
  120. echo $name . "<br>";
  121. if(file_exists("posters/" . $name . ".jpg")) {
  122. echo "skipping..<br><br>";
  123. continue;
  124. }
  125. $series = curl_download("http://thetvdb.com/api/GetSeries.php?seriesname=" . urlencode($name));
  126. $series = new SimpleXMLElement($series);
  127. if(sizeof($series) > 1) {
  128. foreach($series as $serie) {
  129. pa($serie);
  130. echo "<a target=\"_blank\" href=\"?action=singleDownload&seriesname=" . (string) $serie->SeriesName . "&seriesid=" . (string) $serie->seriesid . "\">Load</a><br>";
  131. }
  132. } else {
  133. $seriesID = (string) $series->Series->seriesid[0];
  134. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
  135. if(strpos($series, 'Not Found') !== false) {
  136. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
  137. }
  138. $banners = curl_download($apiURL . "series/" . $seriesID . "/banners.xml");
  139. $banners = new SimpleXMLElement($banners);
  140. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  141. if(sizeof($poster) < 1) {
  142. $poster = $banners->xpath("/Banners/Banner/BannerType[text()='poster']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  143. }
  144. $poster = $poster[0]->BannerPath;
  145. $poster = $bannerURL . $poster;
  146. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $german[0]->abbreviation . "']/parent::*");
  147. if(sizeof($seasons) > 0) {
  148. foreach($seasons as $season) {
  149. $seasonURL = $bannerURL . $season->BannerPath;
  150. file_put_contents("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  151. }
  152. }
  153. $seasons = $banners->xpath("/Banners/Banner/BannerType[text()='season']/../BannerType2[text()='season']/../Language[text()='" . $english[0]->abbreviation . "']/parent::*");
  154. if(sizeof($seasons) > 0) {
  155. foreach($seasons as $season) {
  156. if(file_exists("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg")) {
  157. continue;
  158. }
  159. $seasonURL = $bannerURL . $season->BannerPath;
  160. file_put_contents("posters/" . $name . "_" . (string) $season->Season[0] . ".jpg", fopen($seasonURL, 'r'));
  161. }
  162. }
  163. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $german[0]->abbreviation . ".xml");
  164. $episodes = new SimpleXMLElement($episodes);
  165. if(sizeof($episodes->Episode) > 0) {
  166. foreach($episodes->Episode as $episode) {
  167. if(file_exists("posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  168. continue;
  169. }
  170. $episodeURL = $bannerURL . $episode->filename;
  171. file_put_contents("posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  172. }
  173. }
  174. $episodes = curl_download("http://thetvdb.com/api/084F3E73D176AD88/series/" . $seriesID . "/all/" . $english[0]->abbreviation . ".xml");
  175. $episodes = new SimpleXMLElement($episodes);
  176. if(sizeof($episodes->Episode) > 0) {
  177. foreach($episodes->Episode as $episode) {
  178. if(file_exists("posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg")) {
  179. continue;
  180. }
  181. $episodeURL = $bannerURL . $episode->filename;
  182. file_put_contents("posters/" . $name . "_" . (string) $episode->SeasonNumber[0] . "_" . (string) $episode->EpisodeNumber . ".jpg", fopen($episodeURL, 'r'));
  183. }
  184. }
  185. $series = new SimpleXMLElement($series);
  186. file_put_contents("posters/" . $name . ".jpg", fopen($poster, 'r'));
  187. }
  188. }
  189. }
  190. // Filme
  191. $movieAPIUrl = "https://api.themoviedb.org/3/search/movie?api_key=a39779a38e0619f8ae58b09f64522597&query=";
  192. $moviePosterURL = "https://image.tmdb.org/t/p/original/";
  193. if(isset($_REQUEST['action']) && $_REQUEST['action'] == "singleDownloadMovie") {
  194. $movieName = $_REQUEST['moviename'];
  195. $movieID = $_REQUEST['movieid'];
  196. $movie = curl_download("https://api.themoviedb.org/3/movie/" . $movieID . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de");
  197. if(strpos($movie, 'not be found') !== false) {
  198. echo "something went wrong";
  199. }
  200. $movie = json_decode($movie);
  201. file_put_contents("posters/" . $movieName . ".jpg", fopen($moviePosterURL . $movie->poster_path, 'r'));
  202. echo "Done.";
  203. } else if(!isset($_REQUEST['action'])) {
  204. $list = scandir("/media/Filme");
  205. $list = array_diff($list, array('.', '..'));
  206. foreach($list as $movieName) {
  207. $movieName = explode('.', $movieName);
  208. unset($movieName[sizeof($movieName) - 1]);
  209. unset($movieName[sizeof($movieName) - 1]);
  210. $movieName = implode(' ', $movieName);
  211. $movieName = str_replace(" Directors Cut", "", $movieName);
  212. pa($movieName);
  213. if(file_exists("posters/" . $movieName . ".jpg")) {
  214. echo "skipping..<br><br>";
  215. continue;
  216. }
  217. $movie = json_decode(curl_download($movieAPIUrl . urlencode($movieName)));
  218. if(sizeof($movie->results) > 1) {
  219. foreach($movie->results as $result) {
  220. pa($result);
  221. echo "<a target=\"_blank\" href=\"?action=singleDownloadMovie&moviename=" . $movieName . "&movieid=" . (string) $result->id . "\">Load</a><br>";
  222. }
  223. } else {
  224. $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"));
  225. $poster = $moviePosterURL . $movie->poster_path;
  226. file_put_contents("posters/" . $movieName . ".jpg", fopen($poster, 'r'));
  227. }
  228. }
  229. }
  230. ?>