Recording Deletion too Agressive (1 Viewer)

bam

New Member
March 27, 2007
3
0
Home Country
United Kingdom United Kingdom
TV-Server Version: SVN 19876
MediaPortal Version: SVN 19876
MediaPortal Skin: Indigo
Windows Version: MCE 2005
CPU Type: AMD 3700+
HDD:
Memory:
Motherboard:
Video Card:
Video Card Driver:
Sound Card:
Sound Card AC3:
Sound Card Driver:
1. TV Card: Hauppauge Nova HD-S2
1. TV Card Type: Satellite
1. TV Card Driver:
2. TV Card:
2. TV Card Type:
2. TV Card Driver:
3. TV Card:
3. TV Card Type:
3. TV Card Driver:
4. TV Card:
4. TV Card Type:
4. TV Card Driver:
MPEG2 Video Codec:
MPEG2 Audio Codec:
h.264 Video Codec:
Satelite/CableTV Provider:
HTPC Case:
Cooling:
Power Supply:
Remote:
TV:
TV - HTPC Connection:

I'm recording a lot of olympics off BBC HD atm, multiple episodes each day and they are all named exactly the same (title not filename). If I try to delete one episode from that day, all episodes are removed from the hard drive, but not from the recorded tv screen.
I've looked on the file system and it seems subsequent shows of the same name on the same day will have _1, _2 etc appended to the file name, but looking in the tv.log the regex used matches all filenames for that programme, on that channel on that day.

2008-08-16 00:53:21.328125 [11]: RecordingFileHandler: found 7 file(s) to delete for recording Olympics 2008 - BBC HD - 2008-08-15*
2008-08-16 00:53:22.140625 [11]: RecordingFileHandler: Clean orphan recording dirs for C:\Documents and Settings\All Users\Application Data\Team MediaPortal\MediaPortal TV Server\recordings\Olympics 2008 - BBC HD - 2008-08-15_2.ts
2008-08-16 00:53:22.140625 [11]: RecordingFileHandler: Checking 1 path(s) for cleanup

The 2nd line shows the file I wanted to delete, but the first shows the regex used to find matching files to be deleted.

I haven't included any other log file detail atm as it seems fairly obvious where it's going wrong, if you need anything though I'll provide it.

Thanks
 

blaudden

Portal Pro
November 19, 2006
68
2
Home Country
Sweden Sweden
Below you see the code run for deleting a recording. Notice the special "if" that looks for any ending underscore in the name and removes the 3 last characters of the name if there is an underscore in there. Kind of weird.

Code:
    public bool DeleteRecordingOnDisk(Recording rec)
    {
      if (System.IO.File.Exists(rec.FileName))
      {
        try
        {
          //Delete the matroska tag info xml file 
          if (File.Exists(Path.ChangeExtension(rec.FileName, ".xml")))
            File.Delete(Path.ChangeExtension(rec.FileName, ".xml"));
          // If a recording got interrupted there may be files like <recording name>_1.mpg, etc.
          string SearchFile = System.IO.Path.GetFileNameWithoutExtension(rec.FileName) + @"*";
          // Check only the ending for underscores as a user might have a naming pattern including them between e.g. station and program title
          string SubSearch = SearchFile.Substring((SearchFile.Length - 3));
          int UnderScorePosition = SubSearch.LastIndexOf(@"_");
          if (UnderScorePosition != -1)
            // Length - 3 should be enough since there won't be thousands of files with the same name.
            SearchFile = SearchFile.Substring(0, SearchFile.Length - 3) + @"*";
          string[] allRecordingFiles = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(rec.FileName), SearchFile);
          Log.Debug("RecordingFileHandler: found {0} file(s) to delete for recording {1}", Convert.ToString(allRecordingFiles.Length), SearchFile);
          foreach (string recPartPath in allRecordingFiles)
          {
            System.IO.File.Delete(recPartPath);
          }
          CleanRecordingFolders(rec.FileName);
        }
        catch (Exception ex)
        {
          Log.Error("RecordingFileHandler: Error while deleting a recording from disk: {0}", ex.Message);
          return false; // file not deleted, return failure
        }
        return true; // file deleted, return success
      }
      return true; // no file to delete, return success
    }

I have a recording on my disk and the first episode of the day got no _<num> part. Only the second one has it.

Program_Channel_Date.ts
Program_Channel_Date.xml
Program_Channel_Date_1.ts
Program_Channel_Date_1.xml
 

blaudden

Portal Pro
November 19, 2006
68
2
Home Country
Sweden Sweden
The database has information about wich filename each recording has, when deleting a recording in a virtual folder it will thus pass the full name of that recording and it should be possible to delete _only_ the files that belong to that recording. Don't see why it should need to delete with wildcard at all. Will write a patch.
 

blaudden

Portal Pro
November 19, 2006
68
2
Home Country
Sweden Sweden
Suggested patch

Please see attached patch that should fix the problem.

"Deletes a recording from the disk where it has been saved.
When recording, a unique filename is generated by concatening a underscore
and number to the file name(for example <title - channel>_1). That unique file
name is stored in the database and should
be used as base when deleting files related to the recording.
Thus all files with exactly the same base name but with _any_ extension
will be deleted(for example the releated matroska .xml file)"


Please bug someone to get it commited! :)

/ Magnus
 

Attachments

  • DeleteRecordingOnDisk.patch
    30.7 KB

bam

New Member
March 27, 2007
3
0
Home Country
United Kingdom United Kingdom
Thanks a lot, just hope this get incorporated into the main codebase.
 

rtv

Retired Team Member
  • Premium Supporter
  • April 7, 2005
    3,622
    301
    Osnabruck
    Home Country
    Germany Germany
    Unfortunately an accidentially stopped or crashed tvserver is more common than stupid EPG entries using the same name...
    Nevertheless - recordings should be really unique. Maybe we should just drop that date and add e.g. a unix timestamp instead. This way it will always be unique and the _<n> logic for "restarted" recordings does not need to be touched.
     

    johnzered

    Retired Team Member
  • Premium Supporter
  • April 20, 2008
    358
    80
    Home Country
    Finland Finland
    Unfortunately an accidentially stopped or crashed tvserver is more common than stupid EPG entries using the same name...
    Nevertheless - recordings should be really unique. Maybe we should just drop that date and add e.g. a unix timestamp instead. This way it will always be unique and the _<n> logic for "restarted" recordings does not need to be touched.

    Hi,

    why not just use the id of the recording and use that id to get the filename from recordings table, instead of trying to find matching filenames? I just tried restarting the tv server while recording and when the tv server got up again it created a new entry in the recording table...isn't that the case with series too? (that they create individual entries in recordings table)

    Also this is not only a epg problem as you can make several manual recordings during the day and if you delete one entry from db you actually delete all physical recordings...

    //johnzered
     

    gibman

    Retired Team Member
  • Premium Supporter
  • October 4, 2006
    2,998
    1,372
    Aarhus
    Home Country
    Denmark Denmark
    its in SVN now :)

    thx to blaudden + the rest of u lot for testing it :)

    /gibman
     

    Users who are viewing this thread

    Top Bottom