SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997 |
07-16-22, 01:40 AM | #1 |
Watch
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
|
Tired of Missing Broadcasts? Me too!
The Events folders in the various sound mods are fabulous, and really let you relive history. The only problem with them is that unless you've painstakingly gone through every. single. entry. of. every. events.ini file, they come and go with nary a peep to let you know. Sure, there are big days like D-day, Sevastopol, Guadalcanal and so on that everyone knows, but what about speeches? What about listening to old-time radio shows in the order they were broadcast?
You can have the game send you a radio message when an EVENT happens. If there's an entry in a radio folder's event.ini, the game will do TWO things: 1. it'll start playing the appropriate sound file and 2. if there's an accompanying full.sound.file.name.ini for that sound file, and it's properly formatted as follows: Code:
[NEWS] Title=Whatever You Want Your Title To Be Body=Put the body text of your new radio message here! But Raaaaaax, you say, some of us have thousands of files in various Event folders. That's weeks worth of thankless work! Well, yes. Unless you automate it. With scripts! First off, I'm a Linux sysadmin, not a Windows one, so while these could be rewritten in PowerShell (or, as I like to call it, PowersHell), I wrote them in bash. There are an abundance of ways to get a proper bash command line on a windows PC, but details on how to accomplish that are beyond the scope of this post. Google for WSL2, Git for Windows or MinGW if you're looking to start. Or, go to the Microsoft Store, type in "Ubuntu" at the search bar and grab the latest and greatest. Problem: You've got to create thousands of files, with names that match thousands of source files. Then you've got to fill those thousands of new files with "stuff". First, let's normalize the file names. Music filenames are the absolute worst. Everyone's got their own 'method', sometimes two, and nobody's method is the same as anyone else's. Oh, and song names are linguistic phrases and sentences, explicitly the opposite of nice, standardized variable names. They have all sorts of awful things in them, for example, single quotes for all the "You'll"s and "I'll"s and so on. Scripting languages use quotes for more than separating letters, so we need to remove them. First, remove them from the events.ini file. Open in your favorite text editor and find/replace all "'" with "". (that's "find/replace all single quotes with nothing.") Next, we run a little two-liner in our Events directory: Code:
$ shopt -s globstar $ find -name **" -type f -exec rename "s///g '{}' \; Now, we want to create new .ini files to match all the .mp3/.ogg/.wav files in the Events directory. Another one liner, again run from the Events directory: Code:
$ ls *.mp3 | xargs -IX touch X.ini k, now we have a folder populated with the following: sound files. sound.mp3.ini files and a single event.ini file. Time to fill those .mp3.ini files with actual information. We're going to write a script to do it. create a file, use your favorite text editor to populate the file with the following, and finally, don't forget to chmod +x the file so that you can actually run it: Code:
#!/bin/bash mv events.ini .. #move the events.ini file up one directory level for file in *.ini; do echo "[NEWS]" >> "$file" echo "Title=StationName Broadcast" >> "$file" echo "Body=Channel: NN.NN" >> "$file" done mv ../events.ini . #move the events.ini file back And that's it. Now you'll get a radio message every time an event fires from that radio station. Here's a pic of the end-state: Last edited by Ataraxzy; 07-21-22 at 08:21 AM. Reason: Formatting. |
07-18-22, 10:59 PM | #2 |
Ocean Warrior
Join Date: Mar 2007
Location: Houston, TX
Posts: 2,727
Downloads: 393
Uploads: 12
|
Pretty useful. I know I would have liked it a few years ago when I did it all by hand.
__________________
"Never ask a World War II history buff for a 'final solution' to your problem!" |
07-19-22, 06:15 AM | #3 |
CTD - it's not just a job
|
Exactly!! lol - much easier to use the Delete key to get rid of those you don't want / need, than to have to find and build the ones you want. Very nice, Ataraxzy!
|
07-19-22, 12:18 PM | #4 | ||
Watch
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
|
Quote:
That's how this started, but I looked at the nearly 100Gb of sound files I'd downloaded and silently cried. Then I went, "Waitaminute... I can automate this." Quote:
I just hope someone finds this useful. |
||
07-20-22, 10:18 AM | #5 |
CTD - it's not just a job
|
This idea is definitely useful to me, Ataraxzy. I just have to remember to bookmark this, so I can find it later when we go to do a radio mod... Thank you again!
|
07-20-22, 02:20 PM | #6 | |
Watch
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
|
Quote:
Here's another oneliner to help you out: Code:
grep -r "mm\.dd\.yyyy" -A 1 If you want, I've downloaded ~67gb of Radio files from various mod sources. I could upload them somewhere in chunks. All the work is already done, all you'd have to do is download them. Code:
grep -r "\.yyyy" -A 1 examples: Code:
$ grep -r "06\.12\.1941" -A 1 KGMB/Events/events.ini:StartDate=06.12.1941 KGMB/Events/events.ini-StartTime=19.30.00 -- KLVW/1941/Events/events.ini:StartDate=06.12.1941 KLVW/1941/Events/events.ini-StartTime=17.00.00 -- KNX/1941/Events/events.ini:StartDate=06.12.1941 KNX/1941/Events/events.ini-StartTime=15.45.00 $ grep -r "\.1939" -A 1 DHB/Events/events.ini:StartDate=12.09.1939 DHB/Events/events.ini-StartTime=12.00.00 -- DHB/Events/events.ini:StartDate=01.10.1939 DHB/Events/events.ini-StartTime=12.00.00 -- DHB/Events/events.ini:StartDate=01.11.1939 DHB/Events/events.ini-StartTime=12.00.00 ... ... in the oneliner: -A 1 gets you the "following line" -B 1 gets you the "preceding line" -C 1 gets you BOTH. increase the number to get more than just the next/previous lines. Last edited by Ataraxzy; 07-20-22 at 02:41 PM. |
|
07-20-22, 02:49 PM | #7 |
CTD - it's not just a job
|
Thanks for the offer of the broadcasts, but I already have most that I use, but I'm building one that would definitely benefit from your scripts... excellent, and sorting by date is good too! Thank yoiu!
|
07-20-22, 03:15 PM | #8 |
Watch
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
|
Kick ass!
Lemme know when it's done, I wanna see it! And if you have any questions, have an idea for another oneliner, lemme know. |
07-20-22, 03:33 PM | #9 |
CTD - it's not just a job
|
Copy that! Will do.
|
Tags |
events, radio, scripts, sound mods |
|
|