Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of otaku-info-web. 

5 

6otaku-info-web is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11otaku-info-web is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with otaku-info-web. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from typing import Optional 

21from otaku_info_web.utils.enums import ListService, MediaType 

22from otaku_info_web.utils.mappings import list_service_url_formats 

23 

24 

25def build_service_url( 

26 media_type: MediaType, 

27 service: ListService, 

28 service_id: str 

29) -> str: 

30 """ 

31 Builds an URL for an external service based on an ID 

32 :param media_type: The media type for which to generate an URL 

33 :param service: The service for which to create the URL 

34 :param service_id: The ID of the media item on that service 

35 :return: The generated URL 

36 """ 

37 url_format = list_service_url_formats[service] 

38 url = url_format \ 

39 .replace("@{media_type}", media_type.value) \ 

40 .replace("@{id}", service_id) 

41 return url 

42 

43 

44def build_title(english_title: Optional[str], romaji_title: str) -> str: 

45 """ 

46 Determines the title based on an English and Romaji title 

47 :param english_title: The english title 

48 :param romaji_title: The romaji title 

49 :return: The title 

50 """ 

51 return romaji_title if english_title is None else english_title