home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Support
General Support
Powershell script to move Recorded TV
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="pbathuk" data-source="post: 699285" data-attributes="member: 108858"><p>Hi,</p><p></p><p>I have re-written the script slightly so that it now takes into TV Series you already have on your PC.</p><p></p><p>[CODE]</p><p># Move Recorded TS Files to other locations</p><p></p><p># Owner : Philip Bath</p><p># Version : 0.3</p><p># Notes : Set the StartLocation, FilmLocation and OtherLocation</p><p># Notes1 : You can also turn on / off (1 = on, 0 = off) to delete the XML files that will be left</p><p># In the recordedTV location, off means it will be left as is</p><p># Notes2 : You can input the location of your TVSeriesLocation - This will ensure only series that you have in your</p><p># Collection will be moved.</p><p># Leave as "" if you don't want to use this feature</p><p></p><p>$StartLocation = "C:\Users\Public\Recorded TV\" # "C:\Users\Public\Recorded TV\"</p><p>$FilmLocation = "\\NAS\VideoDownloads\"</p><p>$OtherLocation = "\\NAS\VideoDownloads\"</p><p>$TVSeriesLocation = "\\NAS\Videos\TV Shows\"</p><p>$DeleteFilm = 1</p><p>$DeleteOther = 1</p><p></p><p># Build an array of the .TS files</p><p></p><p>$TVShowlist = Get-ChildItem -Path $TVSeriesLocation | where {$_.mode -match "d"}</p><p>$TSlist = Get-ChildItem -Path $StartLocation | Where-Object {$_.Name -like "*.ts"}</p><p>$Alllist = Get-ChildItem -Path $StartLocation | Where-Object {$_.Name -like "*.xml"}</p><p></p><p># If the TSList is empty then stop here</p><p> if (!$TSlist) </p><p> {</p><p> }</p><p> else</p><p> {</p><p> foreach ($TSfile in $TSlist)</p><p> {</p><p> # Check to see if the file starts with Film_</p><p> if ($TSfile.Name.IndexOf("Film_") -ne -1)</p><p> {</p><p> foreach ($Allfile in $Alllist)</p><p> {</p><p> $tmp = $TSfile.Name.IndexOf(".ts")</p><p> if ($Allfile.Name.IndexOf($TSfile.Name.SubString(0,$tmp)) -ne -1)</p><p> {</p><p> if ($DeleteOther -eq 1)</p><p> {</p><p> # Delete the file</p><p> Remove-Item $StartLocation$Allfile</p><p> }</p><p> else</p><p> {</p><p> # Move to the OtherLocation </p><p> Rename-Item $StartLocation$AllFile $Allfile.Name.subString(5)</p><p> ROBOCOPY $StartLocation.subString(0,$StartLocation.Length-1) $OtherLocation.subString(0,$OtherLocation.Length-1) $Allfile.Name.subString(5) /MOV /R:2 /w:300 /NFL /NDL</p><p> }</p><p> }</p><p> }</p><p> # Now rename file (remove Film_ ) then</p><p> Rename-Item $StartLocation$TSFile $TSfile.Name.subString(5)</p><p> ROBOCOPY $StartLocation.subString(0,$StartLocation.Length-1) $FilmLocation.subString(0,$FilmLocation.Length-1) $TSfile.Name.subString(5) /MOV /R:2 /w:300 /NFL /NDL</p><p> }</p><p> else</p><p> {</p><p> # Check the XML file first to get actual name, then check against already stored TV Series</p><p> # Logic = If series exists move to Otherlocation (assuming that is your area for getting TV episodes moved)</p><p> # If not a series that exists leave along - simply setup the folder in your TV series folder to get it to be moved</p><p> # If it has no episode number then it will NEVER be moved</p><p> </p><p> $tmp = $TSfile.Name.IndexOf(".ts")</p><p> $tmp1 = $TSfile.Name.SubString(0,$tmp)</p><p> # Section Used if not Film</p><p> $AllFile = $Alllist | Where-Object {$_.Name -like "*$tmp1*"}</p><p> </p><p> if (!$Allfile)</p><p> {</p><p> }</p><p> else</p><p> {</p><p> [xml]$xmlFile = get-content $StartLocation$Allfile</p><p> $xmlTitleraw = $xmlFile.tags.tag.SimpleTag | Where-Object {$_.Name -eq "TITLE"}</p><p> $xmlSeries = $xmlFile.tags.tag.SimpleTag |Where-Object {$_.Name -eq "SERIESNUM"}</p><p> $xmlEpisode = $xmlFile.tags.tag.SimpleTag | Where-Object {$_.Name -eq "EPISODENUM"}</p><p> # Test for (R)</p><p> $tmpValue = $xmlTitleraw.value.indexof("(R)")</p><p> if ($tmpValue -eq -1) </p><p> {</p><p> $tmpValue = $xmlTitleraw.value.length</p><p> }</p><p> $xmlTitle = $xmlTitleraw.value.substring(0,$tmpValue).trim()</p><p> </p><p> # if Seriesnum -eq missing then ignore all files</p><p> if ($xmlSeries.value -eq '') </p><p> {</p><p> #Do Nothing </p><p> }</p><p> else</p><p> {</p><p> </p><p> # Rename and Move to the other Location</p><p> # Rename first</p><p> $tmpValue = $xmlEpisode.value.indexof("/")</p><p> if ($tmpValue -eq -1)</p><p> {</p><p> $tmpValue = $xmlEpisode.value.length</p><p> }</p><p> $xmlEpisodeNum = $xmlEpisode.value.substring(0,$tmpValue)</p><p> $newName = $xmlTitle + " S" + $xmlSeries.value + "E" + $xmlEpisodeNum</p><p> $newNameXML = $newName + ".XML"</p><p> $newNameTS = $newName + ".ts"</p><p> </p><p> # Now need to check if the series exists in the TVShowlist</p><p> </p><p> $TVShowTest = $TVShowlist | Where-Object {$_.Name -like "$xmlTitle*"}</p><p> if (!$TVShowTest -and $TVShowList -ne "")</p><p> {</p><p> }</p><p> else</p><p> {</p><p> # If it appears in the list then this will be run</p><p> if ($DeleteOther -eq 1)</p><p> {</p><p> # Delete the file</p><p> Remove-Item $StartLocation$Allfile</p><p> }</p><p> else</p><p> { </p><p> Rename-Item $StartLocation$AllFile $newNameXML</p><p> ROBOCOPY $StartLocation.subString(0,$StartLocation.Length-1) $OtherLocation.subString(0,$OtherLocation.Length-1) $newNameXML /MOV /R:2 /w:300 /NFL /NDL</p><p> }</p><p> </p><p> # Move to the OtherLocation</p><p> Rename-Item $StartLocation$TSfile $newNameTS</p><p> ROBOCOPY $StartLocation.subString(0,$StartLocation.Length-1) $OtherLocation.subString(0,$OtherLocation.Length-1) $newNameTS /MOV /R:2 /w:300 /NFL /NDL</p><p> }</p><p> }</p><p> }</p><p> </p><p> }</p><p> }</p><p> }</p><p></p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="pbathuk, post: 699285, member: 108858"] Hi, I have re-written the script slightly so that it now takes into TV Series you already have on your PC. [CODE] # Move Recorded TS Files to other locations # Owner : Philip Bath # Version : 0.3 # Notes : Set the StartLocation, FilmLocation and OtherLocation # Notes1 : You can also turn on / off (1 = on, 0 = off) to delete the XML files that will be left # In the recordedTV location, off means it will be left as is # Notes2 : You can input the location of your TVSeriesLocation - This will ensure only series that you have in your # Collection will be moved. # Leave as "" if you don't want to use this feature $StartLocation = "C:\Users\Public\Recorded TV\" # "C:\Users\Public\Recorded TV\" $FilmLocation = "\\NAS\VideoDownloads\" $OtherLocation = "\\NAS\VideoDownloads\" $TVSeriesLocation = "\\NAS\Videos\TV Shows\" $DeleteFilm = 1 $DeleteOther = 1 # Build an array of the .TS files $TVShowlist = Get-ChildItem -Path $TVSeriesLocation | where {$_.mode -match "d"} $TSlist = Get-ChildItem -Path $StartLocation | Where-Object {$_.Name -like "*.ts"} $Alllist = Get-ChildItem -Path $StartLocation | Where-Object {$_.Name -like "*.xml"} # If the TSList is empty then stop here if (!$TSlist) { } else { foreach ($TSfile in $TSlist) { # Check to see if the file starts with Film_ if ($TSfile.Name.IndexOf("Film_") -ne -1) { foreach ($Allfile in $Alllist) { $tmp = $TSfile.Name.IndexOf(".ts") if ($Allfile.Name.IndexOf($TSfile.Name.SubString(0,$tmp)) -ne -1) { if ($DeleteOther -eq 1) { # Delete the file Remove-Item $StartLocation$Allfile } else { # Move to the OtherLocation Rename-Item $StartLocation$AllFile $Allfile.Name.subString(5) ROBOCOPY $StartLocation.subString(0,$StartLocation.Length-1) $OtherLocation.subString(0,$OtherLocation.Length-1) $Allfile.Name.subString(5) /MOV /R:2 /w:300 /NFL /NDL } } } # Now rename file (remove Film_ ) then Rename-Item $StartLocation$TSFile $TSfile.Name.subString(5) ROBOCOPY $StartLocation.subString(0,$StartLocation.Length-1) $FilmLocation.subString(0,$FilmLocation.Length-1) $TSfile.Name.subString(5) /MOV /R:2 /w:300 /NFL /NDL } else { # Check the XML file first to get actual name, then check against already stored TV Series # Logic = If series exists move to Otherlocation (assuming that is your area for getting TV episodes moved) # If not a series that exists leave along - simply setup the folder in your TV series folder to get it to be moved # If it has no episode number then it will NEVER be moved $tmp = $TSfile.Name.IndexOf(".ts") $tmp1 = $TSfile.Name.SubString(0,$tmp) # Section Used if not Film $AllFile = $Alllist | Where-Object {$_.Name -like "*$tmp1*"} if (!$Allfile) { } else { [xml]$xmlFile = get-content $StartLocation$Allfile $xmlTitleraw = $xmlFile.tags.tag.SimpleTag | Where-Object {$_.Name -eq "TITLE"} $xmlSeries = $xmlFile.tags.tag.SimpleTag |Where-Object {$_.Name -eq "SERIESNUM"} $xmlEpisode = $xmlFile.tags.tag.SimpleTag | Where-Object {$_.Name -eq "EPISODENUM"} # Test for (R) $tmpValue = $xmlTitleraw.value.indexof("(R)") if ($tmpValue -eq -1) { $tmpValue = $xmlTitleraw.value.length } $xmlTitle = $xmlTitleraw.value.substring(0,$tmpValue).trim() # if Seriesnum -eq missing then ignore all files if ($xmlSeries.value -eq '') { #Do Nothing } else { # Rename and Move to the other Location # Rename first $tmpValue = $xmlEpisode.value.indexof("/") if ($tmpValue -eq -1) { $tmpValue = $xmlEpisode.value.length } $xmlEpisodeNum = $xmlEpisode.value.substring(0,$tmpValue) $newName = $xmlTitle + " S" + $xmlSeries.value + "E" + $xmlEpisodeNum $newNameXML = $newName + ".XML" $newNameTS = $newName + ".ts" # Now need to check if the series exists in the TVShowlist $TVShowTest = $TVShowlist | Where-Object {$_.Name -like "$xmlTitle*"} if (!$TVShowTest -and $TVShowList -ne "") { } else { # If it appears in the list then this will be run if ($DeleteOther -eq 1) { # Delete the file Remove-Item $StartLocation$Allfile } else { Rename-Item $StartLocation$AllFile $newNameXML ROBOCOPY $StartLocation.subString(0,$StartLocation.Length-1) $OtherLocation.subString(0,$OtherLocation.Length-1) $newNameXML /MOV /R:2 /w:300 /NFL /NDL } # Move to the OtherLocation Rename-Item $StartLocation$TSfile $newNameTS ROBOCOPY $StartLocation.subString(0,$StartLocation.Length-1) $OtherLocation.subString(0,$OtherLocation.Length-1) $newNameTS /MOV /R:2 /w:300 /NFL /NDL } } } } } } [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Support
General Support
Powershell script to move Recorded TV
Contact us
RSS
Top
Bottom