This file is indexed.

/usr/bin/stxdb is in hxtools 20170430-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/perl
#
#	stxdb 2.1 (Audio file database)
#	Copyright © Jan Engelhardt <jengelh [at] medozas de>, 2005 - 2007
#
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the GNU General Public License
#	as published by the Free Software Foundation; either version 2
#	of the License, or (at your option) any later version.
#
use Data::Dumper;
use Encode;
use Getopt::Long;
use strict;

binmode STDIN,  ":utf8";
binmode STDOUT, ":utf8";
select((select(STDERR), $| = 1)[0]);
my $EXTENSIONS = qr/\.(ogg|mp3|it|mid|divx?|mpe?g)/i;

# Data::Dumper configuration
$Data::Dumper::Useqq = 1;
$Data::Dumper::Indent = 1;

# Option gathering
my @Addpt;
my $Convert;
my $Db_file;
my $Do_mount;
my $Do_save_db;
my $Do_show_db;
my $Vol_id;
my %Opts;

&Getopt::Long::Configure(qw(bundling pass_through));
&GetOptions(
	"A=s" => \@Addpt,      # path to directory which to add
	"C"   => \$Convert,
	"M"   => \$Do_mount,   # (un)mount each "add" target
	"S"   => \$Do_save_db, # save database after operation
	"V=s" => \$Vol_id,     # volume identifier
	"W"   => \$Do_show_db, # show database after operation
	"a"   => \$Opts{artist},
	"f=s" => \$Db_file,    # use specified file
	"l"   => \$Opts{album},
	"o=s" => \%Opts,
);

&load_db();
&process_add();
if($Convert)    { &convert_db(); }
if($Do_save_db) { &save_db(); }
if($Do_show_db) { &show_db(); }

#------------------------------------------------------------------------------
sub add_target ()
{
	my $count = 0; # added this many files
	my($vol_id, $dir) = @_;

	foreach my $filename (`find "$dir" -type f`) {
		my($artist, $album, $title);

		chomp $filename;
		if ($filename !~ /$EXTENSIONS/s) {
			next;
		}

		++$count;
		my $filesize = -s $filename;
		$filename =~ s[^\Q$dir\E/][];

		my $regname = $filename;
		$regname =~ s/$EXTENSIONS$//s;

		#
		# Different kinds of naming schemes:
		#
		if ($regname =~ m{([^/]+)\s+-\s+([^/]+)/([^/]+)$}) {
			#
			# >> "Artist - Album/Title"
			#
			# This storage method is obviously used for complete albums.
			#
			($artist, $album, $title) = ($1, $2, $3);
		} elsif ($regname =~ m{([^/]+)/([^/]+)$}) {
			#
			# >> "Artist/Title.ogg"
			#
			# This one is used when you do not want to sort by album, probably
			# because:
			# - you do not have the full album and thus intermix them
			# - the track does not belong to any album or
			# - has more than one "home" album
			#
			($artist, $album, $title) = ($1, undef, $2);
		} elsif ($regname =~ m{([^/]+)\s+-\s+([^/]+)$}) {
			#
			# >> "Artist - Title.ogg"
			#
			# This is like the above, but used when there are X (depends on
			# personal preference, I use 3 or 4 for X) or less files for that
			# artist on the volume.
			#
			($artist, $album, $title) = ($1, undef, $2);
		} else {
			#
			# >> "Single file.ogg"
			#
			# For files which do not [quite] have an artist, for example the
			# "Star Trek TNG Theme". (You could use "Theme" as artist, though.)
			# To give a clearer example: "Cool Cat". Go figure.
			#
			($artist, $album, $title) = (undef, undef, $regname);

			# Print a warning; maybe this file was not recognized by the above
			# regular expressions.
			print STDERR "Warning: Adding single file \"$filename\"\n";
		}

		$::DB->{$artist}{$album}{$title} = [$filesize, "$vol_id/$filename"];
	}

	return $count;
}

#
# Process -f option: Load database
#
sub load_db ()
{
	if ($Db_file eq "") {
		my $name = getpwuid($>);
		if ($name eq "") {
			$Db_file = "stxdb.dat";
		} else {
			$Db_file = "stxdb-$name.dat";
		}
		do $Db_file;
	} else {
		# Explicit filename was given, so croak if it cannot be loaded
		do $Db_file || die "Error loading database: $!\n";
	}
	return;
}

