Fix target directory with tagged and highlights

Fixes #292.
This commit is contained in:
Alexander Graf 2019-05-08 21:16:33 +02:00
parent 93882d93e0
commit 408cf22c18

View File

@ -13,6 +13,7 @@ from datetime import datetime, timezone
from functools import wraps from functools import wraps
from hashlib import md5 from hashlib import md5
from io import BytesIO from io import BytesIO
from pathlib import Path
from typing import Any, Callable, ContextManager, Iterator, List, Optional, Set, Union, cast from typing import Any, Callable, ContextManager, Iterator, List, Optional, Set, Union, cast
import requests import requests
@ -430,13 +431,13 @@ class Instaloader:
.. versionadded:: 4.2""" .. versionadded:: 4.2"""
self.context.two_factor_login(two_factor_code) self.context.two_factor_login(two_factor_code)
def format_filename(self, item: Union[Post, StoryItem], target: Optional[str] = None): def format_filename(self, item: Union[Post, StoryItem], target: Optional[Union[str, Path]] = None):
"""Format filename of a :class:`Post` or :class:`StoryItem` according to ``filename-pattern`` parameter. """Format filename of a :class:`Post` or :class:`StoryItem` according to ``filename-pattern`` parameter.
.. versionadded:: 4.1""" .. versionadded:: 4.1"""
return _PostPathFormatter(item).format(self.filename_pattern, target=target) return _PostPathFormatter(item).format(self.filename_pattern, target=target)
def download_post(self, post: Post, target: str) -> bool: def download_post(self, post: Post, target: Union[str, Path]) -> bool:
""" """
Download everything associated with one instagram post node, i.e. picture, caption and video. Download everything associated with one instagram post node, i.e. picture, caption and video.
@ -563,7 +564,7 @@ class Instaloader:
if fast_update and not downloaded: if fast_update and not downloaded:
break break
def download_storyitem(self, item: StoryItem, target: str) -> bool: def download_storyitem(self, item: StoryItem, target: Union[str, Path]) -> bool:
"""Download one user story. """Download one user story.
:param item: Story item, as in story['items'] for story in :meth:`get_stories` :param item: Story item, as in story['items'] for story in :meth:`get_stories`
@ -643,7 +644,7 @@ class Instaloader:
with self.context.error_catcher('Download highlights \"{}\" from user {}'.format(user_highlight.title, name)): with self.context.error_catcher('Download highlights \"{}\" from user {}'.format(user_highlight.title, name)):
downloaded = self.download_storyitem(item, filename_target downloaded = self.download_storyitem(item, filename_target
if filename_target if filename_target
else '{}/{}'.format(name, user_highlight.title)) else Path(name) / Path(user_highlight.title))
if fast_update and not downloaded: if fast_update and not downloaded:
break break
@ -846,8 +847,6 @@ class Instaloader:
"""Download all posts where a profile is tagged. """Download all posts where a profile is tagged.
.. versionadded:: 4.1""" .. versionadded:: 4.1"""
if target is None:
target = profile.username + '/:tagged'
self.context.log("Retrieving tagged posts for profile {}.".format(profile.username)) self.context.log("Retrieving tagged posts for profile {}.".format(profile.username))
count = 1 count = 1
for post in profile.get_tagged_posts(): for post in profile.get_tagged_posts():
@ -856,7 +855,7 @@ class Instaloader:
if post_filter is not None and not post_filter(post): if post_filter is not None and not post_filter(post):
self.context.log('<{} skipped>'.format(post)) self.context.log('<{} skipped>'.format(post))
with self.context.error_catcher('Download tagged {}'.format(profile.username)): with self.context.error_catcher('Download tagged {}'.format(profile.username)):
downloaded = self.download_post(post, target) downloaded = self.download_post(post, target if target else Path(profile.username) / Path(':tagged'))
if fast_update and not downloaded: if fast_update and not downloaded:
break break