25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

90 satır
2.6 KiB

  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. This script downloads all drives and offsets from Accuraterip's website, and then
  5. applies various bits of normalization to be used within the Logchecker
  6. */
  7. $replacements = [
  8. ['16X DVD- - ROM', '16X DVD-ROM'],
  9. ['HL)DP-ST', 'HL-DP-ST'],
  10. ['FREECOM_', 'FREECOM'],
  11. ['Generic_', 'GENERIC']
  12. ];
  13. $ch = curl_init();
  14. curl_setopt($ch, CURLOPT_URL, 'http://www.accuraterip.com/driveoffsets.htm');
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  17. $doc = new DOMDocument();
  18. $doc->loadHTML(curl_exec($ch), LIBXML_NOWARNING | LIBXML_NOERROR);
  19. curl_close($ch);
  20. print("Loaded AccurateRip Drive Website\n\n");
  21. $item = $doc->getElementsByTagName('table')->item(1);
  22. if ($item === null) {
  23. die();
  24. }
  25. $drives = [];
  26. $count = $item->childNodes->count();
  27. for ($i = 2; $i < $count; $i++) {
  28. $childNode = $item->childNodes->item($i);
  29. if ($childNode === null) {
  30. continue;
  31. }
  32. if ($childNode->nodeName !== 'tr') {
  33. continue;
  34. }
  35. $drive = array_map('trim', explode("\n", ltrim(trim($childNode->textContent), "- ")));
  36. if (count($drive) !== 4) {
  37. continue;
  38. }
  39. $drive[1] = (int) $drive[1];
  40. $drive[3] = (int) $drive[3];
  41. if ($drive[1] === '[Purged]' || $drive[3] <= 50) {
  42. continue;
  43. }
  44. foreach ($replacements as [$old, $new]) {
  45. $drive[0] = str_replace($old, $new, $drive[0]);
  46. }
  47. $drive[0] = strtolower($drive[0]);
  48. $drive[0] = preg_replace('/ +- +/', ' ', $drive[0]);
  49. $drive[0] = preg_replace('/ +/', ' ', $drive[0]);
  50. //print("[" . implode(', ', array_values($drive)) . "]\n");
  51. $drives[] = $drive;
  52. }
  53. file_put_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'src', 'resources', 'drives.json']), json_encode($drives));
  54. print("Updating " . count($drives) . " drives\n");
  55. /*
  56. $drives = [];
  57. for ($i = 1; $i < $rows->length; $i++) {
  58. $row = $rows->item($i);
  59. if ($row->childNodes->length > 4 && $row->childNodes->item(3)->nodeValue !== '[Purged]') {
  60. $drive = trim($row->childNodes->item(1)->nodeValue, '- ');
  61. foreach ($replacements as $replacement) {
  62. $drive = str_replace($replacement[0], $replacement[1], $drive);
  63. }
  64. $drive = strtolower($drive);
  65. $drive = preg_replace('/ +- +/', ' ', $drive);
  66. $drive = preg_replace('/ +/', ' ', $drive);
  67. $offset = ltrim(trim($row->childNodes->item(3)->nodeValue), '+');
  68. $offsets[] = $drive.','.$offset;
  69. }
  70. }
  71. file_put_contents(__DIR__.'/../src/offsets.txt', implode("\n", $offsets));
  72. print("Updating ".count($offsets)." drives\n");
  73. */