#
# Process -A targets, if any.
#
sub process_add ()
{
	foreach my $pt (@Addpt) {
		if($Do_mount) {
			system "mount", $pt;
		}
		&add_target($Vol_id, $pt);
		if($Do_mount) {
			system "umount", $pt;
		}
	}
	return;
}

#
# Process -S
#
sub save_db ()
{
	my $db = Dumper($::DB);
	$db =~ s[^\$VAR1 = \{][\$::DB = \{]s; # }}

	open(OUT, "> $Db_file");
	print OUT "#!/usr/bin/perl\n", $db;
	close OUT;
	return 1;
}

sub convert_db ()
{
	my $ND = {};

	while (my($artist, $album_hash) = each %$::DB) {
		print "Converting artist \"", $artist, "\"\n";
		my $artist_utf = decode("utf-8", $artist);
		my $NA = {};
		$ND->{$artist_utf} = $NA;

		while (my($album, $title_hash) = each %$album_hash) {
			print "Converting album \"", $album, "\"\n";
			my $album_utf = decode("utf-8", $album);
			my $NT = {};
			$NA->{$album_utf} = $NT;

			while (my($title, $title_data) = each %$title_hash) {
				print "Converting title \"", $title, "\"\n";
				my $title_utf = decode("utf-8", $title);
				$NT->{$title_utf} = $title_data;
			}
		}
	}

	$::DB = $ND;
	return;
}

#
# Process -W
# Displays the database in a nice text-tabular format.
# show_db() is always executed after save_db(), so that bytes-per-artist
# are not stored in the database.
#
sub show_db ()
{
	my($total_files, $total_size) = (0, 0);

	printf "%-50s  %16s  LOCATION\n", "ARTIST / ALBUM / TITLE", "FILES / SIZE";
	print "-" x 160, "\n";

	#
	# Compute bytes-per-artist, bytes-per-album and total sizes
	# Will use "each" since order does not matter here.
	#
	my $stat = {};
	while (my($artist, $album_hash) = each %$::DB) {
		while (my($album, $title_hash) = each %$album_hash) {
			while (my($title, $title_data) = each %$title_hash) {
				++$total_files;
				$total_size += $title_data->[0];
				++$stat->{$artist}[0];
				$stat->{$artist}[1] += $title_data->[0];
				++$stat->{$artist}[2]{$album};
				$stat->{$artist}[3]{$album} += $title_data->[0];
			}
		}
	}

	# Now traverse the assoc arrays for printing
	foreach my $artist (sort keys %$::DB) {
		my $album_hash = $::DB->{$artist};
		my $indent = 0;
		if ($artist ne "") {
			printf "%-42s %25s\n", "$artist >",
			       sprintf "(%u files, %.1f MB)",
			       $stat->{$artist}[0],
			       $stat->{$artist}[1] / 1048576;
			$indent += 2;
		}
		# -o artist shows only ... artists
		if (defined $Opts{artist}) {
			next;
		}
		&show_albums($artist, $album_hash, $stat, $indent);
	}

	print "-" x 160, "\n";
	printf "%-50s  %16s  (%.1f MB, %.2f GB, %.2f TB)\n",
	       $total_files." files", &commify($total_size, "_"),
	       $total_size / (1024 ** 2), $total_size / (1024 ** 3),
	       $total_size / (1024 ** 4);
	return;
}

sub show_albums ()
{
	my($artist, $album_hash, $stat, $indent) = @_;

	foreach my $album (sort keys %$album_hash) {
		my $title_hash = $album_hash->{$album};

		if ($album ne "") {
			printf "  %-39s  %25s\n", "$album >",
			       sprintf "(%u files, %.1f MB)",
			       $stat->{$artist}[2]{$album},
			       $stat->{$artist}[3]{$album} / 1048576;
			$indent += 2;
		}

		if (!defined($Opts{album})) {
			# show_titles()
			my $len = 57 - $indent;
			foreach my $title (sort keys %$title_hash) {
				printf "%s%-*s  %9d  %13s %s\n", " " x $indent,
				       $len, $title, @{$title_hash->{$title}};
			}
		}

		if ($album ne "") {
			$indent -= 2;
		}
	}

	return;
}

sub commify ()
{
	# from perl manuals
	my $v = shift @_;
	my $sep = shift(@_) || ",";
	while($v =~ s/^([-+]?\d+)(\d{3})/$1$sep$2/) {
	}
	return $v;
}