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 

20from abc import ABC 

21from typing import Dict, Any, Tuple, List 

22from puffotter.os import listdir 

23from toktokkie.metadata.base.Prompter import Prompter 

24from toktokkie.metadata.tv.TvExtras import TvExtras 

25from toktokkie.exceptions import InvalidDirectoryState 

26 

27 

28class TvPrompter(Prompter, TvExtras, ABC): 

29 """ 

30 Prompter class for tv series 

31 """ 

32 

33 @classmethod 

34 def prompt(cls, directory_path: str) -> Dict[str, Any]: 

35 """ 

36 Generates new Metadata JSON using prompts for a directory 

37 :param directory_path: The path to the directory for which to generate 

38 the metadata object 

39 :return: The generated metadata JSON 

40 """ 

41 base = super().prompt(directory_path) 

42 seasons = [] 

43 

44 # Make sure that regular Seasons are prompted first and in order 

45 season_folders = [] # type: List[Tuple[str, str]] 

46 special_folders = [] # type: List[Tuple[str, str]] 

47 unsorted_folders = listdir(directory_path, no_files=True) 

48 

49 for folder, folder_path in unsorted_folders: 

50 if folder.startswith("Season "): 

51 try: 

52 int(folder.split("Season ")[1]) 

53 season_folders.append((folder, folder_path)) 

54 except (ValueError, IndexError): 

55 special_folders.append((folder, folder_path)) 

56 else: 

57 special_folders.append((folder, folder_path)) 

58 

59 season_folders.sort(key=lambda x: int(x[0].split("Season ")[1])) 

60 

61 for season_name, season_path in season_folders + special_folders: 

62 print("\n{}:".format(season_name)) 

63 ids = cls.prompt_component_ids( 

64 cls.valid_id_types(), 

65 base["ids"], 

66 cls.create_id_fetcher(directory_path) 

67 ) 

68 

69 seasons.append({ 

70 "ids": ids, 

71 "name": season_name 

72 }) 

73 

74 base.update({ 

75 "seasons": seasons 

76 }) 

77 return base 

78 

79 @classmethod 

80 def pre_prompt_check(cls, directory_path: str): 

81 """ 

82 Makes sure that the tv directory has at least one season 

83 :param directory_path: The path to the directory to check 

84 :return: None 

85 """ 

86 super().pre_prompt_check(directory_path) 

87 if len(listdir(directory_path, no_files=True)) == 0: 

88 raise InvalidDirectoryState("No season directory")