Jump to content

Find 'IsWatched' episodes in a specific directory?


muzicman0

Recommended Posts

muzicman0

I have tried a couple things, but to be honest, I'm not a developer!  I am trying to pull up TV episodes that are watched in my Recorded TV folder (let's say C:\Recorded TV).  I can authenticate, but I can't figure out how to actually get the info that I need.

 

Eventually, the idea I want to implement is that anything that has been watched get's automatically compressed and moved to an alternate file location.  BUT, not until it has been watched.  

 

I already have the VBS script that compresses the video, I just need to find a way to tell if a specific file has been watched or not.

 

Can anyone help?

Link to post
Share on other sites
PenkethBoy

$embyServerUrl + "/emby/users/" + $User.User.Id + "/items?Recursive=true&IncludeItemTypes=Episode&IsPlayed=True" + "&api_key=" + $User.AccessToken

 

this is from Powershell but if you are using vbs not that hard to follow

 

it will return a json object with some basic info about the episodes that have been played - across all TV libraries

Link to post
Share on other sites
PenkethBoy

If you wait a couple of weeks i will be posting a reporting script which will give you all the data you need and more

Link to post
Share on other sites
muzicman0

use the library id as ParentID=<library ID>

I tried this, but then realized that I don't know how to find the library ID.  I tried Recordings, but it didn't seem to work.  I'm slogging through the Swagger UI page and trying different combinations, but still can't get it to work.

 

If you wait a couple of weeks i will be posting a reporting script which will give you all the data you need and more

I can probably wait, but was hoping to test ASAP, since I just purchased a month, and am hoping to replicate the functionality I already have using JRiver.

 

I do very much appreciate the help!!

Link to post
Share on other sites
speechles

You might want to "&sortby=datecreated,sortname&sortorder=descending" at the end In that way you can sort of cache in your script the last watched item-title and it's item-id into variables. Then when you read the next json package it can work to give you an idea of where to stop when parsing the json on down from the last. So you don't parse two fields twice sort of thing.

 

 

$embyServerUrl + "/emby/users/" + $User.User.Id + "/Views"

 

That would get the root of the entire library including id's.

Edited by speechles
Link to post
Share on other sites
PenkethBoy

the library id is in the url of the library home page

 

it depends which version of the server you are using as Luke is making major changes at the moment - it might say topParentID=xxxx

 

but its parentID in the api url

Link to post
Share on other sites
PenkethBoy

"I already have the VBS script that compresses the video"

 

Have you tried the convert/sync option within Emby?

Link to post
Share on other sites
muzicman0

"I already have the VBS script that compresses the video"

 

Have you tried the convert/sync option within Emby?

No, but I didn't see an option to only compress after I had watched it.  Did I miss it?

Link to post
Share on other sites
muzicman0

Have you explored our convert media feature?

see one post above.  I only want to convert (and delete the original) after watching in HD.  This is for archive purposes, and I want it to be automated.

Link to post
Share on other sites
  • 1 year later...

So I am back on this again.  Really wanting to get this to work, but I just can't for whatever reason.  If I do this:

http://10.1.0.122:8096/emby/items?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&Recursive=true&IncludeItemTypes=Episode

I get a list of all items.  However, as soon as I add &IsPlayed=True, it throws an error.  Here is what I tried:

http://10.1.0.122:8096/emby/items?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxx&Recursive=true&IncludeItemTypes=Episode&IsPlayed=True

What am I doing wrong? 

 

Then, even if I get the list, I have to figure out in vbs how to parse JSON in VBS, and I don't believe that is a simple task.

Edited by muzicman0
Link to post
Share on other sites

I remoted in and tried it to make sure I get the exact error.  The error is:

 

Exception of type 'SQLitePCL.pretty.SQLiteException' was thrown.

 

Also, assuming I can get this to work, is there a way that the path to the file can be included in the output?  When I look at the items (without the filter for 'played'), path isn't included.

Link to post
Share on other sites
PenkethBoy

I just tried this (beta Server)

 

and it works - guess as you are not adding the /users/<userid> thats probably it - did not test that

 

anyway this works

".../emby/users/" + $User.User.Id + "/items?Fields=Path&Recursive=true&IncludeItemTypes=Episode&IsPlayed=True" + "&api_key=" + $User.AccessToken

Adding Fields=Path will return the path to the item if you need other Fields the field names are comma delimited e.g. Fields=Path,Genres,ProviderIds etc etc

 

Example output

{
    "Items":  [
                  {
                      "Name":  "Jasper + Chef",
                      "ServerId":  "393d783c30484015a24645f7844060b4",
                      "Id":  "884",
                      "Path":  "F:\\EmbyTest\\TVTesting\\Alan Partridge Mid Morning Matters\\Season 2\\Alan Partridge\u0027s Mid Morning Matters - S02E04 - Episode 4.ts",
                      "RunTimeTicks":  16001340416,
                      "IndexNumber":  4,
                      "ParentIndexNumber":  2,
                      "IsFolder":  false,
                      "Type":  "Episode",
                      "ParentLogoItemId":  "867",
                      "ParentBackdropItemId":  "867",
                      "ParentBackdropImageTags":  [
                                                      "8b09d6b2705e17f0362eda8c3bf0541e",
                                                      "7390971789f97cc5797acaad92cbaa9d",
                                                      "65df2fb83a3084a3d39b04366949e80c",
                                                      "23a6f33b8b72907526595b78970d5b35"
                                                  ],
                      "UserData":  {
                                       "PlaybackPositionTicks":  0,
                                       "PlayCount":  1,
                                       "IsFavorite":  false,
                                       "LastPlayedDate":  "2019-09-09T20:11:34.0000000+00:00",
                                       "Played":  true
                                   },
                      "SeriesName":  "Alan Partridge\u0027s Mid Morning Matters",
                      "SeriesId":  "867",
                      "SeasonId":  "883",
                      "SeriesPrimaryImageTag":  "0d26d4afaf9e37fa7ba265667f87deb9",
                      "SeasonName":  "Season 2",
                      "ImageTags":  {
                                        "Primary":  "59d1c3b87ec9afbaf42e664d7950af47"
                                    },
                      "BackdropImageTags":  [

                                            ],
                      "ParentLogoImageTag":  "8e89c5c81fe8788b872dac62b0807a12",
                      "ParentThumbItemId":  "867",
                      "ParentThumbImageTag":  "6084f185aac52a90ea088e2281d3e7a8",
                      "MediaType":  "Video"
                  }
              ],
    "TotalRecordCount":  1
}

