Project

General

Profile

Move existing recordings to new subdirectories

Added by Davor Komljenovic 18 days ago

Hello,

I am running the latest release of Tvheadend 4.3-1855. I am thinking of modifying the recording format string so that TV shows and Movies are in separate subdirectories. I need to do this so that Kodi can efficiently import all recordings into its library. For this importing to work, I have to have separate directories for TV shows and Movies.

I change these settings in the Recording profile and all new recordings will be separated. But how do I move the existing recordings in Tvheadend? I know which ones are Movies and which ones are TV shows so I can manually copy/move files but then I am assuming Tvheadend will lose these recordings from its database.

How can I do this?


Replies (6)

RE: Move existing recordings to new subdirectories - Added by Joe User 17 days ago

I am not sure what system/os you are running on, but if it supports inotify, then it can be done automatically by tvheadend if the following is TRUE:

The destination directory must ALREADY have at least one recording from tvheadend.

Via inotify, Tvheadend monitors all directories which contain recordings - it does not use inotify to monitor individual files. When a file is moved, it generates two inotify events - IN_MOVED_FROM and IN_MOVED_TO. A IN_MOVED_FROM event is generated for the existing directory, which tells Tvheadend which file in the directory is being moved, and a linked (by cookie) IN_MOVED_TO event is generated for the directory to which the file is moved (destination directory). HOWEVER, if Tvheadend is not monitoring the destination directory, it will never receive the IN_MOVED_TO and thus not update the new file location in the database (dvr log files). So, in order for Tvheadend to detect the "move", it MUST be monitoring the destination directory - which is only the case if there is already an existing recording there.

If you do not have any new recordings in the new folders yet, you can make a short, temporary recording in the new folder before trying to move your other recordings.

To monitor inotify activity, enable the trace option "dvr-inotify". Certainly I would try moving just one file first and watch the trace log and make sure the recording does not get moved to the "removed recordings" tab of dvr. If that happens, you can move the file back, however Tvheadend won't notice the file has been returned until it is restarted.

Note, it "should" handle bulk moves, but depending on your system/os it is possibly that moving too many files at once will cause some events to be missed.

Also note, your version contains the fix I made last year (https://tvheadend.org/issues/5188) but for those using older versions, it is best to avoid bulk moves...

RE: Move existing recordings to new subdirectories - Added by Joe User 17 days ago

I see from previous posts that you build your own tvheadend. In that case, you may be interested in this patch. It is what I did a long time ago when I was going through the same process of creating multiple subdirs for a few thousand recordings. With this patch, if you create a subdir in a already tvheadend "watched" directory, it will create a "dummy" recording for that directory and thus tell tvheadend to also monitor that directory. So, when my script which automated my moves ran, tvheadend automatically updated all the dvr log files to point to the new locations. Note: you will see some "dummy" recordings in your "removed recordings" tab which can be deleted after completing the moves.

Just use:

git apply dvr_inotify.patch.diff

RE: Move existing recordings to new subdirectories - Added by Davor Komljenovic 17 days ago

This is very cool. Thank you very much. If I decide to do this, I will try your patch.

RE: Move existing recordings to new subdirectories - Added by Davor Komljenovic 17 days ago

One additional question. Can I also change the file name of the recordings? For the scrapper in Kodi to work well, it needs file names of TV show recordings to contain Season and Episode numbers. My current recordings have default file names and I would then have to change file names also. With your above explanation, will it also work if I change the file names?

RE: Move existing recordings to new subdirectories - Added by Em Smith 17 days ago

Yes, it will handle file rename too. Since you are compiling yourself, make sure you compiled with the libinotify support. I assume your disk with recordings on is local to XU4, so everything should just work.

I would check with one file first to ensure everything is working. You should see the entry in the dvr/log directory updating after a few seconds.

Most important is what Joe says about bulk moves.

I'd also take a backup copy of your dvr/log directory before you start (it contains details of all your recordings) so that any problems can easily be fixed by restoring the broken entry.

Also, Kodi will only import media for which a lookup succeeds. So, it will work for "The Simpsons S01E01", but won't work so well for "Evening News."

RE: Move existing recordings to new subdirectories - Added by Joe User 16 days ago

Note there are three possibilities of failure if inotify is "overwhelmed" by too many moves too quickly. (again system dependent...)

1. Tvheadend receives MOVED_FROM but not MOVED_TO - in this case Tvheadend doesn't know where the file went, so marks it as being removed and the recording will show up in "removed recordings"

2. Tvheadend receives MOVED_TO but not MOVED_FROM (very unlikely...) - in this case Tvheadend ignores it because it would not be able to find the matching log for the recording. In this case Tvheadend will not immediately mark the file is removed, but if you try to play it, or on restart, Tvheadend will not find it where it should be and then will mark it a removed.

3. Tvheaded doesn't receive any inotify events - in this case Tvheadend does the same as for 2.

In any case, any failures will end up in "removed recordings". Then you could either move those files back and restart Tvheadend so it sees them, then try to move them again. Or shutdown Tvheadend and manually edit the dvr log files and fix the recording location.

For those who do not have inotify, you can move your files by using the "dvr/entry/filemoved" api to tell Tvheadend about the move.
(https://github.com/dave-p/TVH-API-docs/wiki/Dvr)

Some info here: https://tvheadend.org/boards/5/topics/39239
but there may be better examples to be found by a search. :)

    (1-6/6)