From ccf55dbeef05ac7bf94aba3a73e838e08817a3b9 Mon Sep 17 00:00:00 2001 From: Friendly Date: Tue, 16 Apr 2019 19:49:31 -0400 Subject: [PATCH] New Format Specifier: {pcaption} I saw the abbreviated caption output from save_caption and realized it was perfect for --filename-pattern. Even if this pull request is not accepted, please do not abandon the idea within. The ability to put captions in file names is *very* useful. --- instaloader/structures.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/instaloader/structures.py b/instaloader/structures.py index 6b56ee0..0efe36d 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -252,6 +252,14 @@ class Post: mention_regex = re.compile(r"(?:@)(\w(?:(?:\w|(?:\.(?!\.))){0,28}(?:\w))?)") return re.findall(mention_regex, self.caption.lower()) + @property + def pcaption(self) -> str: + """Printable caption, useful as a format specifier for --filename-pattern.""" + def _elliptify(caption): + pcaption = ' '.join([s.replace('/', '∕') for s in caption.splitlines() if s]).strip() + return (pcaption[:30] + u"\u2026") if len(pcaption) > 31 else pcaption + return _elliptify(self.caption) if self.caption else '' + @property def tagged_users(self) -> List[str]: """List of all lowercased users that are tagged in the Post."""