You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 line
1.5 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. $rows = $doc->getElementsByTagName('table')->item(1)->getElementsByTagName('tr');
  21. $drives = [];
  22. for ($i = 1; $i < $rows->length; $i++) {
  23. $row = $rows->item($i);
  24. if ($row->childNodes->length > 4 && $row->childNodes->item(3)->nodeValue !== '[Purged]') {
  25. $drive = trim($row->childNodes->item(1)->nodeValue, '- ');
  26. foreach ($replacements as $replacement) {
  27. $drive = str_replace($replacement[0], $replacement[1], $drive);
  28. }
  29. $drive = strtolower($drive);
  30. $drive = preg_replace('/ +- +/', ' ', $drive);
  31. $drive = preg_replace('/ +/', ' ', $drive);
  32. $offset = ltrim(trim($row->childNodes->item(3)->nodeValue), '+');
  33. $offsets[] = $drive.','.$offset;
  34. }
  35. }
  36. file_put_contents(__DIR__.'/../src/offsets.txt', implode("\n", $offsets));
  37. print("Updating ".count($offsets)." drives\n");