BioTorrents.de’s version of Gazelle
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.

validate.class.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. class Validate
  3. {
  4. # Line 171
  5. /**
  6. * Extension Parser
  7. *
  8. * Takes an associative array of file types and extension, e.g.,
  9. * $Archives = [
  10. * '7z' => ['7z'],
  11. * 'bzip2' => ['bz2', 'bzip2'],
  12. * 'gzip' => ['gz', 'gzip', 'tgz', 'tpz'],
  13. * ...
  14. * ];
  15. *
  16. * Then it finds all the extensions in a torrent file list,
  17. * organizes them by file size, and returns the "heaviest" match.
  18. *
  19. * That way, you can have, e.g., 5 GiB FASTQ sequence data in one file,
  20. * and 100 other small files, and get the format of the actual data.
  21. *
  22. * todo: Incorporate into the main function (remove if statements first)
  23. */
  24. public function ParseExtensions($FileList, $Category, $FileTypes)
  25. {
  26. # Make $Tor->file_list() output manageable
  27. $UnNested = array_values($FileList[1]);
  28. $Sorted = (usort($UnNested, function ($a, $b) {
  29. return $b <=> $a; # Workaround because ↑ returns true
  30. }) === true) ? array_values($UnNested) : null;
  31. # Harvest the wheat
  32. $TopTen = array_slice($Sorted, 0, 10);
  33. $Result = [];
  34. foreach ($TopTen as $TopTen) {
  35. # How many extensions to keep
  36. $Extensions = array_slice(explode('.', strtolower($TopTen[1])), -2, 2);
  37. print_r('<pre>');
  38. var_dump($FileTypes);
  39. print_r('</pre>');
  40. $Result = array_filter($Extensions, function ($a) {
  41. foreach ($FileTypes as $FileType) {
  42. in_array($a, $FileType);
  43. }
  44. });
  45. /*
  46. foreach ($FileTypes as $k => $FileType) {
  47. var_dump(array_intersect($Extensions, $FileTypes));
  48. }
  49. */
  50. }
  51. print_r('<pre>');
  52. print_r('===== RESULTS =====');
  53. print_r($Result);
  54. print_r('</pre>');
  55. # To be continued
  56. }
  57. # Line 229