diff --git a/pyproject.toml b/pyproject.toml index f074a2e..0538574 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "phylm" -version = "4.2.0" +version = "4.2.1" description = "Phylm" authors = ["Dom Batten "] license = "MIT" diff --git a/src/phylm/sources/imdb.py b/src/phylm/sources/imdb.py index a4f2fcb..53d753b 100644 --- a/src/phylm/sources/imdb.py +++ b/src/phylm/sources/imdb.py @@ -105,6 +105,18 @@ def title(self) -> Optional[str]: return str(self._imdb_data.get("title")) + @property + def id(self) -> Optional[str]: + """Return the IMDb id. + + Returns: + the id of the movie + """ + if not self._imdb_data: + return None + + return str(self._imdb_data.movieID) + def genres(self, limit: int = 3) -> List[str]: """Return the genres. diff --git a/tests/unit/sources/test_imdb.py b/tests/unit/sources/test_imdb.py index 166fe6b..cd85e67 100644 --- a/tests/unit/sources/test_imdb.py +++ b/tests/unit/sources/test_imdb.py @@ -247,6 +247,36 @@ def test_no_results(self, mock_ia: MagicMock) -> None: assert imdb.runtime is None +class TestId: + """Tests for the `id` property.""" + + @patch(IMDB_IA_PATH) + def test_year(self, mock_ia: MagicMock, the_matrix: Movie) -> None: + """ + Given a match with id, + When the year is retrieved, + Then the id is returned + """ + mock_ia.search_movie.return_value = [the_matrix] + + imdb = Imdb("The Matrix") + + assert imdb.id == "0133093" + + @patch(IMDB_IA_PATH) + def test_no_results(self, mock_ia: MagicMock) -> None: + """ + Given no search results, + When the id is retrieved, + Then `None` is returned + """ + mock_ia.search_movie.return_value = [] + + imdb = Imdb("The Matrix") + + assert imdb.id is None + + class TestYear: """Tests for the `year` method."""