def _map_resp_to_metadata(self, resp) -> GenericMetadata: md = GenericMetadata() if resp.credits: md = self._add_credits_to_metadata(md, resp.credits) md.series = resp.series.name md.volume = resp.volume md.issue = IssueString(resp.number).as_string() md.publisher = resp.publisher.name md.day = resp.cover_date.day md.month = resp.cover_date.month md.year = resp.cover_date.year md.comments = resp.desc md.notes = self._create_note(resp.id) if resp.story_titles: md.title = list_to_string(list(resp.story_titles)) if resp.characters: md.characters = list_to_string([c.name for c in resp.characters]) if resp.teams: md.teams = list_to_string([t.name for t in resp.teams]) if resp.arcs: md.story_arc = list_to_string([a.name for a in resp.arcs]) return md
def create_issue_slug(series, number): formatted_number = IssueString(number).as_string(pad=3) slug = orig = slugify(f"{series}-{formatted_number}") for count in itertools.count(1): if not Issue.objects.filter(slug=slug).exists(): break slug = f"{orig}-{count}" return slug
def determine_name(self, filename: Path) -> Optional[str]: """Method to create the new filename based on the files metadata""" meta_data = self.metdata new_name = self.template new_name = self.replace_token(new_name, meta_data.series, "%series%") new_name = self.replace_token(new_name, meta_data.volume, "%volume%") if meta_data.issue is not None: issue_str = "{0}".format( IssueString( meta_data.issue).as_string(pad=self.issue_zero_padding)) else: issue_str = None new_name = self.replace_token(new_name, issue_str, "%issue%") new_name = self.replace_token(new_name, meta_data.issue_count, "%issuecount%") new_name = self.replace_token(new_name, meta_data.year, "%year%") new_name = self.replace_token(new_name, meta_data.publisher, "%publisher%") new_name = self.replace_token(new_name, meta_data.title, "%title%") new_name = self.replace_token(new_name, meta_data.month, "%month%") month_name = None if (meta_data.month is not None and ((isinstance(meta_data.month, str) and meta_data.month.isdigit()) or isinstance(meta_data.month, int)) and int(meta_data.month) in range(1, 13)): date_time = datetime.datetime(1970, int(meta_data.month), 1, 0, 0) month_name = date_time.strftime("%B") new_name = self.replace_token(new_name, month_name, "%month_name%") new_name = self.replace_token(new_name, meta_data.genre, "%genre%") new_name = self.replace_token(new_name, meta_data.language, "%language_code%") new_name = self.replace_token(new_name, meta_data.critical_rating, "%criticalrating%") new_name = self.replace_token(new_name, meta_data.alternate_series, "%alternateseries%") new_name = self.replace_token(new_name, meta_data.alternate_number, "%alternatenumber%") new_name = self.replace_token(new_name, meta_data.alternate_count, "%alternatecount%") new_name = self.replace_token(new_name, meta_data.imprint, "%imprint%") new_name = self.replace_token(new_name, meta_data.format, "%format%") new_name = self.replace_token(new_name, meta_data.maturity_rating, "%maturityrating%") new_name = self.replace_token(new_name, meta_data.story_arc, "%storyarc%") new_name = self.replace_token(new_name, meta_data.series_group, "%seriesgroup%") new_name = self.replace_token(new_name, meta_data.scan_info, "%scaninfo%") if self.smart_cleanup: new_name = self.smart_cleanup_string(new_name) ext = filename.suffix new_name += ext # some tweaks to keep various filesystems happy new_name = cleanup_string(new_name) return new_name
def test_issue_float(): val = IssueString("1½").as_float() assert val == 1.5
def test_issue_string_none_value(): val = IssueString("Test").as_string() assert val == "Test"
def test_issue_string_minus_one(): val = IssueString("-1").as_string(3) assert val == "-001"
def test_issue_string_monsters_unleashed(): val = IssueString("1.MU").as_string(3) assert val == "001.MU"
def test_issue_float_as_int(): val = IssueString("1.5").as_int() assert val == 1
def test_issue_string_pad(): val = IssueString("1").as_string(pad=3) assert val == "001"
def test_issue_int(): val = IssueString("1").as_int() assert val == 1
def test_issue_string_no_value_as_int(): val = IssueString("").as_int() assert val is None
def test_issue_verify_float(): val = IssueString("1.5").as_float() assert val == 1.5
def test_issue_float_half(): val = IssueString("½").as_float() assert val == 0.5