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 List 

22from puffotter.os import listdir 

23from toktokkie.enums import IdType 

24from toktokkie.metadata.base.components.RenameOperation import RenameOperation 

25from toktokkie.metadata.base.Renamer import Renamer 

26from toktokkie.metadata.book_series.BookSeriesExtras import BookSeriesExtras 

27 

28 

29class BookSeriesRenamer(Renamer, BookSeriesExtras, ABC): 

30 """ 

31 Implements the Renamer functionality for book series metadata 

32 """ 

33 

34 def create_rename_operations(self) -> List[RenameOperation]: 

35 """ 

36 Creates renaming operations for book series metadata 

37 :return: The renaming operations 

38 """ 

39 operations = [] 

40 children = listdir(self.directory_path, no_dirs=True) 

41 fill = len(str(len(children))) 

42 

43 for i, (volume, path) in enumerate(children): 

44 ext = volume.rsplit(".", 1)[1] 

45 new_name = "{} - Volume {}.{}".format( 

46 self.name, 

47 str(i + 1).zfill(fill), 

48 ext 

49 ) 

50 

51 operations.append(RenameOperation(path, new_name)) 

52 

53 return operations 

54 

55 def resolve_title_name(self) -> str: 

56 """ 

57 If possible, will fetch the appropriate name for the 

58 metadata based on IDs, falling back to the 

59 directory name if this is not possible or supported. 

60 """ 

61 return self.load_title_and_year([ 

62 IdType.ANILIST 

63 ])[0]