@@ -30,6 +30,16 @@ BEGIN {
3030 }
3131}
3232
33+ sub _read_season_meta {
34+ my ($self , $showid , $seasonid ) = @_ ;
35+ try {
36+ my $bytes = read_file($self -> {tvmeta }." /$showid /$seasonid /season.json" );
37+ my $meta = decode_json($bytes );
38+ return $meta ;
39+ } catch($e ) {}
40+ return ;
41+ }
42+
3343sub readtvdir {
3444 my ($self , $tvshows , $source , $b_tvdir ) = @_ ;
3545 my $dh ;
@@ -63,8 +73,14 @@ sub readtvdir {
6373 catch($e ) {}
6474 $tvshows -> {$showid } = \%show ;
6575 }
66- $tvshows -> {$showid }{seasons }{$season } //= {};
67- $tvshows -> {$showid }{seasons }{$season }{" $source /$b_filename " } = {name => $filename , isdir => (-d _ // 0)+0};
76+ $tvshows -> {$showid }{seasons }{$season } //= {
77+ editions => {},
78+ do {
79+ my $meta = $self -> _read_season_meta($showid , $season );
80+ $meta ? (meta => $meta ) : ()
81+ },
82+ };
83+ $tvshows -> {$showid }{seasons }{$season }{editions }{" $source /$b_filename " } = {name => $filename , isdir => (-d _ // 0)+0};
6884 }
6985 closedir ($dh );
7086}
@@ -80,21 +96,6 @@ sub _build_tv_library {
8096 my $b_tvdir = $self -> {server }{settings }{SOURCES }{$source }{folder };
8197 $self -> readtvdir(\%tvshows , $source , $b_tvdir );
8298 }
83- # load the season metadata, maybe remove this if we allow querying a show without a season
84- while (my ($showid , $show ) = each %tvshows ) {
85- while (my ($seasonid , $season ) = each %{$show -> {seasons }}) {
86- my $meta ;
87- try {
88- my $bytes = read_file($self -> {tvmeta }." /$showid /$seasonid /season.json" );
89- $meta = decode_json($bytes );
90- } catch($e ) {}
91- $meta or next ;
92- # HACK: modifies each season item as there isn't a season object
93- foreach my $value (values %$season ) {
94- $value -> {plot } = $meta -> {overview };
95- }
96- }
97- }
9899 \%tvshows
99100}
100101
@@ -104,15 +105,15 @@ sub _get_tv_item {
104105 exists $tvshows -> {$showid }{seasons }{$seasonid } or die " season $seasonid does not exist" ;
105106 my $seasonitem = $tvshows -> {$showid }{seasons }{$seasonid };
106107 my $sourcemap = $self -> {server }{settings }{SOURCES };
107- my $meta ;
108- try {
109- my $bytes = read_file( $self -> { tvmeta }. " / $showid / $seasonid /season.json " );
110- $meta = decode_json( $bytes ) ;
111- } catch( $e ) {}
112- $source or return bless {season => $seasonitem , id => $seasonid , sourcemap => $sourcemap , ( $meta ? ( meta => $meta ) : ()) }, ' MHFS::Kodi::Season' ;
108+ # TODO: Instead of updating the tv library here, the library should be updated when new metadata is loaded
109+ if (! exists $seasonitem -> { meta }) {
110+ my $meta = $self -> _read_season_meta( $showid , $seasonid );
111+ $seasonitem -> { meta } = $meta if $meta ;
112+ }
113+ $source or return bless {season => $seasonitem , id => $seasonid , sourcemap => $sourcemap }, ' MHFS::Kodi::Season' ;
113114 $b64_item or die " b64_item not provided" ;
114115 my $path = abs_path($self -> {server }{settings }{SOURCES }{$source }{folder } .' /' . decode_base64url($b64_item ));
115- if (!$path || rindex ($path , $self -> {server }{settings }{SOURCES }{$source }{folder }, 0) != 0, ! -f $path ) {
116+ if (!$path || rindex ($path , $self -> {server }{settings }{SOURCES }{$source }{folder }, 0) != 0 || ! -f $path ) {
116117 die " item not found" ;
117118 }
118119 {b_path => $path }
0 commit comments