JSON API for querying TVDB and IMDB

Started by Bardmaster, April 30, 2017, 07:56:19 AM

Previous topic - Next topic

Bardmaster

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

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. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

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

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Bardmaster

Is there a command reference somewhere?  I am unable to find any documentation on commands, format, syntax, etc.

JTaylor

I think you are going to have to be a bit more specific...not sure for which thing you are wanting documentation  :)

Jim

Bardmaster

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

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

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

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Maybe a bit off topic, but Powershell has built in REST capabilities and json conversions. Sometimes as simple as 1 line

$j = Invoke-WebRequest -Uri http://gomashup.com/json.php?fds=geo/usa/zipcode/state/NC | ConvertFrom-Json


and Powershell works well with WB

td

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

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

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.   


"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

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