NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public NextPVR Support Windows v
« Previous 1 … 3 4 5 6 7 … 103 Next »
NPVR Windows recordings folder cleanup....

 
  • 0 Vote(s) - 0 Average
NPVR Windows recordings folder cleanup....
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,878
Threads: 770
Joined: Nov 2003
#11
2024-01-07, 05:21 PM
(2024-01-07, 05:09 PM)mvallevand Wrote: I wasn't meaning the extra files, NextPVR wasn't deleting rows from the database either and I am sure in testing that has happened to me before, one reason that the missing tree setting became important.
It depends. In NextPVR.exe or a uiclient, it does triggers these checks if files exists while loading the recording lists. The web app doesn't do that, for a quicker response - it just trust the list is up to date.
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 53,371
Threads: 963
Joined: May 2006
#12
2024-01-07, 05:58 PM (This post was last modified: 2024-01-07, 06:04 PM by mvallevand.)
OK I was testing via the web, not NextPVR.exe so that explains it. Why does the web client need faster loading than UI clients? config.xml controls the speed for those that don't want look up so it becomes confusing for users. Even back on topic the script here won't help for web users.

This line should probably not be verbose

2024-01-07 12:56:24.496 [VERBOSE][13] Deleting non-existant recording ....

Martin
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,878
Threads: 770
Joined: Nov 2003
#13
2024-01-07, 06:06 PM
Quote:OK I was testing via the web, not NextPVR.exe so that explains it. Why does the web client need faster loading than UI clients?
Honestly, no particular reason. That's just what I did at the time, when I first created the current web app, in an effort to keep it as quick as possible. (for a good first impression for users that were going to have to switch from the v4 they knew, to something entirely new)

Ok, changed it to debug log level.
stat
Offline

Junior Member

uk
Posts: 14
Threads: 3
Joined: Sep 2023
#14
2024-01-11, 10:43 AM
(2024-01-06, 12:36 PM)Colincam Wrote: I use Plex to watch TV shows recorded by NextPVR.  When done with the recordings, I will delete them via Plex.  This leaves behind orphaned metadata.  I wanted a routine to clean up the NextPVR recordings folder, delete orphaned NextPVR metadata and if that leaves an empty folder, delete the empty folder as well.   So, I asked AI to help me create a batch file to perform these duties.  I then set a task in Windows Task Scheduler to run this batch file daily.  Below is the batch file created with the help of AI.  Please note that you use this batch file AT YOUR OWN RISK.  Please backup your recordings folder before applying this process.  It WILL delete any files that do not have a related file with a .ts file extension.  If there is a .ts file, it will leave it and its associated metadata alone.  If you have any .mp4's for instance in the NextPVR recordings folder, they will also be deleted since they have no .ts file associated with them.  This script assumes that you use the NextPVR recordings folder only for NextPVR recordings with the .ts file extension.  Please replace the set command at the beginning to point to YOUR recordings folder.  What you see is mine as an example.  Do not put this batch file in the recordings folder itself for it will delete itself.  No warranty is implied, use at your own risk.  You can copy and paste into your favorite text editor.  Make the set command change to reflect your recordings folder and save as a batch (.bat) file.  Again, do NOT place the batch file in the recordings folder....

@echo off
set "folder_path=D:\Recorded TV\"

for /r "%folder_path%" %%F in (*) do (
    if "%%~xF" neq ".ts" (
        if not exist "%%~dpnF.ts" (
            del "%%F"
            echo Delete: "%%F"
        )
    )
)

for /d /r "%folder_path%" %%d in (*) do (
    dir /b "%%d" 2>nul | findstr "^" >nul || (
        rd "%%d"
        echo Deleted empty subfolder: "%%d"
    )
)

Nice work Colincam, this is exactly what I've been looking for, will save a heap of time.
And here's your modified code to delete anything without a .ts file extention OR .mp4 file extention.

@echo off
set "folder_path= D:\Recorded TV\"

for /r "%folder_path%" %%F in (*) do (
    if "%%~xF" neq ".ts" if "%%~xF" neq ".mp4" (
        if not exist "%%~dpnF.ts" (
            del "%%F"
            echo Delete: "%%F"
        )
    )
)

for /d /r "%folder_path%" %%d in (*) do (
    dir /b "%%d" 2>nul | findstr "^" >nul || (
        rd "%%d"
        echo Deleted empty subfolder: "%%d"
    )
)
blobbyguts
Offline

Junior Member

