updateMetadata.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. require('functions.php');
  3. $apiURL = "http://thetvdb.com/api/084F3E73D176AD88/";
  4. $bannerURL = "http://www.thetvdb.com/banners/";
  5. if(!file_exists("posters")) {
  6. mkdir("posters");
  7. }
  8. // http://www.thetvdb.com/wiki/index.php/Programmers_API
  9. // Step 2 (dev)
  10. $languages = curl_download($apiURL . "languages.xml");
  11. $languages = new SimpleXMLElement($languages);
  12. $german = $languages->xpath('/Languages/Language/abbreviation[.="de"]/parent::*');
  13. $english = $languages->xpath('/Languages/Language/abbreviation[.="en"]/parent::*');
  14. // Step 1
  15. $mirrors = curl_download($apiURL . "mirrors.xml");
  16. $mirrors = new SimpleXMLElement($mirrors);
  17. // xml mirrors
  18. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="1"]/parent::*');
  19. if(sizeof($xmlMirrors < 1)) {
  20. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
  21. if(sizeof($xmlMirrors < 1)) {
  22. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
  23. if(sizeof($xmlMirrors < 1)) {
  24. $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  25. }
  26. }
  27. }
  28. // banner mirrors
  29. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="2"]/parent::*');
  30. if(sizeof($bannerMirrors < 1)) {
  31. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
  32. if(sizeof($bannerMirrors < 1)) {
  33. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
  34. if(sizeof($bannerMirrors < 1)) {
  35. $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  36. }
  37. }
  38. }
  39. // zip mirrors
  40. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="4"]/parent::*');
  41. if(sizeof($zipMirrors < 1)) {
  42. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
  43. if(sizeof($zipMirrors < 1)) {
  44. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
  45. if(sizeof($zipMirrors < 1)) {
  46. $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
  47. }
  48. }
  49. }
  50. // Step 2
  51. $serverTime = curl_download("http://thetvdb.com/api/Updates.php?type=none");
  52. $serverTime = new SimpleXMLElement($serverTime);
  53. // Step 3
  54. if(isset($_REQUEST['action']) && $_REQUEST['action'] == "singleDownload") {
  55. $seriesName = $_REQUEST['seriesname'];
  56. $seriesID = $_REQUEST['seriesid'];
  57. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
  58. if(strpos($series, 'Not Found') !== false) {
  59. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
  60. }
  61. $series = new SimpleXMLElement($series);
  62. $poster = (string) $series->Series->poster;
  63. $poster = $bannerURL . $poster;
  64. file_put_contents("posters/" . $seriesName . ".jpg", fopen($poster, 'r'));
  65. } else {
  66. $list = scandir("/media/Serien");
  67. $list = array_diff($list, array('.', '..'));
  68. foreach($list as $name) {
  69. echo $name . "<br>";
  70. if(file_exists("posters/" . $name . ".jpg")) {
  71. echo "skipping..<br><br>";
  72. continue;
  73. }
  74. $series = curl_download("http://thetvdb.com/api/GetSeries.php?seriesname=" . urlencode($name));
  75. $series = new SimpleXMLElement($series);
  76. if(sizeof($series) > 1) {
  77. foreach($series as $serie) {
  78. pa($serie);
  79. echo "<a target=\"_blank\" href=\"?action=singleDownload&seriesname=" . (string) $serie->SeriesName . "&seriesid=" . (string) $serie->seriesid . "\">Load</a><br>";
  80. }
  81. } else {
  82. $seriesID = (string) $series->Series->seriesid[0];
  83. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
  84. if(strpos($series, 'Not Found') !== false) {
  85. $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
  86. }
  87. $series = new SimpleXMLElement($series);
  88. $poster = (string) $series->Series->poster;
  89. $poster = $bannerURL . $poster;
  90. file_put_contents("posters/" . $name . ".jpg", fopen($poster, 'r'));
  91. }
  92. }
  93. }
  94. ?>