Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Delete Lower Quality Plex Duplicates
$Server='192.168.1.9:32400'
$PlexToken = 'FGir5aQ5yfpRZZ4ZqxAg'
$libraries = Invoke-RestMethod -Uri "http://$server/library/sections/all?X-Plex-Token=$PlexToken"
$VideoLibraries = $libraries.MediaContainer.Directory | ?{$_.type -eq 'show'}
$Resolutions = @{
"sd" = 1
"420" = 10
"720" = 20
"1080" = 30
}
foreach($library in $VideoLibraries){
#$library
$episodes = Invoke-RestMethod -Uri "http://$server/library/sections/$($library.key)/all?type=4&duplicate=1&X-Plex-Token=$PlexToken"
foreach($episode in $episodes.MediaContainer.Video){
Write-Information "$($episode.GrandparentTitle) $($episode.ParentTitle) $($episode.title)"
$MediaFilesByQuality = $episode.Media | Select-Object @{L='width';E={[int]$_.width}}, @{L='Bitrate';E={[int]$_.bitrate}}, id | Sort-Object width,bitrate -Descending
$Winner = $MediaFilesByQuality[0]
Write-Information "`tWinner is $($Winner.width) at $($Winner.bitrate)bps"
$Losers = $MediaFilesByQuality[1..$MediaFilesByQuality.Length]
Foreach($Loser in $Losers){
Write-Information "`t`tDeleting loser: $($Loser.width) at $($Loser.bitrate)bps"
$url = "http://192.168.1.9:32400$($Episode.Key)/media/$($Loser.id)?X-Plex-Token=$PlexToken"
Write-Information $url
Invoke-RestMethod $url -Method Delete
#Invoke-WebRequest -Uri "http://192.168.1.9:32400/library/metadata/31701/media/60326?X-Plex-Product=Plex%20Web&X-Plex-Version=3.39.5&X-Plex-Client-Identifier=51o3nj392lk2e4zcn61myrda&X-Plex-Platform=Chrome&X-Plex-Platform-Version=65.0&X-Plex-Sync-Version=2&X-Plex-Device=Windows&X-Plex-Device-Name=Chrome&X-Plex-Device-Screen-Resolution=1920x949%2C1920x1080&X-Plex-Token=FGir5aQ5yfpRZZ4ZqxAg&X-Plex-Provider-Version=1.1" -Method "DELETE"
#-Headers @{"Cookie"="imdb_top_dvd_rentals_view=thumb; wanted_view=thumb; advanced_toggle_checked=1; snatched_view=list; soon_view=thumb; suggest_view=thumb; late_view=list; blu_ray_com_new_releases_view=thumb; imdb_box_office_view=thumb; imdb_top_250_movies_view=thumb; _ga=GA1.1.821301858.1492893135; _pk_id.1.b9e6=51028061d5d57592.1495274484.60.1523229603.1523229602.; login_cookie=816dfa72c4545e16c4d0e595627feb181f417539; login_salt=69"; "Origin"="http://192.168.1.9:32400"; "Accept-Encoding"="gzip, deflate"; "Accept-Language"="en-GB"; "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"; "Accept"="text/plain, */*; q=0.01"; "Referer"="http://192.168.1.9:32400/web/index.html"; "X-Requested-With"="XMLHttpRequest"}
}
}
}
@zimmertr

This comment has been minimized.

Copy link

@zimmertr zimmertr commented Aug 16, 2018

Hey dude, thanks for posting this. So you know, though, you published your personal authentication token. You might want to edit/delete this Gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment