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

    • harsh3466@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 months ago

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

  • pcouy@lemmy.pierre-couy.fr
    link
    fedilink
    arrow-up
    9
    arrow-down
    1
    ·
    11 months ago

    Github is not really independent from Git, it’s a git provider. (you could see it as Github being to Git what Gmail is to e-mails)

    • harsh3466@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      11 months ago

      That makes sense. I couldn’t come up with quite the right wording to distinguish between them when I was writing up the post.

  • PlexSheep@feddit.de
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    11 months ago

    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.

    • harsh3466@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      10 months ago

      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.

    • harsh3466@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      5
      ·
      11 months ago

      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.