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 2015 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of toktokkie. 

5 

6toktokkie 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 

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

18LICENSE""" 

19 

20import os 

21from abc import ABC 

22from typing import Dict, Any 

23from puffotter.os import listdir 

24from toktokkie.exceptions import InvalidMetadata 

25from toktokkie.metadata.base.Validator import Validator 

26from toktokkie.metadata.tv.TvExtras import TvExtras 

27 

28 

29class TvValidator(Validator, TvExtras, ABC): 

30 """ 

31 Class that handles validation of tv series metadata 

32 """ 

33 

34 @classmethod 

35 def build_schema(cls) -> Dict[str, Any]: 

36 """ 

37 Generates the JSON schema 

38 :return: The JSON schema 

39 """ 

40 base = super().build_schema() 

41 ids = cls._create_ids_schema() 

42 

43 excludes = {} 

44 multi_episodes = {} 

45 season_start_overrides = {} 

46 for id_type in cls.valid_id_types(): 

47 extra_base = { 

48 "type": "array", 

49 "items": { 

50 "type": "object", 

51 "properties": { 

52 "season": {"type": "number"}, 

53 "episode": {"type": "number"} 

54 }, 

55 "required": ["season", "episode"] 

56 } 

57 } 

58 excludes[id_type.value] = extra_base.copy() 

59 season_start_overrides[id_type.value] = extra_base.copy() 

60 

61 extra_base = { 

62 "type": "array", 

63 "items": { 

64 "type": "object", 

65 "properties": { 

66 "season": {"type": "number"}, 

67 "start_episode": {"type": "number"}, 

68 "end_episode": {"type": "number"} 

69 }, 

70 "required": ["season", "start_episode", "end_episode"] 

71 } 

72 } 

73 multi_episodes[id_type.value] = extra_base.copy() 

74 

75 base["properties"].update({ 

76 "seasons": { 

77 "type": "array", 

78 "items": { 

79 "type": "object", 

80 "properties": { 

81 "ids": ids, 

82 "name": {"type": "string"} 

83 }, 

84 "required": ["name"], 

85 "additionalProperties": False 

86 } 

87 }, 

88 "excludes": { 

89 "type": "object", 

90 "additionalProperties": excludes 

91 }, 

92 "season_start_overrides": { 

93 "type": "object", 

94 "additionalProperties": season_start_overrides 

95 }, 

96 "multi_episodes": { 

97 "type": "object", 

98 "additionalProperties": multi_episodes 

99 } 

100 }) 

101 base["required"].append("seasons") 

102 return base 

103 

104 def validate(self): 

105 """ 

106 Performs additional validation 

107 """ 

108 super().validate() 

109 foldercount = len(listdir(self.directory_path, no_files=True)) 

110 

111 if len(self.seasons) < foldercount: 

112 raise InvalidMetadata("Missing seasons in metadata") 

113 elif len(self.seasons) > foldercount: 

114 raise InvalidMetadata("Missing season directories") 

115 

116 for season in self.seasons: 

117 if not os.path.isdir(season.path): 

118 raise InvalidMetadata("Missing season directory {}" 

119 .format(season.name))