SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SH4 Mods Workshop
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 07-16-22, 01:40 AM   #1
Ataraxzy
Watch
 
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
gear 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!
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:
Attached Images
File Type: jpg inifile format.jpg (97.3 KB, 13 views)

Last edited by Ataraxzy; 07-21-22 at 08:21 AM. Reason: Formatting.
Ataraxzy is offline   Reply With Quote
Old 07-18-22, 10:59 PM   #2
razark
Ocean Warrior
 
Join Date: Mar 2007
Location: Houston, TX
Posts: 2,727
Downloads: 393
Uploads: 12
Default

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!"
razark is offline   Reply With Quote
Old 07-19-22, 06:15 AM   #3
propbeanie
CTD - it's not just a job
 
propbeanie's Avatar
 
Join Date: May 2016
Location: One hour from Music City USA!
Posts: 9,911
Downloads: 444
Uploads: 2


Default

Quote:
Originally Posted by razark View Post
Pretty useful. I know I would have liked it a few years ago when I did it all by hand.
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!
__________________

"...and bollocks to the naysayers" - Jimbuna
propbeanie is offline   Reply With Quote
Old 07-19-22, 12:18 PM   #4
Ataraxzy
Watch
 
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
Default

Quote:
Originally Posted by razark View Post
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 View Post
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!
That's a great idea!

I just hope someone finds this useful.
Ataraxzy is offline   Reply With Quote
Old 07-20-22, 10:18 AM   #5
propbeanie
CTD - it's not just a job
 
propbeanie's Avatar
 
Join Date: May 2016
Location: One hour from Music City USA!
Posts: 9,911
Downloads: 444
Uploads: 2


Default

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!
__________________

"...and bollocks to the naysayers" - Jimbuna
propbeanie is offline   Reply With Quote
Old 07-20-22, 02:20 PM   #6
Ataraxzy
Watch
 
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
Default

Quote:
Originally Posted by propbeanie View Post
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!



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.

Last edited by Ataraxzy; 07-20-22 at 02:41 PM.
Ataraxzy is offline   Reply With Quote
Old 07-20-22, 02:49 PM   #7
propbeanie
CTD - it's not just a job
 
propbeanie's Avatar
 
Join Date: May 2016
Location: One hour from Music City USA!
Posts: 9,911
Downloads: 444
Uploads: 2


Default

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!
__________________

"...and bollocks to the naysayers" - Jimbuna
propbeanie is offline   Reply With Quote
Old 07-20-22, 03:15 PM   #8
Ataraxzy
Watch
 
Join Date: Apr 2021
Posts: 16
Downloads: 37
Uploads: 0
Default

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.



Ataraxzy is offline   Reply With Quote
Old 07-20-22, 03:33 PM   #9
propbeanie
CTD - it's not just a job
 
propbeanie's Avatar
 
Join Date: May 2016
Location: One hour from Music City USA!
Posts: 9,911
Downloads: 444
Uploads: 2


Default

Copy that! Will do.
__________________

"...and bollocks to the naysayers" - Jimbuna
propbeanie is offline   Reply With Quote
Reply

Tags
events, radio, scripts, sound mods


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:57 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.