Add a few more scripts
This commit is contained in:
parent
95644ad0bb
commit
c391ebd812
4 changed files with 37986 additions and 0 deletions
9
convert-all-songs
Executable file
9
convert-all-songs
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
for file in *.mp3; do
|
||||
echo "* Converting $file to ${file%.mp3}.m4a..."
|
||||
rm -f "${file%.mp3}.m4a"
|
||||
"${BASH_SOURCE[0]}/../convert-song" "$file" >/dev/null 2>&1
|
||||
done
|
||||
18
convert-song
Executable file
18
convert-song
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
input="$1"
|
||||
if ! [ -r "$input" ]; then
|
||||
if ! [ -z "$input" ]; then
|
||||
echo "[error] File not found: $input"
|
||||
else
|
||||
echo "usage: $0 <input mp3>"
|
||||
echo
|
||||
echo "Converts an mp3 to an m4a (AAC) and reduces the bitrate to 128 kbps."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# -vn drops video on the floor, required for source mp3s with artwork
|
||||
ffmpeg -i "$input" -vn -c:a aac -b:a 128k "${input%.mp3}.m4a"
|
||||
57
crunch-android-devices.rb
Executable file
57
crunch-android-devices.rb
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env ruby -w
|
||||
|
||||
require 'csv'
|
||||
|
||||
HEADERS = %w[device_name sessions].freeze
|
||||
|
||||
DEVICES_PATH = File.join(__dir__, 'supported_devices.csv')
|
||||
|
||||
# Maps device model to name using Google's giant CSV that lives alongside this file.
|
||||
DEVICE_MAP = CSV.foreach(DEVICES_PATH).each_with_object({}) do |row, map|
|
||||
# skip the first header row
|
||||
next if row[0] == 'Retail Branding'
|
||||
|
||||
# columns: Retail Branding (maker), Marketing Name, Device (unused), Model
|
||||
maker = row[0]
|
||||
name = row[1]
|
||||
model = row[3]
|
||||
map[model] = "#{maker} #{name}"
|
||||
end
|
||||
|
||||
def main
|
||||
in_csv = CSV.new(ARGF)
|
||||
sessions_by_device = count_devices(in_csv)
|
||||
render_csv(sessions_by_device)
|
||||
end
|
||||
|
||||
def zero_hash
|
||||
Hash.new { |_k, _v| 0 }
|
||||
end
|
||||
|
||||
def count_devices(in_csv)
|
||||
# skip the first header row
|
||||
in_csv.drop(1).each_with_object(zero_hash) do |row, h|
|
||||
# devices come in a raw model and we have to look up the marketing name for each one
|
||||
# e.g. SM-S908N and SM-S908U are 2 of 9 models of the Galaxy S22 Ultra line
|
||||
device_model = row[0]
|
||||
device_name = DEVICE_MAP[device_model] || device_model
|
||||
|
||||
# Skip things that are obviously not Android
|
||||
next if device_name =~ /iphone|ipad/i
|
||||
|
||||
h[device_name] += 1
|
||||
end
|
||||
end
|
||||
|
||||
def render_csv(sessions_by_device)
|
||||
puts CSV.generate_line(HEADERS)
|
||||
sessions_by_device
|
||||
.sort_by { |_device, sessions| sessions }
|
||||
.reverse
|
||||
.each do |device_name, sessions|
|
||||
out_row = [device_name, sessions]
|
||||
puts CSV.generate_line(out_row)
|
||||
end
|
||||
end
|
||||
|
||||
main if $PROGRAM_NAME == __FILE__
|
||||
37902
supported_devices.csv
Normal file
37902
supported_devices.csv
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue