Compare commits

..
5 Commits
Author SHA1 Message Date
Alexander Graf 5d83a4ccf6 Release of version 2.2.2 2017-08-06 10:49:36 +02:00
Alexander Graf 56c8ac729f Cleanup .gitignore 2017-08-05 13:43:26 +02:00
André Koch-Kramer 987d95c048 Forgot "file=" in some print statements 2017-08-05 00:22:43 +02:00
André Koch-Kramer 9b5d4e34fc Raise and catch NodeUnavailableException
In case a node can not be downloaded or its metadata is needed and can
not be retrieved, a NodeUnavailableException is raised and the according
node will be skipped.
Concerns #26
2017-08-04 19:19:56 +02:00
Alexander Graf 838ea645a8 Let Travis automatically deploy releases to PyPi 2017-08-04 11:18:20 +02:00
4 changed files with 83 additions and 41 deletions
-3
View File
@@ -1,4 +1 @@
__pycache__/
build/
dist/
instaloader.egg-info/
+8
View File
@@ -10,3 +10,11 @@ install:
- pip install pylint requests
script:
- python3 -m pylint -r n -d bad-whitespace,missing-docstring,too-many-arguments,locally-disabled,line-too-long,too-many-public-methods,too-many-lines,too-many-instance-attributes,too-many-locals,too-many-branches,too-many-statements instaloader
deploy:
provider: pypi
user: aandergr
on:
tags: true
python: 3.6
password:
secure: KBsATtXNnEzqr0X2ALdyx2zaYj2EUfK8YjP4jEOilBELpJ4evHYXVgRkn9CKXGsD7LKbWmR3gz2rr8NZ6U42pHw0fpQHizz91MpJSKbNY7RZZh4UVWMDh81izeglchWAF+m3Wdpxpo/GBDbrZIbRQFhPgB+kjSzJo3uiCS+yVXtGG+6csJHzd0WkJjsVHz+XSdxyOiLy/qFF3nmY6ZrVrgw6WbX2YLbx9je6DxK3YRrnBqgMgH7Ui2xWWbgJCk3KKpQTMiMKnTa9mdeMJAd26YMCz1gG/X7ck6VNly/6bs5+Zq7/bU0dSolhPBhNthyccYdS0IeGPdPF3YqatblJ4fLGTfHn8oJs3/T11yIW9pvOT3UftEynPOUX+en2Qnb/3WfgwUfVts8i8DAYgEFLGEzbF5XMGy4gwAD/bZ0JW0pmgAG2PZsdOokAt+ydlNj/uxq1GFW2doZbul6k4t03p1mik6itYscvuhKoEm8Yw6wr1P9aDvMR6FFpSu4gDt2XrKmRmWkSXxpNeCfZujTjyAnISxLVQGSY7BG5K0Z2HbDtqqNz9nj4WgNGzZmngiRofCevWR+vPIDUDW7NCX03csfcFS9RRllBO/BrL7NVUV+Qp9dfTQYp+8SqYLWgHtDoXdgyMREjJaAmbx2u/TYTY8bADZ5F3vGUpv2j5hP3NTU=
+74 -37
View File
@@ -80,6 +80,10 @@ class BadResponseException(NonfatalException):
pass
class NodeUnavailableException(NonfatalException):
pass
class BadCredentialsException(InstaloaderException):
pass
@@ -166,9 +170,9 @@ class Instaloader:
else:
raise ConnectionException("Request returned HTTP error code {}.".format(resp.status_code))
except (urllib3.exceptions.HTTPError, requests.exceptions.RequestException, ConnectionException) as err:
print("URL: " + url + "\n" + err, file=sys.stderr)
print("URL: {}\n{}".format(url, err), file=sys.stderr)
if tries <= 1:
raise err
raise NodeUnavailableException
self._sleep()
self._get_and_write_raw(url, filename, tries - 1)
@@ -547,13 +551,18 @@ class Instaloader:
print(err, file=sys.stderr)
print(json.dumps(pic_json, indent=4), file=sys.stderr)
if tries <= 1:
raise err
raise NodeUnavailableException
self._sleep()
media = self.get_node_metadata(node_code, tries - 1)
return media
def get_location(self, node_code: str) -> Dict[str, str]:
media = self.get_node_metadata(node_code)
try:
media = self.get_node_metadata(node_code)
except NodeUnavailableException:
print("Unable to lookup location for node \"https://www.instagram.com/p/{}/\".".format(node_code),
file=sys.stderr)
return dict()
if media["location"] is not None:
location_json = self.get_json("explore/locations/" +
media["location"]["id"])
@@ -580,8 +589,13 @@ class Instaloader:
if already_has_profilename:
profilename = profile if profile is not None else node['owner']['username']
else:
metadata = self.get_node_metadata(shortcode)
profilename = metadata['owner']['username']
try:
metadata = self.get_node_metadata(shortcode)
profilename = metadata['owner']['username']
except NodeUnavailableException:
print("Unable to gather profilename for node "
"\"https://www.instagram.com/p/{}/\".".format(shortcode), file=sys.stderr)
profilename = 'UNKNOWN'
else:
profilename = None
profilename = profilename.lower() if profilename else None
@@ -712,27 +726,32 @@ class Instaloader:
date=date,
shortcode=shortcode)
os.makedirs(os.path.dirname(filename), exist_ok=True)
if "image_versions2" in item:
url = item["image_versions2"]["candidates"][0]["url"]
downloaded = self.download_pic(filename=filename,
url=url,
mtime=date)
else:
self._log("Warning: Unable to find story image.")
downloaded = False
if "caption" in item and item["caption"] is not None:
caption = item["caption"]
if isinstance(caption, dict) and "text" in caption:
caption = caption["text"]
self.save_caption(filename, date, caption)
else:
self._log("<no caption>", end=' ', flush=True)
if "video_versions" in item and download_videos:
downloaded = self.download_pic(filename=filename,
url=item["video_versions"][0]["url"],
mtime=date)
if "video_duration" in item and self.sleep and downloaded:
time.sleep(item["video_duration"])
try:
if "image_versions2" in item:
url = item["image_versions2"]["candidates"][0]["url"]
downloaded = self.download_pic(filename=filename,
url=url,
mtime=date)
else:
self._log("Warning: Unable to find story image.")
downloaded = False
if "caption" in item and item["caption"] is not None:
caption = item["caption"]
if isinstance(caption, dict) and "text" in caption:
caption = caption["text"]
self.save_caption(filename, date, caption)
else:
self._log("<no caption>", end=' ', flush=True)
if "video_versions" in item and download_videos:
downloaded = self.download_pic(filename=filename,
url=item["video_versions"][0]["url"],
mtime=date)
if "video_duration" in item and self.sleep and downloaded:
time.sleep(item["video_duration"])
except NodeUnavailableException:
print("Unable to download node \"https://www.instagram.com/p/{}/\" of user {} from stories."
.format(shortcode, name), file=sys.stderr)
continue
if item["story_locations"]:
location = item["story_locations"][0]["location"]
if location:
@@ -786,9 +805,14 @@ class Instaloader:
continue
self._log("[%3i] %s " % (count, name), end="", flush=True)
count += 1
downloaded = self.download_node(node, profile=name, target=':feed',
download_videos=download_videos, geotags=geotags,
download_comments=download_comments)
try:
downloaded = self.download_node(node, profile=name, target=':feed',
download_videos=download_videos, geotags=geotags,
download_comments=download_comments)
except NodeUnavailableException:
print("Unable to download node \"https://www.instagram.com/p/{}/\" of user {} from feed."
.format(node['shortcode'], name), file=sys.stderr)
continue
if fast_update and not downloaded:
return
if not feed["page_info"]["has_next_page"]:
@@ -830,9 +854,14 @@ class Instaloader:
self._log('<skipped>')
continue
count += 1
downloaded = self.download_node(node=node, profile=None, target='#'+hashtag,
download_videos=download_videos, geotags=geotags,
download_comments=download_comments)
try:
downloaded = self.download_node(node=node, profile=None, target='#'+hashtag,
download_videos=download_videos, geotags=geotags,
download_comments=download_comments)
except NodeUnavailableException:
print("Unable to download node \"https://www.instagram.com/p/{}/\" "
"while downloading hashtag \"{}\".".format(node['shortcode'], hashtag), file=sys.stderr)
continue
if fast_update and not downloaded:
return
if data['entry_data']['TagPage'][0]['tag']['media']['page_info']['has_next_page']:
@@ -904,7 +933,10 @@ class Instaloader:
name = name_updated
data = self.get_json(name)
# Download profile picture
self.download_profilepic(name, data["entry_data"]["ProfilePage"][0]["user"]["profile_pic_url"])
try:
self.download_profilepic(name, data["entry_data"]["ProfilePage"][0]["user"]["profile_pic_url"])
except NodeUnavailableException:
print("Unable to download profilepic of user {}.".format(name), file=sys.stderr)
if profile_pic_only:
return
# Catch some errors
@@ -939,9 +971,14 @@ class Instaloader:
for node in data["entry_data"]["ProfilePage"][0]["user"]["media"]["nodes"]:
self._log("[%3i/%3i] " % (count, totalcount), end="", flush=True)
count += 1
downloaded = self.download_node(node=node, profile=name, target=name,
download_videos=download_videos, geotags=geotags,
download_comments=download_comments)
try:
downloaded = self.download_node(node=node, profile=name, target=name,
download_videos=download_videos, geotags=geotags,
download_comments=download_comments)
except NodeUnavailableException:
print("Unable to download node \"https://www.instagram.com/p/{}/\" of user {}."
.format(node['shortcode'], name), file=sys.stderr)
continue
if fast_update and not downloaded:
return
data = self.get_json(name, max_id=get_last_id(data))
+1 -1
View File
@@ -8,7 +8,7 @@ if sys.version_info < (3, 5):
setup(
name='instaloader',
version='2.2.1',
version='2.2.2',
py_modules=['instaloader'],
url='https://github.com/Thammus/instaloader',
license='MIT',