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 

22from puffotter.os import listdir 

23from puffotter.prompt import prompt, yn_prompt 

24from toktokkie.enums import IdType 

25from toktokkie.metadata.base.Prompter import Prompter 

26from toktokkie.metadata.music.MusicExtras import MusicExtras 

27 

28 

29class MusicPrompter(Prompter, MusicExtras, ABC): 

30 """ 

31 Implements the Prompter functionality for music metadata 

32 """ 

33 

34 @classmethod 

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

36 """ 

37 Generates new Metadata JSON using prompts for a directory 

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

39 the metadata object 

40 :return: The generated metadata JSON 

41 """ 

42 base = super().prompt(directory_path) 

43 id_fetcher = cls.create_id_fetcher(directory_path) 

44 albums = [] 

45 theme_songs = [] 

46 

47 for album, album_path in listdir(directory_path, no_files=True): 

48 valid_album_ids = cls.valid_id_types() 

49 valid_album_ids.remove(IdType.MUSICBRAINZ_ARTIST) 

50 valid_album_ids.append(IdType.MUSICBRAINZ_RELEASE) 

51 

52 album_data = { 

53 "name": album, 

54 "genre": prompt("Genre"), 

55 "year": prompt("Year", _type=int), 

56 "ids": cls.prompt_component_ids( 

57 valid_album_ids, {}, id_fetcher 

58 ) 

59 } 

60 albums.append(album_data) 

61 

62 if yn_prompt("Is this a theme song?"): 

63 theme_data = { 

64 "name": album, 

65 "theme_type": prompt( 

66 "Theme Type", 

67 choices={"OP", "ED", "Insert", "Special", "Other"} 

68 ).lower(), 

69 "series_ids": cls.prompt_ids( 

70 Prompter.theme_song_id_types(), [], {}, id_fetcher 

71 ) 

72 } 

73 theme_songs.append(theme_data) 

74 

75 base.update({"albums": albums, "theme_songs": theme_songs}) 

76 return base