Jump to content

Emby Server api


PrincessClevage

Recommended Posts

What about the server log? I may be able to spot something. Thanks.

Link to comment
Share on other sites

  • 2 weeks later...
PrincessClevage

Hi Luke,

I now have the resume functionality working after armed security camera is triggered it plays automatically on either of my two main emby clients if they are active and streaming video (usually a movie) but when I stop the security camera footage and go back to previously playing media it auto starts the security camera footage again. I assume it is doing this because the security camera footage was the last recorded playing media, is it possible to auto resume previously playing footage (prior to the auto stream of the security camera footage e.g resume previously playing movie)?

After a bricked Vera edge and re-loading updated apps to verplus and working with Chef to get his Surveillance plugin for emby working again I can finally say that I have this operational and each part responds reasonably quickly (to my delight). Logic is:

Motion detection in the garage while sensors is in armed state (house in night mode) and if either of two main emby clients are active the reactor will trigger and action a bookmark current play state of both clients then wait 5sec then play garage camera feed to the which ever client is active then wait 5secs and disarm garage sensor. A second reactor (Vera hub plugin) is set to monitor the two main emby clients for playingtitle with the name of “garage” and when triggered resumes media on each of the main emby clients, of course this resume does not actually occur immediately on the emby client as the garage camera feed is still playing but the second reactor is in a tripped state still waiting to resume

Media and once stop of the garage camera feed has occurred then with in a couple of seconds the previously playing media resumes then the second reactor wait for 5mins (4mins for sensors cool off time I think) and then arms the garage sensor again ready to trigger the whole process again. Pretty cool and really wanted to thank Rigpapa and Chef for their wonderful work and great plugins to Vera home automation and Emby ecosystem!

  • Like 1
Link to comment
Share on other sites

chef

I finally got all of this working inside Home Assistant. I have an automation that will launch emby on a certain firestick, play a movie and turn on the tv at a set time. Message me if you'd like the details.

 

5ccb40b9e1953_20190502_141008.png

 

This is cool!

Link to comment
Share on other sites

hooray4me

How would I go about calling a random/shuffled episode of a show like Paw Patrol, which has several seasons?

Link to comment
Share on other sites

PrincessClevage

How would I go about calling a random/shuffled episode of a show like Paw Patrol, which has several seasons?

emby would have to support the random play from a tv series
Link to comment
Share on other sites

hooray4me

emby would have to support the random play from a tv series

 

Emby already does support this... I just need to know what variables need to be posted to the api to do this.

Link to comment
Share on other sites

chef

Emby already does support this... I just need to know what variables need to be posted to the api to do this.

When you create a play request, use array of BaseItem internal IDs.

 

When using c# you would use the parameter items[] = new[] {internalID, internalID, internalID}

 

To create a command line url it probably looks similar to that, but using "&items[]=internalID" etc.

 

I think. I'm not great with comnandline urls

Link to comment
Share on other sites

hooray4me

When you create a play request, use array of BaseItem internal IDs.

 

When using c# you would use the parameter items[] = new[] {internalID, internalID, internalID}

 

To create a command line url it probably looks similar to that, but using "&items[]=internalID" etc.

 

I think. I'm not great with comnandline urls

 

sooo... in trying to cross programming languages.... the yaml syntax for my command to start a show is:

  emby_start_show:
    url: http://tv.xxxx.com:8096/emby/Sessions/{{ session }}/Playing?ItemIds={{ show }}&PlayCommand=PlayNow&api_key={{ token }}
    method: POST
    headers:
      accept: '*/*'
      Content-Type: 'application/json'
    payload: '{"ControllingUserId":"{{ userid }}","SubtitleStreamIndex":0,"AudioStreamIndex":0,"StartIndex":0}'

I pass in the session, show and token variable.

 

The show variable is derived from a pre-defined list I created of show ID's...

 

IE)

show: '{% if is_state(''input_select.firetv_movies'',''Cinderella'') %} 24959
        {% elif is_state(''input_select.firetv_movies'',''Despicable Me'') %} 60872

I'd like to be able to select "Paw Patrol" from my list... in this scenario I'd have to get the ID of a specific episode... how would you try to select a random episode? Maybe pull all the episode ID's for the show series and then locally use random selection logic to chose what plays thru maybe a bash script?

Link to comment
Share on other sites

chef

Sorry yeah, itemIds is an array of internalItemIds.

 

Sorry, I wasnt at a computer so what I posted was a bit confusing.

 

Use a comma delimited array of IDs for itemIds, and that will start to play those items in squence.

 

Inorder to randomize/shuffle the IDs, you'd have to write your own logic to handle it.

 

Sorry for not being super clear about that.

Edited by chef
Link to comment
Share on other sites

chef

If you request series and narrow down results to, example paw patrol, then do a new item query for season, and then episodes.

 

Once you have the list of BaseItems use the internalItemId.

 

Im not versed in ymal so I'm not sure if it has a class which you could use to randomly choose IDs for your item array.

 

