Compare commits

..
10 Commits
5 changed files with 18 additions and 18 deletions
+3 -1
View File
@@ -18,6 +18,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here. # documentation root, use os.path.abspath to make it absolute, like shown here.
# #
import os import os
import platform
import subprocess import subprocess
import sys import sys
import typing import typing
@@ -50,8 +51,9 @@ intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
'requests': ('https://requests.kennethreitz.org/en/master/', None)} 'requests': ('https://requests.kennethreitz.org/en/master/', None)}
current_release = subprocess.check_output(["git", "describe", "--abbrev=0"]).decode("ascii")[1:-1] current_release = subprocess.check_output(["git", "describe", "--abbrev=0"]).decode("ascii")[1:-1]
date_format = "%e %b %Y" if platform.system() != "Windows" else "%d %b %Y"
current_release_date = subprocess.check_output( current_release_date = subprocess.check_output(
["git", "log", "-1", "--tags", "--format=%ad", "--date=format:%e %b %Y"]).decode("ascii")[:-1] ["git", "log", "-1", "--tags", "--format=%ad", "--date=format:"+date_format]).decode("ascii")[:-1]
html_context = {'current_release': current_release, 'current_release_date': current_release_date} html_context = {'current_release': current_release, 'current_release_date': current_release_date}
+1 -1
View File
@@ -1,7 +1,7 @@
"""Download pictures (or videos) along with their captions and other metadata from Instagram.""" """Download pictures (or videos) along with their captions and other metadata from Instagram."""
__version__ = '4.4.4rc1' __version__ = '4.4.4'
try: try:
+5 -14
View File
@@ -3,7 +3,6 @@
import ast import ast
import datetime import datetime
import os import os
import platform
import re import re
import sys import sys
from argparse import ArgumentParser, SUPPRESS from argparse import ArgumentParser, SUPPRESS
@@ -16,20 +15,10 @@ from .instaloader import get_default_session_filename
from .instaloadercontext import default_user_agent from .instaloadercontext import default_user_agent
def get_simple_argv0() -> str:
if platform.system() != "Windows":
argv0 = os.path.basename(sys.argv[0])
else:
dirname = os.path.relpath(os.path.dirname(sys.argv[0]))
basename = os.path.basename(sys.argv[0])
argv0 = os.path.join(dirname, basename)
argv0 = "instaloader" if argv0 == "__main__.py" else argv0
return argv0
def usage_string(): def usage_string():
# NOTE: duplicated in README.rst and docs/index.rst # NOTE: duplicated in README.rst and docs/index.rst
argv0 = get_simple_argv0() argv0 = os.path.basename(sys.argv[0])
argv0 = "instaloader" if argv0 == "__main__.py" else argv0
return """ return """
{0} [--comments] [--geotags] {0} [--comments] [--geotags]
{2:{1}} [--stories] [--highlights] [--tagged] [--igtv] {2:{1}} [--stories] [--highlights] [--tagged] [--igtv]
@@ -93,6 +82,8 @@ def _main(instaloader: Instaloader, targetlist: List[str],
instaloader.context.log('Only download storyitems with property "{}".'.format(storyitem_filter_str)) instaloader.context.log('Only download storyitems with property "{}".'.format(storyitem_filter_str))
# Login, if desired # Login, if desired
if username is not None: if username is not None:
if not re.match(r"^[A-Za-z0-9._]+$", username):
instaloader.context.error("Warning: Parameter \"{}\" for --login is not a valid username.".format(username))
try: try:
instaloader.load_session_from_file(username, sessionfile) instaloader.load_session_from_file(username, sessionfile)
except FileNotFoundError as err: except FileNotFoundError as err:
@@ -207,7 +198,7 @@ def _main(instaloader: Instaloader, targetlist: List[str],
if len(profiles) > 1: if len(profiles) > 1:
instaloader.context.log("Downloading {} profiles: {}".format(len(profiles), instaloader.context.log("Downloading {} profiles: {}".format(len(profiles),
' '.join([p.username for p in profiles]))) ' '.join([p.username for p in profiles])))
if ((profiles and download_profile_pic) or download_posts) and not instaloader.context.is_logged_in: if profiles and (download_profile_pic or download_posts) and not instaloader.context.is_logged_in:
instaloader.context.error("Warning: Use --login to download higher-quality versions of pictures.") instaloader.context.error("Warning: Use --login to download higher-quality versions of pictures.")
instaloader.download_profiles(profiles, instaloader.download_profiles(profiles,
download_profile_pic, download_posts, download_tagged, download_igtv, download_profile_pic, download_posts, download_tagged, download_igtv,
+5 -2
View File
@@ -242,7 +242,9 @@ class Post:
"""URL of the picture / video thumbnail of the post""" """URL of the picture / video thumbnail of the post"""
if self.typename == "GraphImage" and self._context.is_logged_in: if self.typename == "GraphImage" and self._context.is_logged_in:
try: try:
return self._iphone_struct['image_versions2']['candidates'][0]['url'] orig_url = self._iphone_struct['image_versions2']['candidates'][0]['url']
url = re.sub(r'&se=\d+(&?)', r'\1', orig_url)
return url
except (InstaloaderException, KeyError, IndexError) as err: except (InstaloaderException, KeyError, IndexError) as err:
self._context.error('{} Unable to fetch high quality image version of {}.'.format(err, self)) self._context.error('{} Unable to fetch high quality image version of {}.'.format(err, self))
return self._node["display_url"] if "display_url" in self._node else self._node["display_src"] return self._node["display_url"] if "display_url" in self._node else self._node["display_src"]
@@ -266,7 +268,8 @@ class Post:
if not is_video and self._context.is_logged_in: if not is_video and self._context.is_logged_in:
try: try:
carousel_media = self._iphone_struct['carousel_media'] carousel_media = self._iphone_struct['carousel_media']
display_url = carousel_media[idx]['image_versions2']['candidates'][0]['url'] orig_url = carousel_media[idx]['image_versions2']['candidates'][0]['url']
display_url = re.sub(r'&se=\d+(&?)', r'\1', orig_url)
except (InstaloaderException, KeyError, IndexError) as err: except (InstaloaderException, KeyError, IndexError) as err:
self._context.error('{} Unable to fetch high quality image version of {}.'.format(err, self)) self._context.error('{} Unable to fetch high quality image version of {}.'.format(err, self))
yield PostSidecarNode(is_video=is_video, display_url=display_url, yield PostSidecarNode(is_video=is_video, display_url=display_url,
+4
View File
@@ -94,6 +94,10 @@ class TestInstaloaderAnonymously(unittest.TestCase):
self.assertEqual(EMPTY_PROFILE.lower(), self.assertEqual(EMPTY_PROFILE.lower(),
instaloader.Profile.from_id(self.L.context, EMPTY_PROFILE_ID).username) instaloader.Profile.from_id(self.L.context, EMPTY_PROFILE_ID).username)
def test_get_username_by_name_empty(self):
self.assertEqual(EMPTY_PROFILE_ID,
instaloader.Profile.from_username(self.L.context, EMPTY_PROFILE).userid)
def test_post_from_mediaid(self): def test_post_from_mediaid(self):
for post in instaloader.Profile.from_username(self.L.context, PUBLIC_PROFILE).get_posts(): for post in instaloader.Profile.from_username(self.L.context, PUBLIC_PROFILE).get_posts():
post2 = instaloader.Post.from_mediaid(self.L.context, post.mediaid) post2 = instaloader.Post.from_mediaid(self.L.context, post.mediaid)