Project

General

Profile

Feature #5189

Add the option to use "Name" from autorec for sub-directories instead of the title.

Added by Joe User about 6 years ago. Updated about 6 years ago.

Status:
New
Priority:
Normal
Assignee:
Category:
PVR / DVR
Target version:
-
Start date:
2018-09-03
Due date:
% Done:

0%

Estimated time:

Description

I recently sorted my recordings from a single directory to sub-directories using the program title. While doing so, I noticed a lot of inconsistencies with the titles of programs. Mostly just capitalization changes, but also occasional spelling mistakes. When I set the recording profile to use the program tittle as the sub-directory name, I end up with multiple sub-directories for the same program because of these differences. For example:

"the Cat in the Hat Knows a Lot About That" 
"The Cat In The Hat Knows a Lot About That" 
"The Cat in the Hat Knows Alot About That" 

While the regex matching works fine for the autorec, recordings end up in different sub-directories. These differences can occur when recording the same program on different channels and/or for different providers, when using different EPG sources, and sometimes simply broadcaster/EPG provider errors.

It also would let one shorten long titles for the sub-directory name to something like:

"The Cat in the Hat" 

Another case would be similar programs one would like grouped together with similar titles, with titles such as:
"Program:subtitle" 
"Program:different subtitle" 
"Program:yet a different subtitle" 

Again, a regex can be made to match all, but they would end up in different sub-directories.

Maybe add an option "%a" for autorec name which could be used to build the path:

Format string/Pathname specification:  $a/$t %F %R.$x

And/or a checkbox for it:

Make subdirectories per autorec name : Create a directory per autorec name when storing recordings. If the day/channel directory checkboxes are also enabled, those directories will be parents of this directory.

I know I can make separate recording profiles, but that is a lot of work since I currently have more than 50 autorec entries. It would also be a lot to maintain - for instance, in case you needed to change the stream profile.

BTW - it does not necessarily have to be the autorec name, it could be a new field.

I looked in dvr_autorec.c and dvr_rec.c and think it would not be too difficult to add, but I am not sure about all the interconnected ramifications when making changes. Of course if there is not much interest in this, I will give it a shot on my own...

As a side note, wouldn't it be more logical to put the "Digital Video Recorder Profiles" tab under the "Digital Video Recorder" tab instead of under "Configuration/Recording"???

History

#1

Updated by Em Smith about 6 years ago

The only minor problem is that if you hit record on a tv programme (such as from the epg) then it would use the same path specifier (by default), but it would presumably not be an autorec, so $a would be empty, so those recordings would end up in the root of that storage.

Of course the user could create a separate recording profile for epg and autorec records; or perhaps $a should fallback to being title if not an autorec?

#2

Updated by Joe User about 6 years ago

Em Smith wrote:

The only minor problem is that if you hit record on a tv programme (such as from the epg) then it would use the same path specifier (by default), but it would presumably not be an autorec, so $a would be empty, so those recordings would end up in the root of that storage.

Of course the user could create a separate recording profile for epg and autorec records; or perhaps $a should fallback to being title if not an autorec?

Yes, certainly if the name filed is empty, the title should be used. And if you do not like that fallback. you could create, as you suggest, a separate record profile for autorec.

I may prefer them to go into the root record directory, then I could later manually move them to the directory I want. With inotify, tvheadend will automatically see the move and update the database (sic) to reflect the new location.

BTW - I made a quick hack to dvr_inotify to recognize the creation of a new directory in a watched directory and add it to be watched. With this hack I was able to create 50+ subdirs and move my 3000+ recordings into them without having to manually modify any dvr log files and restart tvheadend... I did this because I was not sure when (or if) this feature would be implemented. [[https://tvheadend.org/issues/3763]]

#3

Updated by Em Smith about 6 years ago

The dvr_inotify sounds really useful to me for when people tidy up their recordings. If you have time, submit it as a pull request.

I split my recordings by "age rating" once thinking it would be a good idea, but un-splitting/tidying it was a pain.

I think there is some issue with inotify with too many watches, but I don't think the change would add many more watches than we have already.

Hm. A check suggests /proc/sys/fs/inotify/max_user_watches is the maximum, which on my system is 8192. I guess that's global, even so, it's unlikely to be hit with many dirs being watched, so should be ok. I don't know what the limit is on the LibreElec platforms.

I guess watching the whole hierarchy means it will also handle the case where your "mv 'the cat' 'The Cat'"?

Re: $a, yes, I don't mind either way (I never record from EPG so it would never affect me), so I don't know what other people prefer as the default. I can see people could want either way, or even in to a "no-autorec", directory. Submit however you think best, and people can always comment or add modifiers in the future.

I don't know if you know about the "Directory" field in autorec (might be hidden in expert options), but I think your $a would be easier for most people to just globally change recordings.

#4

Updated by Joe User about 6 years ago

Em Smith wrote:

I don't know if you know about the "Directory" field in autorec (might be hidden in expert options), but I think your $a would be easier for most people to just globally change recordings.

Ahh, no I did not, thanks! I have expert mode, but the line was below the bottom of the screen. (another small annoyance with the webif...)
Anyway, yes, that does pretty much what I want - just a little more work to fill it in for my 50+ autorec instead of using the already filled in "name". But a small script should do most of the work.

I guess this feature request can be closed unless, like you said others feel the $a would be a better way to implement...

(I will post about the inotify stuff in the forum later when I get a chance...)

#5

Updated by Em Smith about 6 years ago

The tool "jq" is your friend (though not something I use often enough to offer an example). There are some examples on the forum somewhere. Personally I'd just try using sed or perl on the autorec files when tvheadend isn't running, but after taking a backup for when it didn't quite work...

[[https://stedolan.github.io/jq/]]

Something like this on an autorec file may get you close:

 perl -nape 'print qq/        "directory":$F[1]\n/ if $F[0] eq qq/"name":/' < MYFILE > MYFILE.new

(Followed by diff to make sure it's ok, then mv it back, where MYFILE is your autorec filename).

#6

Updated by Joe User about 6 years ago

Thanks.

I usually use sed (with in-place) to change paths in the dvr/log files which is easiest for multiple files.
For example, when I changed the mount point for some of my recordings, I used something like:

sed -i 's/old\/path\/new\/path/g' /home/hts/.hts/tvheadend/dvr/log/*

But I already had a script I used to change the "comment" field from the default "Created from EPG query" to the title.

#!/bin/bash

cp -rp autorec autorec.sv

for file in autorec.sv/*
do
    fname=$(basename "$file")
    jq '.comment = .title + "  - AUTOREC" ' $file > autorec/$fname
done

Which I now modified to:

#!/bin/bash

cp -rp autorec autorec.sv

for file in autorec.sv/*
do
    fname=$(basename "$file")
    jq '.directory = .name' $file > autorec/$fname
done

Then to check, use:

diff -r autorec autorec.sv |less

Note that if "directory" does not exist, it will be added. Yes, it would be nicer to insert a new "directory" to where it usually is instead of appending it to the end, but another day... :)

#7

Updated by Em Smith about 6 years ago

Fantastic. That's nice and easy with jq and saves messing about with quotes in perl.

Also available in: Atom PDF