Edit: this is actually not nessessary, you can request items using the item query to get specific returns. I apologize again. Once you've sourced out an array of Paw Patrol Episode BaseItem info, then you'd randomly choose internalItemIds and stick them in The itemIds array if your play request...

 

Man! I hope I'm not making this more difficult for ya!

Edited by chef
Link to comment
Share on other sites

hooray4me

If you request series and narrow down results to, example paw patrol, then do a new item query for season, and then episodes.

 

Once you have the list of BaseItems use the internalItemId.

 

Im not versed in ymal so I'm not sure if it has a class which you could use to randomly choose IDs for your item array.

 

Edit: this is actually not nessessary, you can request items using the item query to get specific returns. I apologize again. Once you've sourced out an array of Paw Patrol Episode BaseItem info, then you'd randomly choose internalItemIds and stick them in The itemIds array if your play request...

 

Man! I hope I'm not making this more difficult for ya!

 

Oh, so ItemIds can be a comma delimited list?  /Playing?ItemIds=12345,54321,12345 fantastic!

 

One more question now that I have your ear.... can you think of a query that I can use to pull all itemid's, for a given series, from the api? 

Edited by robrhedrick
  • Like 1
Link to comment
Share on other sites

chef

In The C# API, you can request BaseItem info by using a couple different parameters in the ItemQuery, "Name" and "SeriesName".

 

I'm not exactly sure how that looks in a url.

 

I'd have to double check the swagger to see what that looks like.

 

The long way would be to request "Type" "Series", look for the Series name in the return data and use the ID to request BaseItem info on it.

 

But I'm pretty sure there is a faster way to get Series Info then requesting the root folder and drilling down.

 

I'll check swagger.

Edited by chef
Link to comment
Share on other sites

hooray4me

In The C# API, you can request BaseItem info by using a couple different parameters in the ItemQuery, "Name" and "SeriesName".

 

I'm not exactly sure how that looks in a url.

 

I'd have to double check the swagger to see what that looks like.

 

The long way would be to request "Type" "Series", look for the Series name in the return data and use the ID to request BaseItem info on it.

 

But I'm pretty sure there is a faster way to get Series Info then requesting the root folder and drilling down.

 

I'll check swagger.

 

I can curl a base url and pass in a json "payload" of parameters if they are accepted... just don't know which parameters to pass... If I can just a decent json response that includes everything I want, I can filter out the un-needed stuff.

  • Like 1
Link to comment
Share on other sites

chef

Check this out to get Series Info:

 

curl -X GET "http://localhost:8096/emby/Users/*ThisIsYourUserId*/Items?Limit=10&Recursive=true&IncludeItemTypes=Series&IsSeries=true&api_key=*YourASpiKey*" -H "accept: application/json"

 

 

I will figure out getting a bunch of Episode items next one minute :)

Link to comment
Share on other sites

hooray4me

Check this out to get Series Info:

 

curl -X GET "http://localhost:8096/emby/Users/*ThisIsYourUserId*/Items?Limit=10&Recursive=true&IncludeItemTypes=Series&IsSeries=true&api_key=*YourASpiKey*" -H "accept: application/json"

 

 

I will figure out getting a bunch of Episode items next one minute :)

 

Is there something like &SeriesTitle= ?

  • Like 1
Link to comment
Share on other sites

chef

On my Server this command would play Antman and the Wasp and then Infinity War right after

 

curl -X POST "http://localhost:8096/emby/Sessions/**SessionID**/Playing?ItemIds=16195&ItemIds=16197&PlayCommand=PlayNow&api_key=**APIKEY**" -H "accept: */*" -H "Content-Type: application/json" -d "{\"ControllingUserId\":\"string\",\"SubtitleStreamIndex\":0,\"AudioStreamIndex\":0,\"MediaSourceId\":\"string\",\"StartIndex\":0}"

 

SO that is how the URL should look when lining up a bunch of media to play in a list :)

  • Like 1
Link to comment
Share on other sites

chef

Is there something like &SeriesTitle= ?

 

 

One second I'll look :)

Link to comment
Share on other sites

chef

This might return the proper information:

 

curl -X GET "http://localhost:8096/emby/Users/**UserId**/Items?Limit=10&Recursive=true&IsSeries=true&NameStartsWithOrGreater=Paw%20Patrol&api_key=**APIKEY**" -H "accept: application/json"

  • Like 1
Link to comment
Share on other sites

hooray4me

This might return the proper information:

 

curl -X GET "http://localhost:8096/emby/Users/**UserId**/Items?Limit=10&Recursive=true&IsSeries=true&NameStartsWithOrGreater=Paw%20Patrol&api_key=**APIKEY**" -H "accept: application/json"

 

Thanks alot! I'll work on code conversion.

  • Like 1
Link to comment
Share on other sites

chef

Thanks alot! I'll work on code conversion.

 

Anytime sir! Hope I was able to help a bit :)

Link to comment
Share on other sites

hooray4me

Thanks alot! I'll work on code conversion.

 

That didn't work. Only thing I could find to do is add a Tag of PawPatrol to every single paw patrol episode. then:

