<commit_before>package EventStreamr::Devices;
use Moo; # libmoo-perl
use Cwd 'realpath';
use File::Slurp 'read_file'; #libfile-slurp-perl
use Hash::Merge::Simple; # libhash-merge-simple-perl
use Data::Dumper;

sub all {
  my $self = shift;
  my $v4l = v4l();
  my $dv = dv();
  my $alsa = alsa();
  @{$self->{devices}{v4l}{all}} = ();
  @{$self->{devices}{dv}{all}} = ();
  @{$self->{devices}{alsa}{all}} = ();

  if ($v4l) { $self->{devices}{v4l} = $v4l;       }
  if ($dv)  { $self->{devices}{dv} = $dv;         }
  if ($alsa)  { $self->{devices}{alsa} = $alsa;   }
  if ($v4l || $dv || $alsa) {
    $self->{devices}{all} = Hash::Merge::Simple->merge($v4l,$dv,$alsa);
    @{$self->{devices}{array}} = (@{$self->{devices}{v4l}{all}}, @{$self->{devices}{dv}{all}},@{$self->{devices}{alsa}{all}});
  }

  return $self->{devices};
}

sub v4l {
  my @v4ldevices = </dev/video*>;
  my $v4l_devices;
  foreach my $device (@v4ldevices) {
    $device =~ m/\/dev\/(?<index>.+)/;
    my $index = $+{index};
    $v4l_devices->{$index}{device} = $device;
    $v4l_devices->{$index}{name} = get_v4l_name($index);
    $v4l_devices->{$index}{type} = "v4l";
    push (@{$v4l_devices->{all}}, $v4l_devices->{$index});
  }
  return $v4l_devices;
}

sub dv {
  my @dvs = </sys/bus/firewire/devices/*>;
  my $dv_devices;

  foreach my $dv (@dvs) { # suffers from Big0 notation, but should only be a limited number of devices
    if (-e "$dv/vendor_name") {
      my $vendor_name = read_file("$dv/vendor_name");
      chomp $vendor_name;
      
      unless ($vendor_name eq "Linux Firewire") {
        my $guid = read_file("$dv/guid");
        my $model = read_file("$dv/model_name");
        chomp $guid;
        chomp $model;
        $dv_devices->{$guid}{device} = $guid;
        $dv_devices->{$guid}{model} = $model;
        $dv_devices->{$guid}{vendor} = $vendor_name;
        $dv_devices->{$guid}{type} = "dv";
        push (@{$dv_devices->{all}}, $dv_devices->{$guid}); ;
      }
    }
  }
  return $dv_devices;
}

sub alsa { # Only Does USB devices currently
  my $alsa_devices;
  my @devices = read_file("/proc/asound/cards");
  @devices = grep { /].+USB Audio (CODEC|Device)/ } @devices;
  chomp @devices;

  foreach my $device (@devices) {
    $device =~ m/^.+(?<card> \d+).*/x;
    my $card = $+{card};
    my $usbid = read_file("/proc/asound/card$card/usbid");
    my $name = name_lsusb($usbid);
    chomp $usbid;

    $alsa_devices->{$card}{usbid} = $usbid;
    $alsa_devices->{$card}{name} = $name;
    $alsa_devices->{$card}{device} = $card;
    $alsa_devices->{$card}{type} = "alsa";
    push (@{$alsa_devices->{all}}, $alsa_devices->{$card});
  }
  return $alsa_devices;<commit_msg>useful to have the id<commit_after>package EventStreamr::Devices;
use Moo; # libmoo-perl
use Cwd 'realpath';
use File::Slurp 'read_file'; #libfile-slurp-perl
use Hash::Merge::Simple; # libhash-merge-simple-perl
use Data::Dumper;

sub all {
  my $self = shift;
  my $v4l = v4l();
  my $dv = dv();
  my $alsa = alsa();
  @{$self->{devices}{v4l}{all}} = ();
  @{$self->{devices}{dv}{all}} = ();
  @{$self->{devices}{alsa}{all}} = ();

  if ($v4l) { $self->{devices}{v4l} = $v4l;       }
  if ($dv)  { $self->{devices}{dv} = $dv;         }
  if ($alsa)  { $self->{devices}{alsa} = $alsa;   }
  if ($v4l || $dv || $alsa) {
    $self->{devices}{all} = Hash::Merge::Simple->merge($v4l,$dv,$alsa);
    @{$self->{devices}{array}} = (@{$self->{devices}{v4l}{all}}, @{$self->{devices}{dv}{all}},@{$self->{devices}{alsa}{all}});
  }

  return $self->{devices};
}

sub v4l {
  my @v4ldevices = </dev/video*>;
  my $v4l_devices;
  foreach my $device (@v4ldevices) {
    $device =~ m/\/dev\/(?<index>.+)/;
    my $index = $+{index};
    $v4l_devices->{$index}{device} = $device;
    $v4l_devices->{$index}{name} = get_v4l_name($index);
    $v4l_devices->{$index}{type} = "v4l";
    $v4l_devices->{$index}{id} = $index;
    push (@{$v4l_devices->{all}}, $v4l_devices->{$index});
  }
  return $v4l_devices;
}

sub dv {
  my @dvs = </sys/bus/firewire/devices/*>;
  my $dv_devices;

  foreach my $dv (@dvs) { # suffers from Big0 notation, but should only be a limited number of devices
    if (-e "$dv/vendor_name") {
      my $vendor_name = read_file("$dv/vendor_name");
      chomp $vendor_name;
      
      unless ($vendor_name eq "Linux Firewire") {
        my $guid = read_file("$dv/guid");
        my $model = read_file("$dv/model_name");
        chomp $guid;
        chomp $model;
        $dv_devices->{$guid}{device} = $guid;
        $dv_devices->{$guid}{model} = $model;
        $dv_devices->{$guid}{vendor} = $vendor_name;
        $dv_devices->{$guid}{type} = "dv";
        $dv_devices->{$guid}{id} = $guid;
        push (@{$dv_devices->{all}}, $dv_devices->{$guid}); ;
      }
    }
  }
  return $dv_devices;
}

sub alsa { # Only Does USB devices currently
  my $alsa_devices;
  my @devices = read_file("/proc/asound/cards");
  @devices = grep { /].+USB Audio (CODEC|Device)/ } @devices;
  chomp @devices;

  foreach my $device (@devices) {
    $device =~ m/^.+(?<card> \d+).*/x;
    my $card = $+{card};
    my $usbid = read_file("/proc/asound/card$card/usbid");
    my $name = name_lsusb($usbid);
    chomp $usbid;

    $alsa_devices->{$card}{usbid} = $usbid;
    $alsa_devices->{$card}{name} = $name;
    $alsa_devices->{$card}{device} = $card;
    $alsa_devices->{$card}{type} = "alsa";
    $alsa_devices->{$card}{id} = $card;
    push (@{$alsa_devices->{all}}, $alsa_devices->{$card});
  }
  return $alsa_devices;
{'fraction_non_alphanumeric': 0.23110544527408486, 'fraction_numerical': 0.008195228555818612, 'mean_word_length': 3.4041700080192463, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '956306', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2130, 'n_words': 399}