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
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.