Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

feat(db): add tv show support #2673

Merged
merged 1 commit into from
Jan 10, 2024
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You can view the entire database at [ThemerrDB](https://app.lizardbyte.dev/Theme
[![TheMovieDB Movies](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapp.lizardbyte.dev%2FThemerrDB%2Fmovies%2Fpages.json&query=count&style=for-the-badge&label=TheMovieDB%20Movies&logo=the-movie-database&logoColor=ffffff&color=01B4E4&labelColor=01B4E4)](#movies)
[![IMDB Movies](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapp.lizardbyte.dev%2FThemerrDB%2Fmovies%2Fpages.json&query=imdb_count&style=for-the-badge&label=IMDB%20Movies&logo=imdb&logoColor=000000&color=F5C518&labelColor=F5C518)](#movies)
[![Movie Collections](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapp.lizardbyte.dev%2FThemerrDB%2Fmovie_collections%2Fpages.json&query=count&style=for-the-badge&label=Movie%20Collections&logo=the-movie-database&logoColor=ffffff&color=01B4E4&labelColor=01B4E4)](#movie-collections)
[![TV Shows](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapp.lizardbyte.dev%2FThemerrDB%2Ftv_shows%2Fpages.json&query=count&style=for-the-badge&label=TV%20Shows&logo=the-movie-database&logoColor=ffffff&color=01B4E4&labelColor=01B4E4)](#tv-shows)
[![Games](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapp.lizardbyte.dev%2FThemerrDB%2Fgames%2Fpages.json&query=count&style=for-the-badge&label=Games&logo=igdb&logoColor=ffffff&color=9147FF&labelColor=9147FF)](#games)
[![Games](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapp.lizardbyte.dev%2FThemerrDB%2Fgame_collections%2Fpages.json&query=count&style=for-the-badge&label=Game%20Collections&logo=igdb&logoColor=ffffff&color=9147FF&labelColor=9147FF)](#game-collections)
[![Games](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapp.lizardbyte.dev%2FThemerrDB%2Fgame_franchises%2Fpages.json&query=count&style=for-the-badge&label=Game%20Franchises&logo=igdb&logoColor=ffffff&color=9147FF&labelColor=9147FF)](#game-franchises)
Expand All @@ -27,6 +28,9 @@ You can view the entire database at [ThemerrDB](https://app.lizardbyte.dev/Theme
#### Movie Collections
![Movie Collections](https://app.lizardbyte.dev/ThemerrDB/movie_collections/movie_collections_plot.svg)

#### TV Shows
![TV Shows](https://app.lizardbyte.dev/ThemerrDB/tv_shows/tv_shows_plot.svg)

#### Games
![Games](https://app.lizardbyte.dev/ThemerrDB/games/games_plot.svg)

Expand Down Expand Up @@ -84,6 +88,7 @@ at UTC 12:00. Theme songs will not be available until they are published.
| game_franchises | igdb |
| movies | themoviedb, imdb |
| movie_collections | themoviedb |
| tv_shows | themoviedb |

2. Determine the id of the item from the main database.

Expand All @@ -92,6 +97,8 @@ at UTC 12:00. Theme songs will not be available until they are published.
- Movies
- [imdb](https://www.imdb.com/)
- [themoviedb](https://www.themoviedb.org/)
- TV Shows
- [themoviedb](https://www.themoviedb.org/)

3. Access the item on ThemerrDB at the following url:

Expand Down
24 changes: 19 additions & 5 deletions src/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@
title='Movie Collections',
type='movie_collection',
api_endpoint='collection',
)
),
tv_show=dict(
all_items=[],
path=os.path.join('database', 'tv_shows', 'themoviedb'),
title='TV Shows',
type='tv_show',
api_endpoint='tv',
),
)
imdb_path = os.path.join('database', 'movies', 'imdb')

Expand Down Expand Up @@ -251,7 +258,7 @@ def process_item_id(item_type: str,
raise Exception(f'Error getting game id: {e}')
else:
json_data = json_result[0]
elif item_type.startswith('movie'):
elif item_type.startswith('movie') or item_type == 'tv_show':
database_path = databases[item_type]['path']
endpoint = databases[item_type]['api_endpoint']

Expand Down Expand Up @@ -290,8 +297,8 @@ def process_item_id(item_type: str,
summary = ''
if item_type == 'game':
title = json_data['name']
issue_title = f"[GAME]: {title} ({json_data['release_dates'][0]['y']})"
year = json_data['release_dates'][0]['y']
issue_title = f"[GAME]: {title} ({year})"
poster = f"![poster](https:{json_data['cover']['url'].replace('/t_thumb/', '/t_cover_big/')})"
summary = json_data['summary'].replace('\n', '<br>').replace('\r', '<br>')
elif item_type == 'game_collection':
Expand All @@ -302,15 +309,21 @@ def process_item_id(item_type: str,
issue_title = f"[GAME FRANCHISE]: {title}"
elif item_type == 'movie':
title = json_data['title']
issue_title = f"[MOVIE]: {title} ({json_data['release_date'][0:4]})"
year = json_data['release_date'][0:4]
year = json_data['release_date'].split('-')[0]
issue_title = f"[MOVIE]: {title} ({year})"
poster = f"![poster](https://image.tmdb.org/t/p/w185{json_data['poster_path']})"
summary = json_data['overview'].replace('\n', '<br>').replace('\r', '<br>')
elif item_type == 'movie_collection':
title = json_data['name']
issue_title = f"[MOVIE COLLECTION]: {title}"
poster = f"![poster](https://image.tmdb.org/t/p/w185{json_data['poster_path']})"
summary = json_data['overview'].replace('\n', '<br>').replace('\r', '<br>')
elif item_type == 'tv_show':
title = json_data['name']
year = json_data['first_air_date'].split('-')[0]
issue_title = f"[TV SHOW]: {title} ({year})"
poster = f"![poster](https://image.tmdb.org/t/p/w185{json_data['poster_path']})"
summary = json_data['overview'].replace('\n', '<br>').replace('\r', '<br>')
issue_comment = f"""
| Property | Value |
| --- | --- |
Expand Down Expand Up @@ -438,6 +451,7 @@ def process_issue_update(database_url: Optional[str] = None, youtube_url: Option
'game_franchise': r'https://www\.igdb\.com/franchises/(.+)/*.*',
'movie': r'https://www\.themoviedb\.org/movie/(\d+)-*.*',
'movie_collection': r'https://www\.themoviedb\.org/collection/(\d+)-*.*',
'tv_show': r'https://www\.themoviedb\.org/tv/(\d+)-*.*',
}

# check the item type
Expand Down
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ def submission_movie_collection():
os.remove(submission_file)


@pytest.fixture(scope='function')
def submission_tv_show():
submission_data = dict(
database_url='https://www.themoviedb.org/tv/1930-the-beverly-hillbillies',
youtube_theme_url='https://www.youtube.com/watch?v=dQw4w9WgXcQ',
)

submission_file = create_submission_file(data=submission_data)

yield submission_data

os.remove(submission_file)


@pytest.fixture(scope='function')
def submission_game_collection():
submission_data = dict(
Expand Down
27 changes: 21 additions & 6 deletions tests/unit/test_issue_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_igdb_authorization(igdb_auth):
('https://www.igdb.com/franchises/james-bond', 'game_franchise'),
('https://www.themoviedb.org/movie/10378-big-buck-bunny', 'movie'),
('https://www.themoviedb.org/collection/645-james-bond-collection', 'movie_collection'),
('https://www.themoviedb.org/tv/1930-the-beverly-hillbillies', 'tv_show'),
])
def test_process_issue_update(db_url, db_type, issue_update_args, igdb_auth, tmdb_auth, youtube_url):
"""Test the provides submission urls and verify they are the correct item type."""
Expand Down Expand Up @@ -72,6 +73,7 @@ def test_check_youtube(youtube_url, url_suffix):
('game_franchise', 37),
('movie', 710),
('movie_collection', 645),
('tv_show', 1930),
])
def test_process_item_id(item_type, item_id, igdb_auth, tmdb_auth, youtube_url):
"""Tests if the provided game_slug is valid and the created dictionary contains the required keys."""
Expand Down Expand Up @@ -102,30 +104,43 @@ def test_main_issue_update_movie(issue_update_args, submission_movie, tmdb_auth)
assert data['youtube_theme_url'] == submission_movie['youtube_theme_url']


def test_main_issue_update_game(issue_update_args, submission_game, igdb_auth):
def test_main_issue_update_movie_collection(issue_update_args, submission_movie_collection, tmdb_auth):
updater.main()
file_path = os.path.join(os.getcwd(), 'database', 'games', 'igdb', '1638.json')
file_path = os.path.join(os.getcwd(), 'database', 'movie_collections', 'themoviedb', '645.json')

assert os.path.isfile(file_path)

# ensure youtube_theme_url is correct
with open(file_path, 'r') as f:
data = json.load(f)

assert data['youtube_theme_url'] == submission_game['youtube_theme_url']
assert data['youtube_theme_url'] == submission_movie_collection['youtube_theme_url']


def test_main_issue_update_movie_collection(issue_update_args, submission_movie_collection, tmdb_auth):
def test_main_issue_update_tv_show(issue_update_args, submission_tv_show, tmdb_auth):
updater.main()
file_path = os.path.join(os.getcwd(), 'database', 'movie_collections', 'themoviedb', '645.json')
file_path = os.path.join(os.getcwd(), 'database', 'tv_shows', 'themoviedb', '1930.json')

assert os.path.isfile(file_path)

# ensure youtube_theme_url is correct
with open(file_path, 'r') as f:
data = json.load(f)

assert data['youtube_theme_url'] == submission_movie_collection['youtube_theme_url']
assert data['youtube_theme_url'] == submission_tv_show['youtube_theme_url']


def test_main_issue_update_game(issue_update_args, submission_game, igdb_auth):
updater.main()
file_path = os.path.join(os.getcwd(), 'database', 'games', 'igdb', '1638.json')

assert os.path.isfile(file_path)

# ensure youtube_theme_url is correct
with open(file_path, 'r') as f:
data = json.load(f)

assert data['youtube_theme_url'] == submission_game['youtube_theme_url']


def test_main_issue_update_game_collection(issue_update_args, submission_game_collection, igdb_auth):
Expand Down