United Kingdom
Posts: 16
Threads: 1
Joined: Jan 2024
#15
2024-02-07, 12:15 PM (This post was last modified: 2024-02-07, 12:28 PM by blobbyguts.)
For those of you running on Windows with PowerShell knowledge, here is some code to clean up your recordings folder and keep a log

#
# Set path to cleanup logging file, this can be anywhere, I have chosen the same location as the NextPVR config file
#
$logfile = "$env:Public\NPVR-data\Cleanup.log"
#
# Create and write the header record if the cleanup logging file does not exist
#
if (-not(Test-Path -Path $logfile)){Add-Content -Path $logfile -Value 'Date Time Removal Folder Name'}
#
# Check if NextPVR XML config file exists - normally located in "C:\Users\Public\NPVR-data"
#
if (-not(Test-Path -Path "$env:Public\NPVR-data\config.xml"))
{
Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Error! File `"$("$env:Public\NPVR-data\config.xml")`" not found, exiting"
exit
}
#
# Attempt to read XML file
#
try {[xml]$XML = Get-Content -Path "$env:Public\NPVR-data\config.xml"}
#
# XML file has errors, exit
#
catch
{
Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Error reading file `"$("$env:Public\NPVR-data\config.xml")`", exiting"
exit
}
#
# Check each recording sub-folder
#
Get-ChildItem -Path $XML.Settings.Recording.RecordingDirectory -Directory | ForEach-Object {
#
# Get ANY common video file types in the root of this sub-folder and any sub-folder; add any other video file types to the -Include list if required
#
$recordings = Get-ChildItem -Path $_.FullName -Include '*.ts','*.wtv','*.mp4','*.mkv','*.avi','*.mpg','*.mpeg','*.wmv' -Recurse
#
# If no recording file-types found, remove the sub-folder and ALL its contents, including sub-folders
#
if ($recordings.Count -eq 0)
{
#
# Try removing the folder and add "Success" to log file
#
try
{
Remove-Item -Path $_.FullName -Recurse -Force -Confirm:$false
Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Success `"$($_.FullName)`""
}
#
# If removal failed, add "Fail" to log file
#
catch {Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Fail `"$($_.FullName)`""}
}
#
# Folder or sub-folders have recordings, add "Retained" to log file
#
else {Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Retained `"$($_.FullName)`""}
}

When trying to run the script you may get an error similar to the one below:
File C:\Temp\Recording-Cleanup.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess

If so, open an administrative PowerShell session and enter command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

This will allow only scripts created locally to run; any downloaded scripts will not execute - this is a safety measure for rogue scripts which may attempt to do nefarious things.


Apologies for the formatting as I don't seem to be able to change it. I would attach the code to this post in a file but that doesn't seem to work for me...
blobbyguts
Offline

Junior Member

United Kingdom
Posts: 16
Threads: 1
Joined: Jan 2024
#16
2024-02-08, 11:09 AM
(2024-02-07, 12:15 PM)blobbyguts Wrote: For those of you running on Windows with PowerShell knowledge, here is some code to clean up your recordings folder and keep a log

