4 # sonynwput: scrambles an MPEG audio file for Sony Network Walkman
8 # sonynwput [OPTION] ... MPGFILE
13 # -k 0xDEADBEEF, --dvid 0xDEADBEEF:
14 # use this device id key to scramble
16 # -d DEVICEPATH, --device DEVICEPATH
17 # put file on the device mounted at DEVICEPATH
20 # scrambles for slot number N
23 # outputs to FILE instead of stdout
25 # MPGFILE: the file to scramble.
27 # It is mandatory to give slot. If DEVICEPATH is not given
28 # or there is no mp3fm/dvid.dat file on the device, a dvid
29 # needs also be given.
33 # File scrambled for slot number N has to be put in
34 # printf("OMGAUDIO\\10F%02x\\1%07x.OMA", N >> 8, N)
35 # on the device in order to be descrambled correctly.
37 # Currently the tool does its best to also copy tags in
38 # the way the device could read.
39 # However, please note that not all encodings are
40 # covered by the device charset.
46 # - VBR file support hasn't been tested yet and possibly is flaky or doesn't work at all.
47 # - Broken mpeg files produce OMA files which don't play at all.
51 # Please forward flowers and flames to RafaĆ Rzepecki <divided.mind@gmail.com>.
57 opts = GetoptLong.new(
58 [ "--slot", "-s", GetoptLong::REQUIRED_ARGUMENT ],
59 [ "--dvid", "-k", GetoptLong::REQUIRED_ARGUMENT ],
60 [ "--device", "-d", GetoptLong::REQUIRED_ARGUMENT ],
61 [ "--out", "-o", GetoptLong::REQUIRED_ARGUMENT ],
62 [ "--help", "-h", GetoptLong::NO_ARGUMENT ]
70 opts.each do |opt, arg|
81 outfile = File.new(arg, 'w+')
87 if device and not dvid
88 f = File.new(File.join([device, "mp3fm", "dvid.dat"]))
90 dvid = f.read(4).unpack("N")[0]
94 dir = sprintf "10f%02x", slot >> 8
95 fname = sprintf "1%07x.oma", slot
96 outfile = File.new(File.join([device, "omgaudio", dir, fname]), 'w+')
99 if !slot || !dvid || !outfile || !mp3file
103 mp3 = Walkman::Mp3.new(mp3file)
104 puts "Scrambling... "
105 mp3.write(outfile, slot, dvid)