viewpoint-particle

Author Topic: JSON API for querying TVDB and IMDB  (Read 1934 times)

Bardmaster

  • Newbie
  • *
  • Posts: 4
JSON API for querying TVDB and IMDB
« on: April 30, 2017, 07:56:19 am »
Hi all, I see there is a command set udfGetJSONList and I'm wondering if anybody created a WBT script to use this to query TVDB (and potentially IMDB but I haven't researched that site yet). 

TVDB has the following API controls identified:

https://api.thetvdb.com/swagger#!/Search/get_search_series_params

I am very experienced with using Winbatch for Windows scripting, and just finished a script that takes an MPEG file of Live TV created by NextPVR (and Emby, which I'm trying out), strips out the commercials and converts to MP4 using comskip and ffmpeg (both freeware versions).  I'm happy to share this code if somebody can help me take the next step and use the TS container's metadata, or straight from filename if needed, to query TVDB and identify the ID to capture showname, season, episode info.

td

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
Re: JSON API for querying TVDB and IMDB
« Reply #1 on: May 02, 2017, 06:56:19 am »
Since JSON is a well defined standard you might want to consider writing your own JSON parsing tool using WIL string functions.  It is the method I prefer over the Tech Database approach.  You can create the simple parser as either API specific or generalized depending on how much time you want to spend on it and your needs.  The REST calls can be handled using either WinBatch's CLR hosting (.Net), the WinInet extender, or the WinBatch COM subsystem using the the COM interfaces accessed via the "winhttp.winhttprequest.5.1" progid.  Generally, COM is the simplest approach but your mileage my vary.

Speaking from experience with REST+JSON and since you are an experience WinBatch user, a home grown script shouldn't take to much time or effort. 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


JTaylor

  • Pundit
  • *****
  • Posts: 786
    • Data & Stuff Inc.
Re: JSON API for querying TVDB and IMDB
« Reply #2 on: May 02, 2017, 07:14:46 am »
Also, you can easily embed a browser in a dialog and let javascript do most of the heavy lifting and easily extract what you need.

Jim

td

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
Re: JSON API for querying TVDB and IMDB
« Reply #3 on: May 02, 2017, 07:39:54 am »
To each his own.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


Bardmaster

  • Newbie
  • *
  • Posts: 4
Re: JSON API for querying TVDB and IMDB
« Reply #4 on: May 02, 2017, 05:59:43 pm »
Is there a command reference somewhere?  I am unable to find any documentation on commands, format, syntax, etc.

JTaylor

  • Pundit
  • *****
  • Posts: 786
    • Data & Stuff Inc.
Re: JSON API for querying TVDB and IMDB
« Reply #5 on: May 02, 2017, 06:17:48 pm »
I think you are going to have to be a bit more specific...not sure for which thing you are wanting documentation  :)

Jim

Bardmaster

  • Newbie
  • *
  • Posts: 4
Re: JSON API for querying TVDB and IMDB
« Reply #6 on: May 02, 2017, 07:02:54 pm »
any and all commands related to JSON queries, retrievals, etc.  I don't have any documentation in my WIL manual and can't find online how to develop a JSON API script.  I see the syntax at THETVDB.com, like this:

SeriesSearchData {
aliases (Array[string], optional),
banner (string, optional),
firstAired (string, optional),
id (integer, optional),
network (string, optional),
overview (string, optional),
seriesName (string, optional),
status (string, optional)
}

which apparently responds with

{
  "aliases": [
    "string"
  ],
  "banner": "string",
  "firstAired": "string",
  "id": 0,
  "network": "string",
  "overview": "string",
  "seriesName": "string",
  "status": "string"
}there,

but how do I initiate the SeriesSearchData using WIL?  What is the syntax for logging in and authenticating my API key?  I see an example script for this, and in the absence of add'l docs will model from it and trial/error, but would prefer to understand how to invoke these commands in a WIL script.

JTaylor

  • Pundit
  • *****
  • Posts: 786
    • Data & Stuff Inc.
