Jump to content


Photo

Find 'IsWatched' episodes in a specific directory?


  • Please log in to reply
25 replies to this topic

#21 muzicman0 OFFLINE  

muzicman0

    Advanced Member

  • Members
  • 32 posts
  • Local time: 06:26 AM

Posted 09 September 2019 - 05:40 PM

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.



#22 PenkethBoy OFFLINE  

PenkethBoy

    Advanced Member

  • Members
  • 3367 posts
  • Local time: 02:26 PM
  • LocationWarrington,UK

Posted 09 September 2019 - 06:06 PM

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

 

Attached File  TVEpisodes-Test.zip   1.1KB   1 downloads - 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, 09 September 2019 - 06:07 PM.

  • muzicman0 likes this

#23 muzicman0 OFFLINE  

muzicman0

    Advanced Member

  • Members
  • 32 posts
  • Local time: 06:26 AM

Posted 09 September 2019 - 06:25 PM

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, 09 September 2019 - 06:25 PM.


#24 PenkethBoy OFFLINE  

PenkethBoy

    Advanced Member

  • Members
  • 3367 posts
  • Local time: 02:26 PM
  • LocationWarrington,UK

Posted 10 September 2019 - 07:29 AM

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



#25 PenkethBoy OFFLINE  

PenkethBoy

    Advanced Member

  • Members
  • 3367 posts
  • Local time: 02:26 PM
  • LocationWarrington,UK

Posted 10 September 2019 - 07:44 AM

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 :)

  • muzicman0 likes this

#26 muzicman0 OFFLINE  

muzicman0

    Advanced Member

  • Members
  • 32 posts
  • Local time: 06:26 AM

Posted 10 September 2019 - 10:01 AM

Thanks!  This is great, I should be able to get it from here!  I really appreciate all the help and examples!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users