I've had this idea bouncing around my head for a bit, and wanted to see if anybody else has thought of or attempted it. In short: Trakt watchlist/watchedlist integration.
The way I see this working is as a custom column. A separate script (either manually triggered or run on every launch) will download the users latest watchlist and watchedlist and store it locally, either in a global variable or written to disk. A custom column script will check each file against those locally cached lists and label each item as Watched Watchlisted (or some other more clever verbiage...). In my particular case, all of my movies have the imdbid in the filename, so matching would be exact and definite instead of fuzzy error-prone search-based matches. Without a hard-link like this in either the filename or in a companion txt/nfo file, I don't know how it would work. TV episodes might be just too complicated.
The biggest hurdle I can envision is handling Trakt's OAuth through scripting, this part might be easier achieved as a standalone EXE, the code for which I already have written in VB.net from another project.
Does this sound at all feasible? I have only just experimented lightly with XY scripting so I'm not sure of its full capabilities and limits. I would love to have a script like this, but I'm not confident that I'd be able to do it entirely from scratch in an XY script.
Script Idea: Trakt
Re: Script Idea: Trakt
I don't think that you can handle the authentication via OAuth in XY scripting.
So I'd use your external app to do this and let it download / parse the Trakt data
as well. Let it store it in UTF-8 / Unicode on disk in plain text (one item per line).
And then the custom column script can access that data easily. If you need help
with that part, post an example of a few file names that contain the id and
the destination .txt document of your external app with the necessary data for
them from Trakt...
So I'd use your external app to do this and let it download / parse the Trakt data
as well. Let it store it in UTF-8 / Unicode on disk in plain text (one item per line).
And then the custom column script can access that data easily. If you need help
with that part, post an example of a few file names that contain the id and
the destination .txt document of your external app with the necessary data for
them from Trakt...
One of my scripts helped you out? Please donate via Paypal
Re: Script Idea: Trakt
I made a quick test column script, and it works.
$wl is a permanent variable containing two ID's for testing purposes. In the first iteration I had it read from a file into a local variable, but that adds a lot of overhead to open, read, and close a text file thousands of times. It runs pretty quickly now: On a folder of ~4500 files it takes only about 3 seconds to refresh. The "production" list will be much longer than two lines though, which will likely slow it down further. Is this script good enough, or is there a better/faster way you might suggest?
Handling OAuth and downloading fresh lists I will handle outside of XY, by manually running a script that launches the external tool, then reads the results into a permanent variable. I could also add the ability to send watched items to Trakt with a custom toolbar button or context menu entry. It's all actually pretty easy once you handle the API calls outside of XY!
I do have one question though... I don't need/want this column to be visible anywhere but in my movies folder. Is there a way to save this column layout and have it automatically load *only* when this is the current folder?
Code: Select all
$imdbid = regexreplace(<cc_base>, ".*?\[(tt\d{7})\].*", "$1");
if strpos($wl, $imdbid) != -1 {
Return "Watched";
}
else {
Return "";
}
Handling OAuth and downloading fresh lists I will handle outside of XY, by manually running a script that launches the external tool, then reads the results into a permanent variable. I could also add the ability to send watched items to Trakt with a custom toolbar button or context menu entry. It's all actually pretty easy once you handle the API calls outside of XY!
I do have one question though... I don't need/want this column to be visible anywhere but in my movies folder. Is there a way to save this column layout and have it automatically load *only* when this is the current folder?
Re: Script Idea: Trakt
On large strings regexmatches() should be faster than strpos()
You could use View - Folder View Settings to store it for that folder...I don't need/want this column to be visible anywhere but in my movies folder
One of my scripts helped you out? Please donate via Paypal
Re: Script Idea: Trakt
It turns out that trakt doesn't require OAuth for grabbing the list of watched movies for any user. So my external tool downloads the JSON string, parses out the imdbid's, and writes them to a text file. Also I think this *could* be adapted for other people even if they don't have imdbid's in their filenames. If the text file listed the imdbid and the default title, the XY script could also look for exact title matches.
I switched the column trigger to List instead of Browse, so the speed isn't even an issue now.highend wrote:On large strings regexmatches() should be faster than strpos()
Thanks, I didn't know about that feature!highend wrote:You could use View - Folder View Settings to store it for that folder...
Re: Script Idea: Trakt
I am not really experienced in this, but since it is only a json I just thought I'd make you aware of a couple XY commands you might not know about that may be able to avoid you using an external tool if you wanted, and they are:
download()
readurl()
readurlUTF8()
download()
readurl()
readurlUTF8()
Re: Script Idea: Trakt
The API call requires custom headers in the GET request, one containing the API version you're working with and another with your API key. So those script commands wouldn't work.
Re: Script Idea: Trakt
Show an example of this GET request please (mask your API key), I want to try that with a different programming language...The API call requires custom headers in the GET request, one containing the API version you're working with and another with your API key. So those script commands wouldn't work.
One of my scripts helped you out? Please donate via Paypal
Re: Script Idea: Trakt
GET /users/YOURUSERNAME/watched/movies HTTP/1.1highend wrote:Show an example of this GET request please (mask your API key), I want to try that with a different programming language...
Host: api.trakt.tv
Content-Type: application/json
trakt-api-key: YOURAPIKEY
trakt-api-version: 2
Re: Script Idea: Trakt
Thanks.
https://trakt.docs.apiary.io/#reference ... -watchlist
Isn't this what you're about to get?
https://trakt.docs.apiary.io/#reference ... -watchlist
Code: Select all
Get watchlist
OAuth Required - Pagination Optional - Extended Info
Returns all items in a user's watchlist filtered by type.
One of my scripts helped you out? Please donate via Paypal
Re: Script Idea: Trakt
This is the one that doesn't require OAuth (for watched history, not watchlist): https://trakt.docs.apiary.io/#reference ... et-watched