Coverage for otaku_info/db/MediaIdMapping.py: 88%

Shortcuts 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

22 statements  

1"""LICENSE 

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

3 

4This file is part of otaku-info. 

5 

6otaku-info 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 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. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from jerrycan.base import db 

21from jerrycan.db.ModelMixin import ModelMixin 

22from otaku_info.enums import ListService, MediaType 

23from otaku_info.db.MediaItem import MediaItem 

24from otaku_info.utils.urls import generate_service_icon_url,\ 

25 generate_service_url 

26 

27 

28class MediaIdMapping(ModelMixin, db.Model): 

29 """ 

30 Database model to map media IDs to each other across services 

31 """ 

32 

33 def __init__(self, *args, **kwargs): 

34 """ 

35 Initializes the Model 

36 :param args: The constructor arguments 

37 :param kwargs: The constructor keyword arguments 

38 """ 

39 super().__init__(*args, **kwargs) 

40 

41 __tablename__ = "media_id_mappings" 

42 __table_args__ = (db.ForeignKeyConstraint( 

43 ("parent_service", "parent_service_id", "media_type"), 

44 (MediaItem.service, MediaItem.service_id, MediaItem.media_type) 

45 ),) 

46 

47 parent_service: ListService = \ 

48 db.Column(db.Enum(ListService), primary_key=True) 

49 parent_service_id: str = db.Column(db.String(255), primary_key=True) 

50 media_type: MediaType = db.Column(db.Enum(MediaType), primary_key=True) 

51 service: ListService = db.Column(db.Enum(ListService), primary_key=True) 

52 

53 service_id: str = db.Column(db.String(255), nullable=False) 

54 

55 media_item: MediaItem = db.relationship( 

56 "MediaItem", back_populates="id_mappings" 

57 ) 

58 

59 @property 

60 def service_url(self) -> str: 

61 """ 

62 :return: The URL to the series for the given service 

63 """ 

64 return generate_service_url( 

65 self.service, 

66 self.media_type, 

67 self.service_id 

68 ) 

69 

70 @property 

71 def service_icon(self) -> str: 

72 """ 

73 :return: The path to the service's icon file 

74 """ 

75 return generate_service_icon_url(self.service)