SUBSIM Radio Room Forums

SUBSIM Radio Room Forums (https://www.subsim.com/radioroom/index.php)
-   SH4 Mods Workshop (https://www.subsim.com/radioroom/forumdisplay.php?f=219)
-   -   [TEC] Tired of Missing Broadcasts? Me too! (https://www.subsim.com/radioroom/showthread.php?t=253139)

Ataraxzy 07-16-22 01:40 AM

Tired of Missing Broadcasts? Me too!
 
1 Attachment(s)
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!

The game will send a radio message to you that appears on your clipboard, letting you know that there's a broadcast you might want to listen to.


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 '{}' \;

Boom. No more single quotes.

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
change *.mp3 for *.ogg or *.wav as needed to get all the files.


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

For each radio station Events folder, change the echo lines to information that is appropriate, like the Station Name and the Channel number. Then, run that script in the Events folder.

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:

razark 07-18-22 10:59 PM

Pretty useful. I know I would have liked it a few years ago when I did it all by hand.

propbeanie 07-19-22 06:15 AM

Quote:

Originally Posted by razark (Post 2818724)
Pretty useful. I know I would have liked it a few years ago when I did it all by hand.

:har: 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! :salute:

Ataraxzy 07-19-22 12:18 PM

Quote:

Originally Posted by razark (Post 2818724)
Pretty useful. I know I would have liked it a few years ago when I did it all by hand.


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:

Originally Posted by propbeanie (Post 2818762)
:har: 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! :salute:

That's a great idea!

I just hope someone finds this useful.

propbeanie 07-20-22 10:18 AM

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! :salute:

Ataraxzy 07-20-22 02:20 PM

Quote:

Originally Posted by propbeanie (Post 2818953)
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! :salute:




Here's another oneliner to help you out:


Code:

grep -r "mm\.dd\.yyyy" -A 1
Run that in the .../Radio subfolder. It will return all StartDate and StartTime for the particular day you've put in. (Or return nothing if there's nothing scheduled for that day.)

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
Will get you everything that matches that particular year


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.

propbeanie 07-20-22 02:49 PM

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!

Ataraxzy 07-20-22 03:15 PM

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.



:Kaleun_Cheers:

propbeanie 07-20-22 03:33 PM

Copy that! Will do. :salute:


All times are GMT -5. The time now is 04:59 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 1995- 2024 Subsim®
"Subsim" is a registered trademark, all rights reserved.