How can I make use of subdir as a variable?
I'm having problems with the use of subdir as variable in a GiP command.

I'd like to copy a file automatically after each tv download using this command (set as a preference)

commandtv = cp /mnt/raid1/Media_Share/GiP_Downloads/Blank.hmi /mnt/raid1/Media_Share/GiP_Downloads/tv/"<subdir>/<fileprefix>.hmi"

But it runs into a problem like this :-
cp: cannot create regular file '/mnt/raid1/Media_Share/GiP_Downloads/tv/<subdir>/A Tattoo To Change Your Life Series 1_-_3. Covering My Mastectomy Scars.hmi': No such file or directory

Where am I going wrong?
Read the documentation on substitution parameters before formulating command strings. There is no <subdir> parameter, so it is ignored when the command string is processed.
Been there, done that.

Either I'm failing to understand the syntax of the substitution commands, or it's not meant to work as I think it should.

Whatever I type as a parameter, I always get the result returned, viz :-
get_iplayer --pid=p05tyfry --listformat fileprefix

That produces this :-
A Tattoo To Change Your Life: Series 1 - Covering My Mastectomy Scars, BBC iPlayer, p05tyfry

As does
--listformat dir

So I'm stuck. Sorry.
EDIT: Two Three problems:
  • Substitution parameters won't be recognised without angle brackets
  • --listformat is limited to fields in cache, which doesn't include <dir> or <fileprefix>
  • --listformat is for search results - it will be ignored when downloading with --pid
Again, read the documentation on substitution parameters. It tells you how to check values for a programme before downloading. However, you don't need to know the values to formulate command strings - that's the whole point of using them.
Ok. I'll give it another go.

Thanks for the pointers.
Still struggling with subdirs!

I'm trying to generate a subdirectory for a radio programme and failing - as usual.

If I look at "Tony Blackburn's Golden Hour - 06/07/2018 (b0b8bnzl)" and in particular the info, I can see this field :-
firstbcastdate: 2018-07-06 so my task is to generate a subdirectory of 'Tony Blackburn's Golden Hour' of the form 'yyyy'. I'm trying to do it with the following command :-
get_iplayer --type=radio --get 45418 --subdir --subdir-format="<nameshort>_<firstbcastdate:0:4>"

It's not working and all I get is a directory with the name 'Tony Blackburns Golden Hour_' and no subdirectory. Is it simply because it's a radio programme?

Also, why is there a trailing underscore in the directory name? I've noticed it in other radio downloads.
(07-07-2018, 10:57 AM)toner_cloud Wrote: It's not working and all I get is a directory with the name 'Tony Blackburns Golden Hour_' and no subdirectory. Is it simply because it's a radio programme?
It's because you're using an invalid substitution parameter in --subdir-format.
Quote:It's because you're using an invalid substitution parameter in --subdir-format

I'm thoroughly confused now then because both parameters, <nameshort> and <firstbcastdate> are both listed in substitution parameters and indeed the docs say '--subdir-format <format> : The format to be used for subdirectory naming. Use substitution parameters in format string (see docs for list)' and I *thought* I was using substitution parameters.
Making *some* progress.

If I use the following :-
get_iplayer --type=radio -g 35020 --subdir --subdir-format="<nameshort>/<firstbcastdate>"
I get a Click folder with a subfolder with the name '2018-06-26' but it all goes wrong when I try to use <firstbcastdate:0:4> as I don't get any subfolder then.

Is there a way to extract the year from the date in the way I desire or do I have to add some more code of my own to do that?
Physician heal thyself - just in case somebody else wants a similar solution.

Doubtless the code could be improved. I think I've left it too late to learn coding now but it works for me.

subdir=$(ls /mnt/raid2/Media_Share/GiP_Downloads/Click) ; short="${subdir:0:4}" ; mv /mnt/raid2/Media_Share/GiP_Downloads/Click/$subdir /mnt/raid2/Media_Share/GiP_Downloads/Click/$short

I've saved it as a preset so can call it as and when needed.
That will fail when you download another episode in the series, so I suspect you have left something out. Show a full command so others can evaluate it properly.
That's the complete command for that part of the operation.

Perhaps I should explain my setup. All GiP downloads go into a GiP_Downloads folder which is then split into radio and tv. But each episode of a programme, be it radio or tv then has another script run to move it into either into a separate folder on the NAS (in the case of tv programmes) or on to a separate drive in the case of a radio file. That script checks for the existence of a folder with the same name and if it doesn't exist, the whole folder, with sub-folder gets moved. If it does exist, the script checks for the existence of a sub-folder with the same name as the new one my latest script creates. If there's no sub-folder, that gets moved to the relevant location and of course the downloaded file gets moved too. If there is a sub-folder then just the files get moved, be they m4a or mp3. The (by now) empty folders in the GiP_Downloads folder are then deleted.

I do have one more script which copies in a .hmi file from the NAS for an M4A file as they get played on one of my Humax machines and they use an HMI file to track play time. That was where I started with this, trying to find a solution for the Blank.hmi file copy routine.

Taking note of your comment, I agree that if there is an existing folder/sub-folder structure in existence, my routine will indeed fail. I might have a crack at adapting my copy procedure outlined above to cope with such an occurrence. If I make it work, I'll post back here for the benefit of others.
I see that in the latest release, v3.17, my code is redundant as there are some new fields being exposed. Extract from the release notes says :-
Added additional substitution parameters: <firstbcastyear, <firstbcastmonth>, <firstbcastday>.

So all I can say is, Many thanks. Much appreciated.

Possibly Related Threads...
Thread Author Replies Views Last Post
  Subdir format for "Top Gear: Best of" not working as expected toner_cloud 1 1,180 17-12-2018, 12:14 PM
Last Post: toner_cloud
  Correct use of "--subdir-format" spncrgr 8 5,806 04-02-2014, 08:12 AM
Last Post: spncrgr