I need to make a shell script that uses jq to rename below mp4 file(s). (could have use jasonpipe but didn't know how to install it on mac)

File Dowloaded:

  1. title1-1000221327.mp4
  2. title1-1000221327.info.json
  3. title1-1000221328.mp4
  4. title1-1000221328.info.json

I want to rename file 1&3 by extracting from above respective json file (2&3):

  • "series": "ShowName", as ShowName
  • "season_number": 1, as "S01"
  • "episode_number": 6, as "E006"
  • "title": "title1", as title1

also insert space & - between these four variables " "-" "

After rename file should be:

ShowName - S01E006 - title1.mp4

contents of "title1-1000221327.info.json"

Edit: thanks for the tip: solved the jq portion sofar

jq '"\(.series) - S0\(.season_number)E00\(.episode_number) - \(.title).mp4"'
"description": "Bla Bla Bla",
"episode": "title1",
"episode_number": 6,
"season": "Chapter 1",
"season_number": 1,
"series": "ShowName",
"title": "title1",
"upload_date": "20181006"

P.S. my question is base on this question: Rename files based on JSON content

  • 2
    Possible duplicate of Rename files based on JSON content – Prvt_Yadav Apr 29 at 0:41
  • In your initial data, the filename of the MP4 file was actual part of the JSON. Is that not the case any longer? That would have made it quite a bit easier to rename the files. – Kusalananda Apr 29 at 6:53
  • by the way what you're trying looks most likely illegal. – Kiwy Apr 29 at 9:11
  • Since this Questioner does not know how to install jsonpipe, the answer at unix.stackexchange.com/questions/283690/… cannot apply. An answer should be provided here, possibly linking to the other solution. – Jeff Schaller Apr 29 at 12:30

I would make it with the find command in Linux to get the filenames out and parse it move the files to the new file name out called from jq.

I hope I can write tomorrow an example for you.

(My English is not the best)

Hope that helps you a little bit out for the start


Edit: use it with this command: find (your path to the files) -type f -name „*.mp4“ -exec mv {} (your new path of the files)(the strings out of the jq array) \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.