@@ -44,27 +44,29 @@ class Song:
4444
4545 def __post_init__ (self ):
4646 self .indexes = {"album" : - 2 , "title" : - 1 , "artist" : - 3 }
47+ norm_path = "_" .join (filter (None , re .split ("[-_\s]" , self .path )))
4748 try :
48- self ._year , self ._album = self . path . split ("/" )[self .indexes ["album" ]].split ("- " , maxsplit = 1 )
49+ self ._year , self ._album = norm_path . split ("/" )[self .indexes ["album" ]].split ("_ " , maxsplit = 1 )
4950 except Exception as e :
5051 # There could be "CDx" sub-dir
5152 try :
5253 self .indexes ["album" ] -= 1
5354 self .indexes ["artist" ] -= 1
54- self ._year , self ._album = self . path . split ("/" )[self .indexes ["album" ]].split ("- " , maxsplit = 1 )
55+ self ._year , self ._album = norm_path . split ("/" )[self .indexes ["album" ]].split ("_ " , maxsplit = 1 )
5556 except Exception as e_sub :
5657 click .echo (f"Error splitting { self .path } for album/year: { e } ; { e_sub } " )
5758 self ._album = self ._album .replace ("_" , " " )
5859 try :
59- self ._name = re .sub ("^[0-9]+([^0-9 ])* (- )?" , "" , self .path .split ("/" )[self .indexes ["title" ]][:- 4 ]).replace ("_" , " " )
60+ # self._name = re.sub("^[0-9]+([^0-9 ])* (- )?", "", norm_path.split("/")[self.indexes["title"]][:-4]).replace("_", " ")
61+ self ._name = re .sub ("^[0-9]+[-_.\s]*" , "" , self .path .split ("/" )[self .indexes ["title" ]][:- 4 ]).replace ("_" , " " )
6062 except Exception as e :
6163 click .echo (f"Error searching name from { self .path } : { e } " )
6264 try :
63- self ._track = re .sub ("[^0-9].*$" , "" , self . path .split ("/" )[self .indexes ["title" ]])
65+ self ._track = re .sub ("[^0-9].*$" , "" , norm_path .split ("/" )[self .indexes ["title" ]])
6466 except Exception as e :
6567 click .echo (f"Error searching track from { self .path } : { e } " )
6668 try :
67- self ._artist = self . path .split ("/" )[self .indexes ["artist" ]].replace ("_" , " " )
69+ self ._artist = norm_path .split ("/" )[self .indexes ["artist" ]].replace ("_" , " " )
6870 except Exception as e :
6971 click .echo (f"Error splitting { self .path } for artist: { e } " )
7072
@@ -81,11 +83,11 @@ def name(self) -> str:
8183 return self ._name
8284
8385 @property
84- def track (self ) -> str :
86+ def track (self ) -> int :
8587 return int (self ._track or "0" )
8688
8789 @property
88- def year (self ) -> str :
90+ def year (self ) -> int :
8991 return int (self ._year )
9092
9193
0 commit comments