Skip to content

Commit

Permalink
ADD: [leanback] search tv shows
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed Mar 29, 2016
1 parent 7c0d201 commit 257e8b7
Showing 1 changed file with 67 additions and 9 deletions.
76 changes: 67 additions & 9 deletions tools/android/packaging/xbmc/src/org/xbmc/kodi/XBMCJsonRPC.java.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ public class XBMCJsonRPC
private String SEARCH_MOVIES_JSON =
"{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.GetMovies\", "
+ "\"params\": { \"filter\": {%s}, "
+ "\"limits\": { \"start\" : 0, \"end\": %d}, "
+ "\"limits\": { \"start\" : 0, \"end\": 10}, "
+ "\"properties\" : [\"imdbnumber\", \"title\", \"tagline\", \"thumbnail\", \"fanart\"], "
+ "\"sort\": { \"order\": \"ascending\", \"method\": \"title\", \"ignorearticle\": true } }, "
+ "\"id\": \"1\"}";

private String SEARCH_SHOWS_JSON =
"{\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.GetTVShows\",\"params\":{\"filter\":{%s},\"limits\":{\"start\":0,\"end\":10},\"properties\":[\"imdbnumber\",\"title\",\"plot\",\"thumbnail\",\"fanart\"],\"sort\":{\"order\":\"descending\",\"method\":\"lastplayed\",\"ignorearticle\":true}},\"id\":\"1\"}";

private NotificationManager mNotificationManager;

public JSONObject request(String jsonRequest)
Expand Down Expand Up @@ -191,13 +194,12 @@ public class XBMCJsonRPC

try
{
int limit = 10;
JSONObject req = request(String.format(SEARCH_MOVIES_JSON, /*"\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"", limit));*/
"\"or\": [" +
"{\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"}, " +
"{\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"set\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"actor\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"actor\", \"value\": \"" + query + "\"}]"
, limit));
"{\"operator\": \"contains\", \"field\": \"director\", \"value\": \"" + query + "\"}]"));

if (req == null)
return null;
Expand All @@ -216,6 +218,30 @@ public class XBMCJsonRPC
return null;
}

try
{
JSONObject req = request(String.format(SEARCH_SHOWS_JSON, /*"\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"", limit));*/
"\"or\": [" +
"{\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"actor\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"director\", \"value\": \"" + query + "\"}]"));
if (req == null)
return null;

JSONObject results = req.getJSONObject("result");
JSONArray tvshows = results.getJSONArray("tvshows");

for (int i = 0; i < tvshows.length(); ++i)
{
JSONObject tvshow = tvshows.getJSONObject(i);
mc.addRow(new Object[]{tvshow.getString("movieid"), tvshow.getString("title"), tvshow.getString("plot"), tvshow.getString("thumbnail"), tvshow.getString("fanart")});
}
} catch (Exception e)
{
e.printStackTrace();
return null;
}

return mc;
}

Expand All @@ -238,10 +264,10 @@ public class XBMCJsonRPC
{
JSONObject req = request(String.format(SEARCH_MOVIES_JSON, /*"\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"", limit));*/
"\"or\": [" +
"{\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"}, " +
"{\"operator\": \"contains\", \"field\": \"actor\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"actor\", \"value\": \"" + query + "\"}]"
, limit));
"{\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"set\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"actor\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"director\", \"value\": \"" + query + "\"}]"));
if (req == null)
return null;

Expand All @@ -267,6 +293,38 @@ public class XBMCJsonRPC
return null;
}

try
{
JSONObject req = request(String.format(SEARCH_SHOWS_JSON, /*"\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"", limit));*/
"\"or\": [" +
"{\"operator\": \"contains\", \"field\": \"title\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"actor\", \"value\": \"" + query + "\"}," +
"{\"operator\": \"contains\", \"field\": \"director\", \"value\": \"" + query + "\"}]"));
if (req == null)
return null;

JSONObject results = req.getJSONObject("result");
JSONArray tvshows = results.getJSONArray("tvshows");

for (int i = 0; i < tvshows.length() && totCount < limit; ++i)
{
JSONObject tvshow = tvshows.getJSONObject(i);
mc.addRow(new Object[]
{
tvshow.getString("tvshowid"),
tvshow.getString("title"),
tvshow.getString("plot"),
XBMCImageContentProvider.GetImageUri(getBitmapUrl(tvshow.getString("thumbnail"))).toString(),
Uri.parse("videodb://tvshows/titles/" + tvshow.getString("tvshowid") + "?showinfo=true"),
});
totCount++;
}
} catch (Exception e)
{
e.printStackTrace();
return null;
}

return mc;
}

Expand Down

0 comments on commit 257e8b7

Please sign in to comment.