Last active
December 21, 2015 05:59
-
-
Save nicolashohm/6260960 to your computer and use it in GitHub Desktop.
Delete watched media items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$path = 'Plex/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db'; | |
try { | |
$dbh = new PDO('sqlite:'.$path, null, null, array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ)); | |
} catch (PDOException $e) { | |
echo "Error!: " . $e->getMessage() . PHP_EOL; | |
die(); | |
} | |
$query = 'SELECT mp.file | |
FROM metadata_item_settings mdis | |
LEFT JOIN metadata_items mdi ON (mdis.guid = mdi.guid) | |
LEFT JOIN media_items mi ON (mi.metadata_item_id = mdi.id) | |
LEFT JOIN media_parts mp ON (mp.media_item_id = mi.id) | |
WHERE mp.file IS NOT NULL AND mdis.view_count > 0 | |
GROUP BY mp.file'; | |
$data = $dbh->query($query)->fetchAll(PDO::FETCH_COLUMN); | |
if(count($data)<1) die('No files to delete!'); | |
print_r($data); | |
echo 'Delete these files? [y/N] '; | |
$input = trim(fgets(STDIN)); | |
if($input == 'y') | |
{ | |
foreach ($data as $path) | |
{ | |
echo date('c'); | |
if (unlink($path)) echo ' deleted: '; | |
else echo ' cannot delete: '; | |
echo $path.PHP_EOL; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment