Another fun week of tinkering! Here’s what I learned:
How to implement a for loop in bash scripts using seq
.
I’ve been working on a script to create folders for my tv show library to play nice with my Jellyfin server. What I wanted was for the script to:
- prompt me for the show’s name
- query The Movie Database: Shows api for the show
- present me a numbered list of the show results formatted as
index showname year tmdb-id
- prompt me to choose the correct result from the list
- create a directory formatted as
Show.Name.(YYYY).[tmdbid-xxxxx]
Since the number of results will vary from query to query, I couldn’t use a preset range like {0..5}
for my for loop. I tried without success to have the loop iterate through the JSON response, but I was unable to figure out how to do that.
So, while likely inelegant, What I did was:
- take the JSON response and pipe it to
jq
, get the number of results - Since
jq
indexes start with 0, take the number of results and subtract 1, setting the results of that calculation as my$count
variable - loop through the JSON using
for i in $(seq 0 $count) ; do
to create the indexed list of results to choose from
How to use jq
to work with and extract data from JSON objects
I’m just scratching the surface of jq
, but I’m finding it very useful! I’ve worked with JSON before making automations on iOS with the Shortcuts app, so getting up and running with jq
was pretty easy once I understood the syntax.
Note: I know tools like Filebot exist to do the kind of thing I’m doing with this script. I’m writing my own scripts from scratch in order to learn
Git and Github are different things
On my post last week a number of people suggested using Git. I already was aware of Github, and because I didn’t know what I didn’t know, I thought Git and Github were parts of a whole. I also generally knew that Git/Github are used for version control, but that was the extent of my knowledge. I still know very little, but I do now understand that Git and Github are independent things that can work together.
I also went ahead and set myself up a gitea instance on my server for when I’m ready to create repositories for myself for my scripts and dotfiles
Github is to git what Pornhub is to porn
Nice anaolgy!
really confused with the grubhub business model right now
bootloaders?
I’m making up Lemmy Gold to give you as a reward for these posts. Thank you!
I thought this was gonna be a “this comment can only be viewed by lemmy gold subscribers” thing
That wouldn’t be very “Lemmy”, imo.
Thank you! I’m glad you enjoy them! They help me keep my own thoughts and progress organized. I had been jotting this stuff down in notes for myself, then I thought, “hey, I might as well share this on Lemmy while I’m at it.”
Cool post, didn’t know about jq and seq. Keep the learning up! Your little series is really nice here.
I also went ahead and set myself up a gitea instance on my server for when I’m ready to create repositories for myself for my scripts and dotfiles
A little question, do you have really really specific skills, or how does it come that you don’t know git but are able to selfhost gitea? Just really proficient with orchestration tools like docker?
Since you host gitea you might want to know. Forgejo and Gitea are almost the same software, Forgejo is a “soft fork” of Gitea maintained by Codeberg, a very pro open source non commercial Organisation pushing for federalization of “code forges”. Think Lemmy/fediverse but for Git Servers.
Thank you (switched to an lemmy.ml account because I haven’t been able to comment or post on lemmy.world for over a week)
Not really specific skills, I’m just a hands on learner/tinkerer. I’ve been messing with self hosting for around three years now, so spinning up new docker services is fairly easy (fairly. I still have a lot to learn about docker). In doing so, I’ve used and referred to github a lot, and even used git to clone repositories for self hosting a service, but beyond that, I hadn’t looked into it as it didn’t seem relevant to me at the time.
And thank you for the Forgejo information! I will look into that and compare to see which one I’d like to use. Coincidentally I just saw today or yesterday that Forgejo has gone for a hard fork.
Did you try sonarr to manage your series library?
I haven’t. I’m aware of the *arrr stuff, but as I mentioned in the post, I’m writing these scripts to learn. I have no illusions that what I’m doing is better than *arrr or filebot or whatever else might be out there, I just like working on projects as a way to learn.