Files.GetDirectory doesn't appear to honor Properties Parameter
#1
Hello all,

I have an application that I'd like to mark all media (mostly video) as watched / played. Not all of it is assigned to TvShows or Movies or Music.

So, I was attempting to do so with the Files.GetDirectory call (https://kodi.wiki/view/JSON-RPC_API/v8#F...tDirectory), but it appears like even though I specify PlayCount as a property I want to be returned, it is not honored (unless I'm doing something wrong).

It seems very similar to what was observed on this thread: https://forum.kodi.tv/showthread.php?tid...pid2802360

Example:

$jsonRequest = '{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": { "directory": "smb://192.168.29.3/TV/Watched/", "media": "files", "properties" : ["playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": 1}'

$requestUri = [String]::Format("{0}?request={1}",$KODI_URI,$jsonRequest)
$webclient.DownloadString($requestUri)

{"id":1,"jsonrpc":"2.0","result":{"files":[
{"file":"smb://192.168.29.3/TV/Watched/Against The Rules/","filetype":"directory","label":"Against The Rules","type":"unknown"},
{"file":"smb://192.168.29.3/TV/Watched/American Gothic/","filetype":"directory","label":"American Gothic","type":"unknown"},
{"file":"smb://192.168.29.3/TV/Watched/The Americans (2013)/","filetype":"directory","label":"The Americans (2013)","type":"unknown"},
..
..
{"file":"smb://192.168.29.3/TV/Watched/Once in a Lifetime Sessions with Moby.mp4","filetype":"file","label":"Once in a Lifetime Sessions with Moby.mp4","type":"unknown"},
{"file":"smb://192.168.29.3/TV/Watched/Real Time with Bill Maher_ Anniversary Special.mp4","filetype":"file","label":"Real Time with Bill Maher_ Anniversary Special.mp4","type":"unknown"}
],"limits":{"end":87,"start":0,"total":87}}}

According to the documentation, the call takes List.Fields.Files as a parameter, that should allow playcount:
     https://kodi.wiki/view/JSON-RPC_API/v8#L...elds.Files

Has anyone else hit this? Is there a workaround? Thanks in advance!
Reply
#2
The problem here is, that you have your movies in directories and what you are going to see then is the filetype "directory": "filetype":"directory"

AFAIK, a directory can't have a playcount. Only the file inside this directory is capable of. So I would recommend to change the media from "files" to "video": 

curl -s -X POST http://127.0.0.1:8080/jsonrpc -H 'Content-Type: application/json' --data '{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": { "directory": "smb://192.168.29.3/TV/Watched/", "media": "video", "properties" : ["playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": 1}'

in combination with "jq" this gives me a result of:

Code:
      {
        "file": "nfs://192.168.1.175/mnt/user/movieshd/ZULU-BLURAY/ZULU.iso",
        "filetype": "file",
        "id": 859,
        "label": "Zulu",
        "playcount": 0,
        "type": "movie"
      }
Reply
#3
Thanks so much for the reply. I really appreciate getting a better understanding of these APIs.

So the application attempts to mark all media under a given folder as watched that currently are not. Within that folder can be other folders, movies, library videos (which are usually TV episodes), or even podcasts (so audio, so the best match being music).

Optimally, it'd be great to minimize the calls and filter based on the playcount, but GetDirectory doesn't apparently allow filters. I'm able to do this via .GetMovies():

$jsonRequest = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"field": "playcount", "operator": "is", "value": "0"}, "properties" : ["playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": 1}'

As you noted, it's also not recursive, which is a shame but makes sense.

But I am a bit hung up of the final two results in this particular folder, which are video files in that folder's root:

..
{"file":"smb://192.168.29.3/TV/Watched/Once in a Lifetime Sessions with Moby.mp4","filetype":"file","label":"Once in a Lifetime Sessions with Moby.mp4","type":"unknown"},
{"file":"smb://192.168.29.3/TV/Watched/Real Time with Bill Maher_ Anniversary Special.mp4","filetype":"file","label":"Real Time with Bill Maher_ Anniversary Special.mp4","type":"unknown"}
],"limits":{"end":87,"start":0,"total":87}}}

Those don't appear to return playcount, either, and I expected it would have.

I'll continue to play around with this more for my own curiosity, but I'll continue to just limit myself to movies for now.
Reply
#4
(2020-04-06, 19:26)ParadoxGBB Wrote: But I am a bit hung up of the final two results in this particular folder, which are video files in that folder's root:

I would recommend to re-think your folder structure. I won´t mix movies that DO have their own subfolder with movies that DON´T have their own subfolder at the same source. That will cause unexpected behaviour probably. Simply decide which structure you will follow and I would recommend to always use movies stored in their own subfolder. 

For the rest, read my posting above again and take a look what I changed to get the playcount.
Reply
#5
(2020-04-13, 14:08)DaVu Wrote:
(2020-04-06, 19:26)ParadoxGBB Wrote: But I am a bit hung up of the final two results in this particular folder, which are video files in that folder's root:

I would recommend to re-think your folder structure. I won´t mix movies that DO have their own subfolder with movies that DON´T have their own subfolder at the same source. That will cause unexpected behaviour probably. Simply decide which structure you will follow and I would recommend to always use movies stored in their own subfolder. 

For the rest, read my posting above again and take a look what I changed to get the playcount. 

Thanks again for the reply, but I don't think you're hearing me: I want to mark all media watched, not just movies. TV shows and podcasts can be marked as consumed, too.

As for the folder structure, the structure is the integration with other applications, not just Kodi. It has been thought through --- all movies under "Watched" are "Watched".
Reply

Logout Mark Read Team Forum Stats Members Help
Files.GetDirectory doesn't appear to honor Properties Parameter0