I am a new fan of Plex but i only use Plex when i am watching movies and series on my xbox. Most of the time however i still use VLC on my PC.
This means that OnDeck and unwatched status is never accurate and i am now planing on fixing this.
I had this idea that when i start start a movie (ex mkv file) on my computer a script will first run, check if that movie exists on my Plex server and if so, mark it as watch. Then it will start the movie with VLC. This will make sure that when i watch a movie on my PC with VLC it will be marked as watched on Plex. So when i run plex on my xbox the status will always be accurate.
1. User double clicks on a video (ex .mkv file)
2. custom script run
2a check if video exists in Plex by file path or name
2b if movie exists mark video as watched, else just ignore
3 start vlc with the video as input
My problem however is that i am unable to find the API calls i need to make to fetch all movies on plex (2a) and how the then mark that movie as watched (2b)
Appreciate any kind of hints or tips to help me solve my problem.
Thanks for your help with the API. Had some problems finding out what key to use. With chrome and developer tools i could see the id that the plex web app used and figured out i were going to use ratingKey.
param($videoPath)
$plexBaseUrl = "http://192.168.1.75:32400"
$vlc = "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
#Fetching video from NAS, so need to convert network path to local server path.
$serverPath = $videoPath.Replace("\\DS415", "/volume1")
$serverPath = $serverPath.Replace("\", "/")
$plexGetSessionsUrl = "$plexBaseUrl/library/sections"
function Mark-VideoAsWatched($videoPath)
{
$plexGetSessionsUrl = "$plexBaseUrl/library/sections"
$responce = Invoke-WebRequest -Uri $plexGetSessionsUrl
$sessions = [xml] $responce.Content
$keys = $sessions.MediaContainer.Directory | select -ExpandProperty key
foreach($item in $keys)
{
$plexGetVideosInSectionUrl = "$plexBaseUrl/library/sections/$item/all"
$responce = Invoke-WebRequest -Uri $plexGetVideosInSectionUrl
$vidoesInSession = [xml] $responce.Content
$vidoes = $vidoesInSession.MediaContainer.Video
foreach($video in $vidoes)
{
if($video.Media.Part.File -eq $videoPath)
{
$key = $video.ratingKey
$plexMarkAsWatchedUrl = "$plexBaseUrl/:/scrobble?key=$key&identifier=com.plexapp.plugins.library"
$responce = Invoke-WebRequest -Uri $plexMarkAsWatchedUrl
return;
}
}
}
}
Mark-VideoAsWatched $serverPath
. $vlc $videoPath
I were not able to open a movie with a PowerShell script file so i wrapped it in a C# console.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MarkedMovieAsWatchAndRunVLC
{
class Program
{
static void Main(string[] args)
{
string scriptFile = @"\\DS415\Work\Privat\Scripts\MarkedMovieAsWatchAndRunVLC.ps1";
string arguments = string.Format("-windowstyle hidden -ExecutionPolicy Bypass -File {0} \"{1}\"", scriptFile, args[0]);
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.FileName = "PowerShell.exe";
proc.StartInfo.Arguments = arguments;
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
}
}
}
It is working, but it is opening up new windows of VLC and not reusing the existing one. This needs to be fixed.
Thanks, I figured out your script. I do not understand the C# part, but that's not important. I liked your idea but I decided to go another way. I chose to use the SQLite command line tool and look into the database instead of calling the xml file. Only takes a split second to get a result. Using the XML seems like it could take some time if you have a lot of media.
Thanks, I figured out your script. I do not understand the C# part, but that's not important. I liked your idea but I decided to go another way. I chose to use the SQLite command line tool and look into the database instead of calling the xml file. Only takes a split second to get a result. Using the XML seems like it could take some time if you have a lot of media.
True, but ....
Accessing the database is something that should not be taken lightly, and besides that, and as already stated, sadly not every platform allows a direct access to the database, and accessing it over the LAN/WAN is NOT recommended with SQLite
Definitely agree, messing with the database is not for beginners. I have more experience with databases than with other coding (except for MortScript) so I actually feel safer dealing with SQL than anything else.