Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ there. To use `tv` from any folder, symlink it into a directory on your `PATH`.

The panel opens to **Library** in grid view. Browse collection folders or turn off
**Show subfolders as collections** to see their movies together. Search, switch to list view, and sort by title,
runtime, year or IMDb rating. Genre and actor/director filters are available above the movies;
runtime, year or IMDb rating. Cards show the US age rating (G to NC-17) from TMDB. Genre, age rating
and actor/director filters are available above the movies;
select a person or genre on a movie's detail page to browse related films in your library. New
files and due metadata retries are checked automatically every minute.

Expand Down
11 changes: 8 additions & 3 deletions docs/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ are remembered in this browser. The theme button cycles through **Auto**, **Ligh
Auto follows the Mac's appearance setting, and the chosen mode is remembered.
Icon labels appear on hover or keyboard focus; Escape dismisses the label.

The genre, language and film-collection menus and searchable actor/director picker filter movies
at the current location. **No collection** finds entries without a TMDB film collection, including
unmatched files. Language matches any listed film language. Sort and filter menus follow the
The genre, language, age-rating and film-collection menus and searchable actor/director picker
filter movies at the current location. **No collection** finds entries without a TMDB film
collection, including unmatched files. Language matches any listed film language. Age ratings are
TMDB's US certifications (G, PG, PG-13, R, NC-17), listed from least to most restrictive and shown
beside the year and runtime on cards and detail pages. The theatrical rating is preferred over
other releases. **No age rating** finds films that are unmatched, unrated (NR) or have no US
certification on TMDB. Cached movie information that lacks an age-rating check refreshes in the
background to add one. Sort and filter menus follow the
chosen appearance. Clear a person filter with the single
clear button inside its field. Watched status and **Show subfolders as collections** sit beside the
actor/director picker; all controls stay visible as the toolbar wraps in narrow windows. Each
Expand Down
8 changes: 8 additions & 0 deletions tests/test_catalogue.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ test('people filtering includes directors and cast and combines with genres', ()
assert.equal(selectMovies(items, {person:'fukunaga'})[0].id, 'a');
assert.equal(selectMovies(items, {person:'Daniel Craig', genre:'Drama'}).length, 1);
});
test('age ratings filter by exact US certification or its absence and combine with genres', () => {
const entries = [{...movies[0], certification:'PG-13'}, {...movies[1], certification:'R'}, {...movies[2], certification:null}, {...movies[2], id:'d'}];
assert.deepEqual(selectMovies(entries, {certification:'PG-13'}).map(m => m.id), ['a']);
assert.deepEqual(selectMovies(entries, {certification:'PG'}), []);
assert.deepEqual(selectMovies(entries, {certification:'none'}).map(m => m.id), ['c', 'd']);
assert.deepEqual(selectMovies(entries, {certification:'R', genre:'Drama'}), []);
assert.deepEqual(selectMovies(entries, {certification:'none', genre:'Drama'}).map(m => m.id), ['c', 'd']);
});
test('film collections filter by provider ID across folders and combine with other filters', () => {
const entries = [
{...movies[0], languages:[{code:'en',name:'English'},{code:'hi',name:'Hindi'}], collection:{id:42,name:'Example Collection'}, root:'/movies', collection_path:'/movies/Part One'},
Expand Down
25 changes: 23 additions & 2 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ def test_languages_collection_and_characters_are_cached_without_changing_name_fi
self.assertIsNone(data['collection'])
self.assertEqual(data['characters'], {})

def test_us_certification_prefers_theatrical_and_ignores_unrated_or_other_regions(self):
def releases(*regions):
return dict(self.details, release_dates={'results': [
{'iso_3166_1': code, 'release_dates': entries} for code, entries in regions]})
cases = [
(releases(('GB', [{'type': 3, 'certification': '15'}]),
('US', [{'type': 4, 'certification': 'PG'}, {'type': 3, 'certification': 'NR'},
{'type': 3, 'certification': ' pg-13 '}, {'type': 2, 'certification': 'R'}])), 'PG-13'),
(releases(('US', [None, {'type': 3, 'certification': ''}, {'type': 6, 'certification': 'R'}])), 'R'),
(releases(('GB', [{'type': 3, 'certification': 'PG'}]), ('US', [{'type': 3, 'certification': 'NR'}])), None),
(self.details, None),
]
for details, expected in cases:
with self.subTest(expected=expected), mock.patch.object(self.metadata, 'request', return_value=details):
self.assertEqual(self.metadata.fetch(1)['certification'], expected)
self.assertIsNone(Metadata(State(self.state.path)).cache[1]['certification'])
with mock.patch.object(self.metadata, 'request', return_value=dict(self.details, release_dates=['invalid'])), \
self.assertRaisesRegex(RuntimeError, 'invalid release dates'):
self.metadata.fetch(1)

def test_wikipedia_uses_english_sitelink_and_persists_offline(self):
url = 'https://en.wikipedia.org/wiki/Example_(film)'
details = dict(self.details, external_ids={'wikidata_id': 'Q123'})
Expand All @@ -88,7 +108,7 @@ def test_wikipedia_uses_english_sitelink_and_persists_offline(self):
with mock.patch.object(self.metadata, 'request', return_value=details) as tmdb, \
mock.patch('urllib.request.urlopen', return_value=io.BytesIO(json.dumps(response).encode())) as wikidata:
self.metadata.enrich(self.movie, self.state.movie(self.movie.path)['match'], False)
tmdb.assert_called_once_with('movie/1', {'append_to_response': 'credits,external_ids', 'language': 'en-US'})
tmdb.assert_called_once_with('movie/1', {'append_to_response': 'credits,external_ids,release_dates', 'language': 'en-US'})
request = wikidata.call_args.args[0]
self.assertEqual(urllib.parse.parse_qs(urllib.parse.urlsplit(request.full_url).query), {
'action': ['wbgetentities'], 'ids': ['Q123'], 'props': ['sitelinks/urls'],
Expand Down Expand Up @@ -453,7 +473,8 @@ def test_negative_cache_retries_after_upgrade_or_expiry_but_keeps_manual_decisio
self.metadata.jobs.task_done()
self.metadata.pending.clear()
self.metadata.cache[1] = {'tmdb_id': 1, 'imdb_id': None, 'wikidata_id': None, 'wikipedia_url': None,
'languages': [], 'collection': None, 'characters': {}, 'title': 'Example'}
'languages': [], 'collection': None, 'characters': {}, 'certification': None,
'title': 'Example'}
self.state.update_movie(self.movie.path, match={'tmdb_id': 1, 'source': 'manual', 'status': 'matched'})
self.metadata.enqueue(self.movie)
self.assertTrue(self.metadata.jobs.empty())
Expand Down
7 changes: 5 additions & 2 deletions tvcast/catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
function normalize(value) {
return String(value || '').normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLocaleLowerCase();
}
// US age ratings in increasing strictness, matching metadata.CERTIFICATIONS.
const CERTIFICATIONS = ['G', 'PG', 'PG-13', 'R', 'NC-17'];
function defaultSortDescending(sort) { return sort === 'year' || sort === 'score'; }
function movieAttention(movie) {
const match = movie.match || {};
Expand All @@ -12,12 +14,13 @@ function movieAttention(movie) {
if (movie.tmdb_id && !movie.poster) reasons.push('Poster missing');
return reasons;
}
function selectMovies(movies, {query = '', sort = 'title', descending = defaultSortDescending(sort), genre = '', person = '', language = '', collection = '', watched = 'all', attention = false} = {}) {
function selectMovies(movies, {query = '', sort = 'title', descending = defaultSortDescending(sort), genre = '', person = '', language = '', certification = '', collection = '', watched = 'all', attention = false} = {}) {
query = normalize(query).trim();
return movies.filter(m => (!query || normalize([m.title, m.file_title, m.original_title, m.year].join(' ')).includes(query))
&& (!genre || (m.genres || []).includes(genre))
&& (!person || [...(m.directors || []), ...(m.cast || [])].some(name => normalize(name).includes(normalize(person).trim())))
&& (!language || (m.languages || []).some(item => item.code === language))
&& (!certification || (certification === 'none' ? !m.certification : m.certification === certification))
&& (!collection || (collection === 'none' ? !m.collection : String(m.collection?.id) === String(collection)))
&& (!attention || movieAttention(m).length)
&& (watched === 'all' || m.watched === (watched === 'watched'))).sort((a, b) => {
Expand Down Expand Up @@ -106,4 +109,4 @@ function movieLinks(movie) {
? [{site:'wikipedia', label:'Wikipedia', href:movie.wikipedia_url}] : []),
];
}
if (typeof module !== 'undefined') module.exports = {selectMovies, defaultSortDescending, groupMovies, browseCollection, playHistory, movieLinks, movieAttention};
if (typeof module !== 'undefined') module.exports = {CERTIFICATIONS, selectMovies, defaultSortDescending, groupMovies, browseCollection, playHistory, movieLinks, movieAttention};
2 changes: 2 additions & 0 deletions tvcast/library.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ a { color: var(--accent); }
.discovery-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.discovery-tools > .genre-picker { flex: 0 0 160px; }
.discovery-tools > .language-picker { flex: 0 0 160px; }
.discovery-tools > .certification-picker { flex: 0 0 150px; }
.discovery-tools > .collection-picker { flex: 0 1 240px; min-width: 160px; }
.discovery-tools > .watched-picker { flex: 0 0 145px; }
#libraryNote:not(:empty) { margin-bottom: 18px; }
Expand Down Expand Up @@ -110,6 +111,7 @@ a { color: var(--accent); }
.movie-detail .movie-meta { margin: 14px 0 22px; font-size: 14px; }
.movie-languages { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.movie-languages .metadata-link { font: inherit; min-height: 24px; padding: 0; }
.movie-meta .certification { padding: 0 4px; border: 1px solid var(--line); border-radius: 3px; font-size: 0.85em; font-weight: 600; line-height: 1.5; }
.movie-detail .synopsis { max-width: 65ch; line-height: 1.75; margin: 24px 0; }
.movie-detail dl { display: grid; grid-template-columns: 85px minmax(0, 1fr); align-items: first baseline; gap: 12px 18px; font-size: 13px; line-height: 1.6; }
.movie-detail dt { color: var(--muted); }
Expand Down
Loading
Loading