#
# Set path to cleanup logging file, this can be anywhere, I have chosen the same location as the NextPVR config file
#
$logfile = "$env:Public\NPVR-data\Cleanup.log"
#
# Create and write the header record if the cleanup logging file does not exist
#
if (-not(Test-Path -Path $logfile)){Add-Content -Path $logfile -Value 'Date Time Removal Folder Name'}
#
# Check if NextPVR XML config file exists - normally located in "C:\Users\Public\NPVR-data"
#
if (-not(Test-Path -Path "$env:Public\NPVR-data\config.xml"))
{
Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Error! File `"$("$env:Public\NPVR-data\config.xml")`" not found, exiting"
exit
}
#
# Attempt to read XML file
#
try {[xml]$XML = Get-Content -Path "$env:Public\NPVR-data\config.xml"}
#
# XML file has errors, exit
#
catch
{
Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Error reading file `"$("$env:Public\NPVR-data\config.xml")`", exiting"
exit
}
#
# Check each recording sub-folder
#
Get-ChildItem -Path $XML.Settings.Recording.RecordingDirectory -Directory | ForEach-Object {
#
# Get ANY common video file types in the root of this sub-folder and any sub-folder; add any other video file types to the -Include list if required
#
$recordings = Get-ChildItem -Path $_.FullName -Include '*.ts','*.wtv','*.mp4','*.mkv','*.avi','*.mpg','*.mpeg','*.wmv' -Recurse
#
# If no recording file-types found, remove the sub-folder and ALL its contents, including sub-folders
#
if ($recordings.Count -eq 0)
{
#
# Try removing the folder and add "Success" to log file
#
try
{
Remove-Item -Path $_.FullName -Recurse -Force -Confirm:$false
Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Success `"$($_.FullName)`""
}
#
# If removal failed, add "Fail" to log file
#
catch {Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Fail `"$($_.FullName)`""}
}
#
# Folder or sub-folders have recordings, add "Retained" to log file
#
else {Add-Content -Path $logfile -Value "$(Get-Date -Format 'yyyy/MM/dd HH:mm:ss.fff') Retained `"$($_.FullName)`""}
}

When trying to run the script you may get an error similar to the one below:
File C:\Temp\Recording-Cleanup.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess

If so, open an administrative PowerShell session and enter command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

This will allow only scripts created locally to run; any downloaded scripts will not execute - this is a safety measure for rogue scripts which may attempt to do nefarious things.


Apologies for the formatting as I don't seem to be able to change it. I would attach the code to this post in a file but that doesn't seem to work for me...

The code (with some updates) can be found here https://1drv.ms/t/s!ApkSgUXUYIE3gu5NwypG...A?e=8vhdTG
blobbyguts
Offline

Junior Member

United Kingdom
Posts: 16
Threads: 1
Joined: Jan 2024
#17
2024-02-09, 10:20 AM
(2024-02-09, 10:09 AM)John Ocampos Wrote: To streamline the cleanup of your NextPVR recordings folder on Windows, consider setting up retention policies within NextPVR itself. This feature allows you to automatically delete recordings based on criteria such as age or space usage, helping to maintain a tidy and organized folder. Additionally, you can utilize batch scripts or third-party utilities like CCleaner to schedule regular cleanup tasks, ensuring that old recordings are regularly removed to free up storage space without manual intervention. Lastly, consider organizing recordings into subfolders based on categories or dates to facilitate easier management and identification of content.

The problem I (and probably others) have is that the main user uses Kodi and doesn't know that the backend recording is managed by a different program.
When they delete programs from the recordings section in Kodi AND things like Comskip are in use orphaned folders are left behind and are unseen.
I use a scheduled task which calls my PowerShell script to tidy up the recordings folder.
Retention policies are of little use as some recordings are kept for long periods of time and automatically deleting those would get me into some bother!
My user hates change - I even have to reload an older Kodi skin to keep them happy when newer versions are released Confused
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 53,371
Threads: 963
Joined: May 2006
#18
2024-02-09, 10:28 AM
Although you are responding to a chatbot you made mistake. If you delete a recording in pvr it will remove all those extra files. There should only be a problem if you delete using a program that is not NextPVR aware.
blobbyguts
Offline

Junior Member

United Kingdom
Posts: 16
Threads: 1
Joined: Jan 2024
#19
2024-02-09, 10:33 AM
(2024-02-09, 10:28 AM)mvallevand Wrote: Although you are responding to a chatbot you made mistake. If you delete a recording in pvr it will remove all those extra files. There should only be a problem if you delete using a program that is not NextPVR aware.

So using the NextPVR web interface to delete the recording will remove the folder?
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 53,371
Threads: 963
Joined: May 2006
#20
2024-02-09, 10:50 AM
If you have the appropriate config xml settings for custom extensions yes.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (3): « Previous 1 2 3 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  Viewing Recordings From Earlier Version of NextPVR boneshakerz 1 41 Yesterday, 08:04 PM
Last Post: mvallevand
  Windows install failed GlenH 12 508 2025-08-11, 03:00 PM
Last Post: mvallevand
  Recurring recordings not happening and no pending recordings JP23 12 503 2025-07-31, 04:05 PM
Last Post: mvallevand
  Recent recordings contain several corrupt data VanKuiSh 3 374 2025-07-07, 04:55 PM
Last Post: mvallevand
  Since v7: EPG mostly "no listings", and channels change during recordings :'( rightbryce 40 5,683 2025-06-23, 01:15 AM
Last Post: sub
  Windows could not start the NextPVR Service service on Local Computer Error 193:0xc1 Jimmyts100 7 6,241 2025-06-18, 06:26 PM
Last Post: jcole998
  Series Recordings - Bug? MalcolmInman 32 2,372 2025-05-31, 01:52 AM
Last Post: mvallevand
  Pending recordings not showing in web interface and NextPVR gadget not working... henryixV 4 631 2025-05-27, 08:29 PM
Last Post: henryixV
  Failed recordings "Operation timed out" Stanno 8 885 2025-04-27, 07:26 PM
Last Post: Nick017
  Can't delete scheduled recordings Druhl 3 451 2025-04-22, 09:10 PM
Last Post: mvallevand

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode