ascagnel / mythPlex

Convert MythTV recordings to XBMC/Plex compatible names using the built-in MythTV APIs
Other
14 stars 14 forks source link

Link Checking #12

Open ascagnel opened 9 years ago

ascagnel commented 9 years ago

Check to see that the target of a given link still exists, in case MythTV has auto-deleted it.

c2dalark commented 9 years ago

So I think there are a couple of ways that we can go about this.

If the item is still in the MythTV database, but the media has been deleted, after the check against the library for repeats, we can use the oprhan logic check, build the symbolic link, then delete that link. I'm not really certain about how long MythTV holds an entry in the database once the media has been deleted, but this is definitely the easiest path to implement.

If the item has been deleted from the MythTV database, I think that we would just have to check for symbolic links within the Plex folders, see if they are valid, and then delete them if they aren't. So a lot more interaction with the file system than currently occurs.

In both methods, I think that there would be a need to cleanup removed ids from the library file, in case an episode is re-recorded at a later date.

ascagnel commented 9 years ago

MythPlex doesn't directly query the MythTV database; instead, it uses the Services API, specifically the GetRecordedList function. This should only return the active recordings (eg: recordings that are marked as having been recorded, regardless of whether or not they currently sit on disk).

Can you provide a log example that I can work from? The link functionality was something I added early on; I mainly use the transcoding functionality to archive.

c2dalark commented 9 years ago

I don't use symlinks either, I've just played with them when I was working on the sorting functionality, since it ran faster, and to make sure the logic worked for all cases. So I don't have a log to work from.

On the Myth side of the things, when I deleted something from the MythWeb Recorded Programs page, the recording got moved into the recording group Deleted. On the API side of things, it would no longer show up in a query to the Recorded list, but shows up on the Expiring list. Then the program sits in that recording group until it is deleted. I've been searching around, and it looks like that time is set by the 'Time to Retain Deleted Recordings' setting on the MythBackend. Once it is deleted, it doesn't show up in any API call that I have found. I don't use the MythFrontend anywhere in my setup, but I believe the process is the same once a recording has been marked for deletion.

So, if the script is run in the window of time where a recording has been marked for deletion but not deleted yet, we could remove the symbolic link pretty easily. We could also remove it easily if the database entry is an orphaned one, where the file has been deleted, but recording entry hasn't been updated. However, I don't see a way to find links for recordings that were cleanly deleted in the database, other than going through the directories. I also don't even know how we would go about doing this.

I don't really have logs for any of this research, I just opened up a tab and watched the GetRecordedList and GetExpiringList results as I started removing recordings from my backend.

We could implement the functionality mentioned above, but have the caveat that in order for MythPlex to catch the deleted recordings, it must be run in that window of time, and recommend upping the 'Time to Retain Deleted Recordings Option'.

Another option would be to store a list of created symlinks in another library type file, and just verify that everything in that list is still valid, deleting the link if it isn't. That's probably the simplest way to do it.

ascagnel commented 9 years ago

I poked into this a little more, and I don't see an explicit way to determine if the user has deleted a recording. If they have, the recording will still appear in the response to GetRecordedList, not GetExpiringList. The blob of XML below contains two recordings -- the first one still exists, the second has not.

The other issue I'm worried about is if data can be modified on MythBackend in between when the recording is created and expired. If there's no data when the link is created, then the link will have the date & time of the recording in place of episode data. If the backend can pick up the season & episode numbers in the meantime, then that's another place it can break.

I'll keep looking into this, but I've been short on time as of late.

`

2015-03-19T01:00:00Z 2015-03-19T02:00:00Z NOVA The Incredible Journey of the Butterflies Anthology true 19 1 1 EP00003163 EP000031630574 0 4148823856 2015-03-19T04:01:42Z 4096 1813_20150319010000.mpg fileserver 2009-01-27 The secret world of the monarch butterfly. 76119 36 10 1813 813 WNETDT /Guide/GetChannelIcon?ChanId=1813 WNETDT (WNET-DT) 0 0 0 0 0 0 0 0 0 0 0 false true -3 0 2015-03-19T01:00:00Z 2015-03-19T02:01:00Z 85 Default Default Default 0 15 6 0 Default 2015-03-19T03:00:00Z 2015-03-19T03:30:00Z Seinfeld The Bottle Deposit Sitcom true 19 1 1 EP00016916 EP000169160153 0 2299131712 2015-03-20T01:31:23Z 4100 1811_20150319025900.mpg fileserver 1996-05-02 Jerry's mechanic (Brad Garrett) steals his car; Kramer and Newman plan to return used bottles to Michigan. 79169 7 22 1811 811 WPIXDT /Guide/GetChannelIcon?ChanId=1811 WPIXDT (WPIX-DT) 0 0 0 0 0 0 0 0 0 0 0 false true -3 0 2015-03-19T02:59:00Z 2015-03-19T03:30:00Z 123 Deleted Default Default 0 15 6 0 Default `
ascagnel commented 9 years ago

Also, take a look at this commit: https://github.com/ascagnel/mythPlex/commit/c70caf25b12aba252ab39608bf110c041eb751b4

Maybe it's possible to loop through all the recordings, find which have abandoned source files, and then delete those links?