/emby/Users/xxxx/Items?Recursive=true&IncludeItemTypes=Episode&Tags=PawPatrol

There's got to be a better way

Link to comment
Share on other sites

chef

That didn't work. Only thing I could find to do is add a Tag of PawPatrol to every single paw patrol episode. then:

/emby/Users/xxxx/Items?Recursive=true&IncludeItemTypes=Episode&Tags=PawPatrol
There's got to be a better way

Agreed. When I was testing some of the endpoints in the swagger I noticed there was missing information when using "IsSeries=true", and "NameStartsWith".

Missing information, like nothing returned...

 

There are three different possible ways to search for names in the API

 

NameStartsWith, NameStartsWithOrGreater, NameStartsWithOrLessThen

 

I'm gonna take a look and see what returns the best and I will get back to you.

Link to comment
Share on other sites

chef

That didn't work. Only thing I could find to do is add a Tag of PawPatrol to every single paw patrol episode. then:

/emby/Users/xxxx/Items?Recursive=true&IncludeItemTypes=Episode&Tags=PawPatrol
There's got to be a better way
Hi rob,

 

Here is what seems to work for me.

 

First thing to know is that if you use the "NameStartsWith" parameter for a show like "Paw Patrol" the you would use "Paw" and not the whole name.

 

 

Example:

"http://192.168.2.126:8096/emby/Items?Recursive=true&IncludeItemTypes=Series&NameStartsWith=Flash&api_key=dae5ce49e95e4117a2610d70adcaadb4"
 
In the example above I am searching for the series "Flash", which return "The Flash".

 

 

For "Paw Patrol" you would do something like this:

"http://192.168.2.126:8096/emby/Items?Recursive=true&IncludeItemTypes=Series&NameStartsWith=Paw&api_key=dae5ce49e95e4117a2610d70adcaadb4" -H "accept: application/json"
 
Take note of "Recursive" equals "true", and we utilize the "NameStartsWith" equaling "Paw".

 

This will return the Series Item Info. We need the "Id". In my case it is "Id: 13176".

 

 

Now we drill down into the series with another query request.

 

This time we tell the API to use the "ParentId" parameter and fill it in with the "Id" we just got from the prior request.

http://192.168.2.126:8096/emby/Items?Limit=5&Recursive=true&ParentId=13176&api_key=dae5ce49e95e4117a2610d70adcaadb4
 
Now the API return Season Item Data.

 

Grab the Id from the season you want to get episode info for. In my case, Season One was "Id: 1707"

 

And Finally we will drill down one more time into the Season folder , using the same ParentId parameter as before, to gather Episode Data:

http://192.168.2.126:8096/emby/Items?Limit=5&Recursive=true&ParentId=1707&api_key=dae5ce49e95e4117a2610d70adcaadb4
 
This will return a list of Episodes with their Id's attached, and those are Id's we want to use in the PlayRequest.

 

Please let me know if I have explained well enough.

 

The C# API has some shortcuts that allow a fast return of episode data without requesting three times, but that's not gonna help here.

Edited by chef
Link to comment
Share on other sites

hooray4me

Hi rob,

 

Here is what seems to work for me.

 

First thing to know is that if you use the "NameStartsWith" parameter for a show like "Paw Patrol" the you would use "Paw" and not the whole name.

 

 

Example:

"http://192.168.2.126:8096/emby/Items?Recursive=true&IncludeItemTypes=Series&NameStartsWith=Flash&api_key=dae5ce49e95e4117a2610d70adcaadb4"
 
In the example above I am searching for the series "Flash", which return "The Flash".

 

 

For "Paw Patrol" you would do something like this:

"http://192.168.2.126:8096/emby/Items?Recursive=true&IncludeItemTypes=Series&NameStartsWith=Paw&api_key=dae5ce49e95e4117a2610d70adcaadb4" -H "accept: application/json"
 
Take note of "Recursive" equals "true", and we utilize the "NameStartsWith" equaling "Paw".

 

This will return the Series Item Info. We need the "Id". In my case it is "Id: 13176".

 

 

Now we drill down into the series with another query request.

 

This time we tell the API to use the "ParentId" parameter and fill it in with the "Id" we just got from the prior request.

http://192.168.2.126:8096/emby/Items?Limit=5&Recursive=true&ParentId=13176&api_key=dae5ce49e95e4117a2610d70adcaadb4
 
Now the API return Season Item Data.

 

Grab the Id from the season you want to get episode info for. In my case, Season One was "Id: 1707"

 

And Finally we will drill down one more time into the Season folder , using the same ParentId parameter as before, to gather Episode Data:

http://192.168.2.126:8096/emby/Items?Limit=5&Recursive=true&ParentId=1707&api_key=dae5ce49e95e4117a2610d70adcaadb4
 
This will return a list of Episodes with their Id's attached, and those are Id's we want to use in the PlayRequest.

 

Please let me know if I have explained well enough.

 

The C# API has some shortcuts that allow a fast return of episode data without requesting three times, but that's not gonna help here.

 

 

Thanks @@chef! I will give it a try!

Link to comment
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...