@@ -885,7 +885,96 @@ var Pluto = (function () {
885885
886886 var vodIndex = null ;
887887
888+ /*
889+ * Which genres are film genres.
890+ *
891+ * Labelling an item "movie" is not the same as belonging in Movies. A
892+ * handball match, a diving championship and an MTV Unplugged concert all
893+ * come back typed as films -- each with its own seriesID, no seasons,
894+ * nothing in the item to say otherwise -- and the site still files them
895+ * under Sport, under Musik and under the series MTV Unplugged. Nothing on
896+ * the item distinguishes them from a documentary or a stand-up special,
897+ * which do belong in Movies.
898+ *
899+ * The catalogue answers it indirectly. Its categories are grouped by
900+ * mainCategories into a dozen or so sections, and one of them holds
901+ * nothing but films -- not a single series among them. That section is
902+ * where the site's own Movies rows come from, so the genres appearing in
903+ * it are, by construction, the genres Pluto considers film genres. Sports
904+ * and Music are never among them; Documentary, Comedy, Drama and Horror
905+ * always are.
906+ *
907+ * So the section is read for its genres rather than its contents, and
908+ * every film in those genres counts wherever it happens to be filed. That
909+ * keeps the documentaries and the stand-up, which live in mixed sections
910+ * of their own, while still leaving out the matches and the concerts.
911+ * Nothing here is named or numbered: the ids are regional, the genre list
912+ * is whatever that section turns out to contain, and both are read afresh
913+ * from each response.
914+ */
915+ function filmSections ( list ) {
916+ var known = { } ;
917+ var mixed = { } ;
918+ var sections = { } ;
919+
920+ list . forEach ( function ( c ) {
921+ var holdsSeries = ( c . items || [ ] ) . some ( isSeries ) ;
922+
923+ ( c . mainCategories || [ ] ) . forEach ( function ( m ) {
924+ var id = text ( m . categoryID ) ;
925+ if ( ! id ) {
926+ return ;
927+ }
928+ known [ id ] = true ;
929+ if ( holdsSeries ) {
930+ mixed [ id ] = true ;
931+ }
932+ } ) ;
933+ } ) ;
934+
935+ Object . keys ( known ) . forEach ( function ( id ) {
936+ if ( ! mixed [ id ] ) {
937+ sections [ id ] = true ;
938+ }
939+ } ) ;
940+
941+ return sections ;
942+ }
943+
944+ /*
945+ * Null rather than an empty set when the catalogue has no section of its
946+ * own for films, or is arranged some way this does not recognise. The
947+ * caller then leaves every film where it is, so Movies is looser than the
948+ * site rather than empty.
949+ */
950+ function filmGenres ( list ) {
951+ var sections = filmSections ( list ) ;
952+ var genres = { } ;
953+ var found = false ;
954+
955+ list . forEach ( function ( c ) {
956+ var filed = ( c . mainCategories || [ ] ) . some ( function ( m ) {
957+ return sections [ text ( m . categoryID ) ] === true ;
958+ } ) ;
959+
960+ if ( ! filed ) {
961+ return ;
962+ }
963+
964+ ( c . items || [ ] ) . forEach ( function ( item ) {
965+ if ( isSeries ( item ) ) {
966+ return ;
967+ }
968+ genres [ text ( item . genre ) || "Other" ] = true ;
969+ found = true ;
970+ } ) ;
971+ } ) ;
972+
973+ return found ? genres : null ;
974+ }
975+
888976 function buildIndex ( list ) {
977+ var films = filmGenres ( list ) ;
889978 var seen = { } ;
890979 var ix = { movies : { } , shows : { } } ;
891980
@@ -901,6 +990,10 @@ var Pluto = (function () {
901990 seen [ id ] = true ;
902991
903992 genre = text ( item . genre ) || "Other" ;
993+ if ( kind === "movies" && films && films [ genre ] !== true ) {
994+ return ;
995+ }
996+
904997 if ( ! ix [ kind ] [ genre ] ) {
905998 ix [ kind ] [ genre ] = [ ] ;
906999 }
0 commit comments