Jump to content

Recommended Posts

Posted

Hello,

I have a strange issue with the Emby API in PHP. I can get it to work in CURL via cmd line and in a browser but when I do the same thing with PHP/Curl it doesn't work.

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://XXXURLXXX:8096/Items?Recursive=true&AnyProviderIdEquals=tmdb.19995&api_key=XXXAPIXXX');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $output = curl_exec($ch);

I copied the headers from the CURL command via browser and it still didn't work. Anyone have a working example of PHP w/ Curl with the options that work? The weird thing is I have my Emby behind a reverse proxy HAPROXY with https and my web app is working fine with my URL.

Posted

The server is refusing the connection. I asked the user and he said there is nothing between the server and the internet beyond a pfsense firewall with the ports forwarded.

I didn't really see any php/curl examples online so hoping someone here has one that is working for sure so I can verify its not my code causing the issue.

Posted (edited)

Hello,

I asked the user if they could use the web app and then pull a log. They said they think this one should cover that but I wasn't sure what to search for in regard to api access to verify if this shows the issue. If this log is not helpful please let me know what I should look for.

I searched this one for 'refused' but got nothing back.

embyserver-63895910400.txt

Edited by bjd223
Typo
Posted

Do you use a reverse proxy?

Posted

The user says they do not, but I can double check if you are thinking they might.

Posted

And it could also just be that they don't have any data matching your query.

Posted

Well the whole point of the query is to see if they have a movie on their server already. Here is the actual code.

function emby_checkmovie($id_tmdb)
{
  global $conn;
  
  $sql1 = "SELECT url_emby, token_emby FROM ou WHERE id = '".intval($_SESSION["gid"])."';";
  $result1 = $conn -> query($sql1);
  
  if ($result1 -> num_rows > 0)
  {
    $found = false;
    $row1 = $result1 -> fetch_assoc();
    
    $params = array(
      'Recursive' => 'true',
      'AnyProviderIdEquals' => 'tmdb.'.$id_tmdb,
      'api_key' => $row1["token_emby"]
    );
    
    $urlparams = http_build_query($params);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $row1["url_emby"]."/Items?".$urlparams);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    $obj = json_decode($output, false);
    //echo 'error: ' . curl_error($ch);
    
    if ($obj -> TotalRecordCount > 0)
    {
      // debug //
      //echo "<pre>";
      //print_r($obj);
      //echo "</pre>";
      
      foreach ($obj -> Items as $item)
      {
        if ($item -> Type == "Movie")
        {
          return true;
        }
      }
    }
  }
  
  return false;
}

If there is no matching Movie on the server the emby api returns

stdClass Object
(
    [Items] => Array
        (
        )

    [TotalRecordCount] => 0
)

If there is a match it returns something like

stdClass Object
(
    [Items] => Array
        (
            [0] => stdClass Object
                (
                    [Name] => The Toxic Avenger Unrated
                    [ServerId] => f1743949139947b89a7c937d54f57ae8
                    [Id] => 69884
                    [RunTimeTicks] => 61305710000
                    [IsFolder] => 
                    [Type] => Movie
                    [ImageTags] => stdClass Object
                        (
                            [Primary] => 130517f9c7e4776aa1fefce2d58c5818
                            [Logo] => 5bd73eac75d3f7d869a64ae7a87d2356
                        )

                    [BackdropImageTags] => Array
                        (
                            [0] => daba2c19d9cda34ec7a2fd5562689e8c
                        )

                    [MediaType] => Video
                )

        )

    [TotalRecordCount] => 1
)

Then my function returns true/false based on that response.

This works fine on my Emby server and on the user's Emby server via curl at the windows CMD prompt and the browser. However it only works on my server via curl from PHP. So I think it is something with either curl on the webserver or the webserver itself.

I had no luck finding a working example of the API via PHP which I think would be helpful here.

Posted

OK if you can get it to work one way but not the other, then I would suggest making sure that the requests that are sent are identical. Maybe something like wireshark could help with that.

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...