Re: JSON API for querying TVDB and IMDB
« Reply #7 on: May 02, 2017, 07:32:55 pm »
This is like asking how to get to Rome...maybe not really "ALL" roads go there but still many, many ways and much of the answer to many of them really isn't a WinBatch question.   On the WinBatch front you could take a look at the WinInet Extender, it has examples for submitting requests and retrieving the reply.   Look at iHostOpen.    On the MS front I am guessing things like WinHttpRequest.5.1 or XMLHTTP would probably get you part way down the road along with a few others.   As far as reading/parsing the results Tony suggested using the WIL String Functions to write your own parser.  Those start with "Str" in the WIL Help File.   If you search the TechDatabase and/or msdn.com for some of the things I mentioned you will probably find some more examples.   Sounds like you found some JSON stuff already.

As far as telling you how the API works that would make me feel like I was doing your school Homework for you  ;)

Jim

Bardmaster

  • Newbie
  • *
  • Posts: 4
Re: JSON API for querying TVDB and IMDB
« Reply #8 on: May 02, 2017, 07:44:53 pm »
OK I've used wininit to perform ftp and basic html interface functions.  I'll refresh the memory on that front and see how it works for these TVDB calls.  Thanks!

td

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
Re: JSON API for querying TVDB and IMDB
« Reply #9 on: May 03, 2017, 08:07:23 am »
Simple JSON based "APIs" are often little more than a PUT (sometimes GET)  with the appropriate  content types in the request headers and the data as a well formatted JSON string.   The "winhttp.winhttprequest.5.1" COM Automation object is simple and well suited for this.  The WinInet extender works well too.  The key is figuring out what the many over-hyped APIs are expecting and understanding a little bit about the HTTP and JSON standards.  Many or at least some "API" providers include REST versions of their "APIs" in their documentation.  In these cases, the figuring is like living in the summertime - easy.

Should add that occasionally things can get more complicated but as long as it is "HTTP" or "HTTPS" and JSON based, it should be mostly doable with the tools mentioned in this topic.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


stanl

  • Pundit
  • *****
  • Posts: 650
Re: JSON API for querying TVDB and IMDB
« Reply #10 on: May 13, 2017, 08:19:59 am »
Maybe a bit off topic, but Powershell has built in REST capabilities and json conversions. Sometimes as simple as 1 line
Code: [Select]
$j = Invoke-WebRequest -Uri http://gomashup.com/json.php?fds=geo/usa/zipcode/state/NC | ConvertFrom-Json

and Powershell works well with WB

td

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
Re: JSON API for querying TVDB and IMDB
« Reply #11 on: May 15, 2017, 08:10:04 am »
There are numerous JSON .Net assemblies available that might be used with WinBatch CLR hosting and avoid using PowerShell - which is something WinBatch users have told us they wish to avoid.  But again, if a WinBatch user has moderate script writing skills, an inclination to learn and a bit of curiosity, rolling their own JSON handler is not difficult either. 

Perhaps a pure WinBatch JSON UDF library should be added to the Tech Database in the future.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


stanl

  • Pundit
  • *****
  • Posts: 650
Re: JSON API for querying TVDB and IMDB
« Reply #12 on: May 17, 2017, 03:42:33 am »
and for some json you can use WinHTTP and javascript.

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/JSON/MSScriptControl+Parse~JSON~Using~Eval.txt

or just search for json in tech database where you will find examples for .net  Tony alluded to.

Final Note:  I remember someone posting the use of WB Binary Tags to process json. With enough parameters that could produce a well-thought UDF.

P.S. I'm not one of the WB users who didn't want to integrate Powershell, in fact, just the opposite and Deana helped me with a semi-generic script to run PS code from the WB CLR.

td

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
Re: JSON API for querying TVDB and IMDB
« Reply #13 on: May 17, 2017, 08:34:06 am »
Yes, there are JSON scripts in the Tech Database as already suggested previously in this topic's thread.    But the JSON standard is neither mysterious nor complicated and a good set of UDFs with minimal external dependencies has it advantages 

No one said you were "one of the WB users who didn't want to integrate Powershell" and Deana's assistance was based on WinBatch + PowerShell scripts I originally wrote.   The point was that based on user feedback many WinBatch users are not interested in solutions that involve PowerShell.   


"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


kdmoyers

  • Full Member
  • ***
  • Posts: 183
Re: JSON API for querying TVDB and IMDB
« Reply #14 on: May 22, 2017, 04:06:07 am »
<< Perhaps a pure WinBatch JSON UDF library should be added to the Tech Database in the future. >>

Man, that would be awesome!!
-Kirby
The mind is everything; What you think, you become.