If VBS does not have an easy way to read JSON - then might be worth moving to a more modern language - i happen to use Powershell and that can read and write json files with no problem - as i suspect can Visual Studio if thats more to your liking etc etc

Link to post
Share on other sites

I wonder if it just doesn't work in a browser.  I tried:

 

http://10.1.0.122:8096/emby/users/muzicman0/items?Fields=Path&Recursive=true&IncludeItemTypes=Episode&IsPlayed=True&api_key=xxxxxxxxxxxxxxxxxxxxxxxx

 

and now it says:

 

Input string was not in a correct format.

 

I'll try learning JSON in powershell.  I have done some basic stuff that way, but I haven't actually done much programming since Visual Basic 6!!  Mostly just scripting in VBS and VBA.

 

I'll try to make a powershell script with your example.

Link to post
Share on other sites

I am confused by this:

 

$User.User.Id

 

Is that just my username in a variable, or is that an object that has multiple properties.  If an object, how do I use it? 

 

I really do appreciate all the help!

Link to post
Share on other sites

Got it!  Took me a bit to figure out my actual user ID.  I assumed it was my actual username.  I got it from /Users/Public, and not it works in a browser...not to figure out how to parse it and save all the paths to a text file or an array.

Link to post
Share on other sites
PenkethBoy

To get you going here is a simple script - This Authenticates against your server using a Users login details - no need to set an API key in the dashboard as it gets one from Emby for the user - user access rights are maintained so use an Admin user to sart with then you can test restricted users when you get more confident

 

Change the first three lines with your user details

 

then migrate in the powershell window to the location of where you saved the script e.g. c:\test

 

and run it like this

 

PS C:\Test> .\TVEpisodes-Test.ps1

 

assuming you save the file in the c:\test folder - the PS C:\Test> is the powershell prompt - and yes the . is important before the filename

 

It will save the JSON returned by Emby to the same location as the script as a TVEpisodes.json file

 

TVEpisodes-Test.zip - unzip it first! :)

 

NB: you will probably need to change your Powershell Execution Policy - see google on how to do this

 

Good Luck

Edited by PenkethBoy
  • Like 1
Link to post
Share on other sites

Thanks a ton.  I had this going:

$request = 'http://10.1.0.122:8096/emby/users/{user ID]/items?Fields=Path&Recursive=true&IncludeItemTypes=Episode&IsPlayed=True&api_key=xxxxxxxxxxxxxxxx'
Invoke-WebRequest $request |
ConvertFrom-Json |
Select -expand Items|
Select SeriesName, SeasonName, Name, Path

It did return the info I was after, but I hadn't figured out how to get the path into a variable, etc yet.  I will look over your code (which is much more elegant), and see what I can do. 

Edited by muzicman0
Link to post
Share on other sites
PenkethBoy

Tip - dont use Aliases in Powershell use the full command (there is a special place in Hell for the people that do) - if you dont it will come back and bite you in the bum - i.e. select is and alias for Select-Object

 

if you assign the webrequest to a variable as i do in the code i gave you its a lot easier to manipulate 

 

e.g. $Result = Invoke-Webrequest ..... so result contains the info returned by Emby - the json is then contained in the $Result.Content - this is what you convert from Json into a PS object so you can then manipulate it how you need

 

Also use the parameters for Invoke-Webrequest -Uri -Method etc etc - buy default it worked for you as the default method is GET

 

Also it better to keep pipeline stuff on one line to make it clearer and not have it over multiline as it makes it hard to read

 

e.g. $Media | ConvertTo-Json -Verbose -Depth 100 | Out-File "$PSScriptRoot\TVEpisode.json"

 

Final tip - Download "Visual Studio Code" (it free) add the Powershell plugin and you will get a much better editor/debugger/IDE the the verrrrrrrrrrry basic Powershel ISE

 

Have fun

Link to post
Share on other sites
PenkethBoy

To Access the data in powershell contained in the $Media variable in my simple example and get you started with a very basic writing to screen of variable info

 

add the below to my script after line 47 before the Exit line and run the script and look at the screen you will see all the episode paths and ID's list

 

 

#hint its ".items" which is how the individual episode are defined in the json file

foreach ($Episode in $Media.Items) 
 
{
 
   $Path = $Episode.Path
 
   $Id = $Episode.ID
 
   Write-Host "Episode ID:" $Id "Path to File:" $Path
 
}
 
$Episode can be anything you like $Banana $Purple etc - usually best to make it descriptive so its easy to understand - especially 9 months later when you come back it and WHAT was i thinking :)
  • Like 1
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...