mirror of
https://github.com/instaloader/instaloader.git
synced 2026-10-29 04:31:55 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92653dcdb9 | ||
|
|
1b5c12c8fa | ||
|
|
bc29ffbd44 | ||
|
|
50a5330fec | ||
|
|
1739844758 | ||
|
|
0ebb223214 | ||
|
|
3d4109ded3 | ||
|
|
8423e3bd00 | ||
|
|
5b0f8b75cc | ||
|
|
3cb33603e5 | ||
|
|
47db7f7ffa | ||
|
|
2567bec975 | ||
|
|
2df1419d68 | ||
|
|
8211c9daf1 | ||
|
|
969d4e3aa4 | ||
|
|
4cf1ae847d | ||
|
|
a276a0dc59 | ||
|
|
cc34b8340f | ||
|
|
45fe509ac4 | ||
|
|
ae492ed68b | ||
|
|
0e433294ad |
+1
-1
@@ -8,7 +8,7 @@ install:
|
|||||||
- pip install pylint requests
|
- pip install pylint requests
|
||||||
- pip install -r docs/requirements.txt
|
- pip install -r docs/requirements.txt
|
||||||
script:
|
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,inconsistent-return-statements,invalid-name,wildcard-import,unused-wildcard-import instaloader
|
- 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,inconsistent-return-statements,invalid-name,wildcard-import,unused-wildcard-import,no-else-return instaloader
|
||||||
- make -C docs html SPHINXOPTS="-W -n"
|
- make -C docs html SPHINXOPTS="-W -n"
|
||||||
deploy:
|
deploy:
|
||||||
- provider: pypi
|
- provider: pypi
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
Authors
|
||||||
|
=======
|
||||||
|
|
||||||
|
Instaloader is written by
|
||||||
|
|
||||||
|
- Alexander Graf (@aandergr)
|
||||||
|
- André Koch-Kramer (@Thammus)
|
||||||
|
- Lars Lindqvist (@e5150)
|
||||||
+28
-1
@@ -75,6 +75,33 @@ Disclaimer
|
|||||||
Instaloader is in no way affiliated with, authorized, maintained or endorsed by Instagram or any of its affiliates or
|
Instaloader is in no way affiliated with, authorized, maintained or endorsed by Instagram or any of its affiliates or
|
||||||
subsidiaries. This is an independent and unofficial project. Use at your own risk.
|
subsidiaries. This is an independent and unofficial project. Use at your own risk.
|
||||||
|
|
||||||
|
Instaloader is licensed under an MIT license. Refer to ``LICENSE`` file for more information.
|
||||||
|
|
||||||
.. disclaimer-end
|
.. disclaimer-end
|
||||||
|
|
||||||
Instaloader is licensed under an MIT license. Refer to ``LICENSE`` file for more information.
|
Contributing
|
||||||
|
------------
|
||||||
|
|
||||||
|
As an open source project, Instaloader heavily depends on the contributions from
|
||||||
|
its community. See
|
||||||
|
`contributing <https://instaloader.github.io/contributing.html>`__
|
||||||
|
for how you may help Instaloader to become an even greater tool.
|
||||||
|
|
||||||
|
It is a pleasure for us to share our Instaloader to the world, and we are proud
|
||||||
|
to have attracted such an active and motivating community, with so many users
|
||||||
|
who share their suggestions and ideas with us. Buying a community-sponsored beer
|
||||||
|
or coffee from time to time is very likely to further raise our passion for the
|
||||||
|
development of Instaloader.
|
||||||
|
|
||||||
|
| For Donations, we provide a PayPal.Me link and a Bitcoin address.
|
||||||
|
| PayPal: `PayPal.me/aandergr <https://www.paypal.me/aandergr>`__
|
||||||
|
| BTC: 1Nst4LoadeYzrKjJ1DX9CpbLXBYE9RKLwY
|
||||||
|
|
||||||
|
For a direct and personal communication within Instaloader's community, we have
|
||||||
|
an IRC channel
|
||||||
|
|
||||||
|
**#instaloader** on **Freenode**.
|
||||||
|
|
||||||
|
Freenode provides a `Web IRC Client
|
||||||
|
<https://webchat.freenode.net/?channels=instaloader>`__, allowing to join our
|
||||||
|
channel without having an IRC client installed.
|
||||||
|
|||||||
Vendored
+8
@@ -10,3 +10,11 @@ dd {
|
|||||||
dl.option dd {
|
dl.option dd {
|
||||||
padding-left: 12px;
|
padding-left: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #008d06;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: #f48400;
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+2
@@ -50,6 +50,8 @@
|
|||||||
<li><a href="https://github.com/instaloader/instaloader">Instaloader on GitHub</a></li>
|
<li><a href="https://github.com/instaloader/instaloader">Instaloader on GitHub</a></li>
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
<li style="padding-left: 20px;"><a class="github-button" href="https://github.com/instaloader/instaloader" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star Instaloader on GitHub">Star</a></li>
|
<li style="padding-left: 20px;"><a class="github-button" href="https://github.com/instaloader/instaloader" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star Instaloader on GitHub">Star</a></li>
|
||||||
|
<li role="separator" class="divider"></li>
|
||||||
|
<li><a href="https://www.paypal.me/aandergr"><b>Donate (via Paypal)</b></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -97,6 +97,9 @@ metadata of a Profile. :class:`Profile` instances can be created with:
|
|||||||
A reference of the many methods provided by the :mod:`instaloader` module is
|
A reference of the many methods provided by the :mod:`instaloader` module is
|
||||||
provided in the remainder of this document.
|
provided in the remainder of this document.
|
||||||
|
|
||||||
|
For a list of real code examples using the Instaloader module for advanced
|
||||||
|
tasks, see :ref:`codesnippets`.
|
||||||
|
|
||||||
``Instaloader`` (Main Class)
|
``Instaloader`` (Main Class)
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ Instaloader supports the following targets:
|
|||||||
**download the user's stories**.
|
**download the user's stories**.
|
||||||
|
|
||||||
- ``"#hashtag"``
|
- ``"#hashtag"``
|
||||||
Posts with a certain **hashtag** (the quotes are usually neccessary),
|
Posts with a certain **hashtag** (the quotes are usually necessary),
|
||||||
|
|
||||||
- ``:stories``
|
- ``:stories``
|
||||||
The currently-visible **stories** of your followees (requires
|
The currently-visible **stories** of your followees (requires
|
||||||
@@ -158,7 +158,7 @@ Filter Posts
|
|||||||
.. py:currentmodule:: instaloader
|
.. py:currentmodule:: instaloader
|
||||||
|
|
||||||
The options :option:`--post-filter` and :option:`--storyitem-filter`
|
The options :option:`--post-filter` and :option:`--storyitem-filter`
|
||||||
allows to specify criterias that posts or story items have to
|
allows to specify criteria that posts or story items have to
|
||||||
meet to be downloaded. If not given, all posts are downloaded.
|
meet to be downloaded. If not given, all posts are downloaded.
|
||||||
|
|
||||||
The filter string must be a
|
The filter string must be a
|
||||||
@@ -273,3 +273,6 @@ consider taking a look at the :ref:`python-module-instaloader`.
|
|||||||
Instaloader exposes its internally used methods and structures, making it a
|
Instaloader exposes its internally used methods and structures, making it a
|
||||||
powerful and intuitive Python API for Instagram, allowing to further customize
|
powerful and intuitive Python API for Instagram, allowing to further customize
|
||||||
obtaining media and metadata.
|
obtaining media and metadata.
|
||||||
|
|
||||||
|
Also see :ref:`codesnippets`, where we collect example scripts that use
|
||||||
|
Instaloader to achieve more complex tasks.
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
.. _codesnippets:
|
||||||
|
|
||||||
|
Advanced Instaloader Examples
|
||||||
|
=============================
|
||||||
|
|
||||||
|
.. currentmodule:: instaloader
|
||||||
|
|
||||||
|
.. highlight:: python
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:backlinks: none
|
||||||
|
|
||||||
|
Here we present code examples that use the :ref:`python-module-instaloader` for
|
||||||
|
more advanced Instagram downloading or metadata mining than what is possible
|
||||||
|
with the Instaloader command line interface.
|
||||||
|
|
||||||
|
.. For each code snippet:
|
||||||
|
- title
|
||||||
|
- brief description of what it does / motivation / how it works
|
||||||
|
- code, or link to code
|
||||||
|
- link to discussion issue
|
||||||
|
- link used methods
|
||||||
|
|
||||||
|
Download Posts in a Specific Period
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
To only download Instagram pictures (and metadata) that are within a specific
|
||||||
|
period, you can play around with :func:`~itertools.dropwhile` and
|
||||||
|
:func:`~itertools.takewhile` from :mod:`itertools` like in this snippet.
|
||||||
|
|
||||||
|
.. literalinclude:: codesnippets/121_since_until.py
|
||||||
|
|
||||||
|
See also :class:`Post`, :meth:`Instaloader.download_post`.
|
||||||
|
|
||||||
|
Discussed in :issue:`121`.
|
||||||
|
|
||||||
|
Likes of a Profile / Ghost Followers
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
To obtain a list of your inactive followers, i.e. followers that did not like
|
||||||
|
any of your pictures, into a file you can use this approach.
|
||||||
|
|
||||||
|
.. literalinclude:: codesnippets/120_ghost_followers.py
|
||||||
|
|
||||||
|
See also :meth:`Profile.get_posts`, :meth:`Post.get_likes`,
|
||||||
|
:meth:`Profile.get_followers`, :meth:`Instaloader.load_session_from_file`,
|
||||||
|
:meth:`Profile.from_username`.
|
||||||
|
|
||||||
|
Discussed in :issue:`120`.
|
||||||
|
|
||||||
|
Track Deleted Posts
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
This script uses Instaloader to obtain a list of currently-online Instagram and
|
||||||
|
compares it with the set of posts that you already have downloaded. It outputs
|
||||||
|
a list of posts which are online but not offline (i.e. not yet downloaded) and a
|
||||||
|
list of posts which are offline but not online (i.e. deleted in the profile).
|
||||||
|
|
||||||
|
.. literalinclude:: codesnippets/56_track_deleted.py
|
||||||
|
|
||||||
|
See also :func:`load_structure_from_file`, :meth:`Profile.from_username`,
|
||||||
|
:meth:`Profile.get_posts`, :class:`Post`.
|
||||||
|
|
||||||
|
Discussed in :issue:`56`.
|
||||||
|
|
||||||
|
Only one Post per User
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
To download only the one most recent post from each user, this snippet creates a
|
||||||
|
:class:`set` that contains the users of which a post has already been
|
||||||
|
downloaded. While iterating the posts, it checks whether the post's owner
|
||||||
|
already is in the set. If not, the post is downloaded from Instagram and the
|
||||||
|
user is added to that set.
|
||||||
|
|
||||||
|
.. literalinclude:: codesnippets/113_only_one_per_user.py
|
||||||
|
|
||||||
|
See also :class:`Post`, :meth:`Instaloader.download_post`,
|
||||||
|
:attr:`Post.owner_profile`, :class:`Profile`.
|
||||||
|
|
||||||
|
Discussed in :issue:`113`.
|
||||||
|
|
||||||
|
Upgrade Images by Local Copies
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
The following script finds local versions of images fetched by Instaloader, in
|
||||||
|
order to upgrade the downloaded images by locally-found versions with better
|
||||||
|
quality. It uses image hashing to identify similar images.
|
||||||
|
|
||||||
|
`updgrade-instaloader-images.py <https://gist.github.com/pavelkryukov/15f93d19a99428a284a8bcec27e0187b>`__ (external link to GitHub Gist)
|
||||||
|
|
||||||
|
Discussed in :issue:`46`.
|
||||||
|
|
||||||
|
Add Captions to Images
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
Instaloader does not modify the downloaded JPEG file. However, one could combine
|
||||||
|
it with an imaging library such as Pillow or PIL to render the caption on
|
||||||
|
Instagram pictures. The following shows an approach.
|
||||||
|
|
||||||
|
.. literalinclude:: codesnippets/110_pil_captions.py
|
||||||
|
|
||||||
|
See also :attr:`Post.caption`, :attr:`Post.url`, :meth:`Post.from_shortcode`,
|
||||||
|
:func:`load_structure_from_file`.
|
||||||
|
|
||||||
|
Discussed in :issue:`110`.
|
||||||
|
|
||||||
|
Metadata JSON Files
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
The JSON files Instaloader saves along with each Post contain all the metadata
|
||||||
|
that has been retrieved from Instagram while downloading the picture and
|
||||||
|
associated required information.
|
||||||
|
|
||||||
|
With `jq <https://stedolan.github.io/jq/>`__, a command-line JSON processor, the
|
||||||
|
metadata can be easily post-processed. For example, Instaloader's JSON files can
|
||||||
|
be pretty-formatted with:
|
||||||
|
|
||||||
|
.. code-block:: none
|
||||||
|
|
||||||
|
xzcat 2018-05-13_11-18-45_UTC.json.xz | jq .node
|
||||||
|
|
||||||
|
However, Instaloader tries to do as few metadata requests as possible, so,
|
||||||
|
depending on how Instaloader has been invoked, it may occur that these files do
|
||||||
|
not contain the complete available metadata structure. Nevertheless, the file
|
||||||
|
can be loaded into Instaloader with :func:`load_structure_from_file` and the
|
||||||
|
required metadata then be accessed via the :class:`Post` or :class:`Profile`
|
||||||
|
attributes, which trigger an Instagram request if that particular information is
|
||||||
|
not present in the JSON file.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
from requests import get
|
||||||
|
from PIL import Image, ImageDraw
|
||||||
|
from instaloader import *
|
||||||
|
|
||||||
|
L = Instaloader()
|
||||||
|
|
||||||
|
# Load Post instance
|
||||||
|
post = load_structure_from_file(L.context, '2017-10-01_18-53-03_UTC.json.xz')
|
||||||
|
# or post = Post.from_shortcode(L.context, SHORTCODE)
|
||||||
|
|
||||||
|
# Render caption
|
||||||
|
image = Image.open(BytesIO(get(post.url).content))
|
||||||
|
draw = ImageDraw.Draw(image)
|
||||||
|
color = 'rgb(0, 0, 0)' # black color
|
||||||
|
draw.text((300,100), post.caption.encode('latin1', errors='ignore'), fill=color)
|
||||||
|
|
||||||
|
# Save image
|
||||||
|
image.save('test.jpg')
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import instaloader
|
||||||
|
|
||||||
|
L = instaloader.Instaloader()
|
||||||
|
|
||||||
|
posts = L.get_hashtag_posts('milfgarden')
|
||||||
|
|
||||||
|
users = set()
|
||||||
|
|
||||||
|
for post in posts:
|
||||||
|
if not post.owner_profile in users:
|
||||||
|
L.download_post(post, '#milfgarden')
|
||||||
|
users.add(post.owner_profile)
|
||||||
|
else:
|
||||||
|
print("{} from {} skipped.".format(post, post.owner_profile))
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import instaloader
|
||||||
|
|
||||||
|
L = instaloader.Instaloader()
|
||||||
|
|
||||||
|
USER = 'your_account'
|
||||||
|
PROFILE = USER
|
||||||
|
|
||||||
|
# Your preferred way of logging in:
|
||||||
|
L.load_session_from_file(USER)
|
||||||
|
|
||||||
|
profile = instaloader.Profile.from_username(L.context, PROFILE)
|
||||||
|
|
||||||
|
likes = set()
|
||||||
|
print('Fetching likes of all posts of profile {}.'.format(profile.username))
|
||||||
|
for post in profile.get_posts():
|
||||||
|
print(post)
|
||||||
|
likes = likes | set(post.get_likes())
|
||||||
|
|
||||||
|
print('Fetching followers of profile {}.'.format(profile.username))
|
||||||
|
followers = set(profile.get_followers())
|
||||||
|
|
||||||
|
ghosts = followers - likes
|
||||||
|
|
||||||
|
print('Storing ghosts into file.')
|
||||||
|
with open('/YOUR PATH/inactive-users.txt', 'w') as f:
|
||||||
|
for ghost in ghosts:
|
||||||
|
print(ghost.username, file=f)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from itertools import dropwhile, takewhile
|
||||||
|
|
||||||
|
import instaloader
|
||||||
|
|
||||||
|
L = instaloader.Instaloader()
|
||||||
|
|
||||||
|
posts = L.get_hashtag_posts('milfgarden')
|
||||||
|
# or
|
||||||
|
# posts = instaloader.Profile.from_username(L.context, PROFILE).get_posts()
|
||||||
|
|
||||||
|
SINCE = datetime(2015, 5, 1)
|
||||||
|
UNTIL = datetime(2015, 3, 1)
|
||||||
|
|
||||||
|
for post in takewhile(lambda p: p.date > UNTIL, dropwhile(lambda p: p.date > SINCE, posts)):
|
||||||
|
print(post.date)
|
||||||
|
L.download_post(post, '#milfgarden')
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
from glob import glob
|
||||||
|
from sys import argv
|
||||||
|
from os import chdir
|
||||||
|
|
||||||
|
from instaloader import Instaloader, Post, Profile, load_structure_from_file
|
||||||
|
|
||||||
|
# Instaloader instantiation - you may pass additional arguments to the constructor here
|
||||||
|
L = Instaloader()
|
||||||
|
|
||||||
|
# If desired, load session previously saved with `instaloader -l USERNAME`:
|
||||||
|
#L.load_session_from_file(USERNAME)
|
||||||
|
|
||||||
|
try:
|
||||||
|
TARGET = argv[1]
|
||||||
|
except IndexError:
|
||||||
|
raise SystemExit("Pass profile name as argument!")
|
||||||
|
|
||||||
|
# Obtain set of posts that are on hard disk
|
||||||
|
chdir(TARGET)
|
||||||
|
offline_posts = set(filter(lambda s: isinstance(s, Post),
|
||||||
|
(load_structure_from_file(L.context, file)
|
||||||
|
for file in (glob('*.json.xz') + glob('*.json')))))
|
||||||
|
|
||||||
|
# Obtain set of posts that are currently online
|
||||||
|
post_iterator = Profile.from_username(L.context, TARGET).get_posts()
|
||||||
|
online_posts = set(post_iterator)
|
||||||
|
|
||||||
|
if online_posts - offline_posts:
|
||||||
|
print("Not yet downloaded posts:")
|
||||||
|
print(" ".join(str(p) for p in (online_posts - offline_posts)))
|
||||||
|
|
||||||
|
if offline_posts - online_posts:
|
||||||
|
print("Deleted posts:")
|
||||||
|
print(" ".join(str(p) for p in (offline_posts - online_posts)))
|
||||||
+4
-1
@@ -39,7 +39,8 @@ import docs.sphinx_autodoc_typehints as sphinx_autodoc_typehints
|
|||||||
extensions = [
|
extensions = [
|
||||||
'sphinx.ext.autodoc',
|
'sphinx.ext.autodoc',
|
||||||
'sphinx.ext.githubpages',
|
'sphinx.ext.githubpages',
|
||||||
'sphinx.ext.intersphinx'
|
'sphinx.ext.intersphinx',
|
||||||
|
'sphinx.ext.extlinks'
|
||||||
]
|
]
|
||||||
|
|
||||||
autodoc_default_flags = ['show-inheritance', 'members', 'undoc-members']
|
autodoc_default_flags = ['show-inheritance', 'members', 'undoc-members']
|
||||||
@@ -49,6 +50,8 @@ autodoc_member_order = 'bysource'
|
|||||||
intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
|
intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
|
||||||
'requests': ('http://docs.python-requests.org/en/master', None)}
|
'requests': ('http://docs.python-requests.org/en/master', None)}
|
||||||
|
|
||||||
|
extlinks = {'issue': ('https://github.com/instaloader/instaloader/issues/%s', 'issue #')}
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
|
|
||||||
|
|||||||
+43
-6
@@ -1,3 +1,5 @@
|
|||||||
|
.. _contributing:
|
||||||
|
|
||||||
Contributing to Instaloader
|
Contributing to Instaloader
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
@@ -15,7 +17,7 @@ Reporting Bugs
|
|||||||
If you encounter a bug, do not hesitate to report it in our
|
If you encounter a bug, do not hesitate to report it in our
|
||||||
`Issue Tracker <https://github.com/instaloader/instaloader/issues>`__. Since
|
`Issue Tracker <https://github.com/instaloader/instaloader/issues>`__. Since
|
||||||
Instaloader is actively developed, the majority of bugs is fixed within only
|
Instaloader is actively developed, the majority of bugs is fixed within only
|
||||||
**4 days** after being reported. When reporting a problem, please keep the
|
**3 days** after being reported. When reporting a problem, please keep the
|
||||||
following in mind:
|
following in mind:
|
||||||
|
|
||||||
- Ensure you **use the latest version** of Instaloader. The currently-installed
|
- Ensure you **use the latest version** of Instaloader. The currently-installed
|
||||||
@@ -23,10 +25,10 @@ following in mind:
|
|||||||
|
|
||||||
- Briefly **check whether the bug has already been reported**. If you find an
|
- Briefly **check whether the bug has already been reported**. If you find an
|
||||||
issue reporting the same bug you encountered, comment there rather than
|
issue reporting the same bug you encountered, comment there rather than
|
||||||
opening a new issue. However, if unsure, it is advised to create a new issue.
|
opening a new issue. However, if unsure, please create a new issue.
|
||||||
|
|
||||||
- State **how the bug can be reproduced**, i.e. how Instaloader was invoked
|
- State **how the bug can be reproduced**, i.e. how Instaloader was invoked
|
||||||
when the problem occured (of course, you may anonymize profile names etc.).
|
when the problem occurred (of course, you may anonymize profile names etc.).
|
||||||
|
|
||||||
- Include all **error messages and tracebacks** in the report.
|
- Include all **error messages and tracebacks** in the report.
|
||||||
|
|
||||||
@@ -47,13 +49,13 @@ few things to consider:
|
|||||||
you forked from the most recent branch.
|
you forked from the most recent branch.
|
||||||
|
|
||||||
- We use `Pylint <https://www.pylint.org/>`__ for error and syntax checking of
|
- We use `Pylint <https://www.pylint.org/>`__ for error and syntax checking of
|
||||||
``instaloader.py``. The file ``.travis.yml`` in the project's root directory
|
the source. The file ``.travis.yml`` in the project's root directory
|
||||||
shows how it is invoked. Note that sometimes it might be better to disable a
|
shows how it is invoked. Note that sometimes it might be better to disable a
|
||||||
warning rather than adapting the code to Pylint's desires.
|
warning rather than adapting the code to Pylint's desires.
|
||||||
|
|
||||||
- The documentation source is located in the ``docs`` folder. The file
|
- The documentation source is located in the ``docs`` folder. The file
|
||||||
``cli-options.rst`` is merely an RST-formatted copy of ``ìnstaloader --help``
|
``cli-options.rst`` is merely an RST-formatted copy of ``instaloader --help``
|
||||||
output, of which the source is near the bottom of ``instaloader.py``.
|
output, of which the source is in ``instaloader/__main__.py``.
|
||||||
|
|
||||||
- Feel free to contact us, even if you "only" have Proof-of-Concepts or
|
- Feel free to contact us, even if you "only" have Proof-of-Concepts or
|
||||||
not-fully integrated changes. They already might be an advance for the
|
not-fully integrated changes. They already might be an advance for the
|
||||||
@@ -81,3 +83,38 @@ Please consider the following:
|
|||||||
- **Be patient**. Naturally, bugs and pull requests have a higher priority than
|
- **Be patient**. Naturally, bugs and pull requests have a higher priority than
|
||||||
feature suggestions. Keep in mind that this is a free software project, and
|
feature suggestions. Keep in mind that this is a free software project, and
|
||||||
unfortunately we only have limited time to work on it.
|
unfortunately we only have limited time to work on it.
|
||||||
|
|
||||||
|
Donations
|
||||||
|
---------
|
||||||
|
|
||||||
|
.. donations-start
|
||||||
|
|
||||||
|
It is a pleasure for us to share our Instaloader to the world, and we are proud
|
||||||
|
to have attracted such an active and motivating community, with so many users
|
||||||
|
who share their suggestions and ideas with us. Buying a community-sponsored beer
|
||||||
|
or coffee from time to time is very likely to further raise our passion for the
|
||||||
|
development of Instaloader.
|
||||||
|
|
||||||
|
| For donations, we provide a PayPal.Me link and a Bitcoin address.
|
||||||
|
| `PayPal.me/aandergr <https://www.paypal.me/aandergr>`__
|
||||||
|
| BTC: 1Nst4LoadeYzrKjJ1DX9CpbLXBYE9RKLwY
|
||||||
|
|
||||||
|
.. donations-end
|
||||||
|
|
||||||
|
.. (Discussion in :issue:`130`)
|
||||||
|
|
||||||
|
IRC Channel
|
||||||
|
-----------
|
||||||
|
|
||||||
|
.. ircchannel-start
|
||||||
|
|
||||||
|
For a direct and personal communication within Instaloader's community, we have
|
||||||
|
an IRC channel
|
||||||
|
|
||||||
|
**#instaloader** on **Freenode**.
|
||||||
|
|
||||||
|
Freenode provides a `Web IRC Client
|
||||||
|
<https://webchat.freenode.net/?channels=instaloader>`__, allowing to join our
|
||||||
|
channel without having an IRC client installed.
|
||||||
|
|
||||||
|
.. ircchannel-end
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ Instaloader Documentation
|
|||||||
basic-usage
|
basic-usage
|
||||||
cli-options
|
cli-options
|
||||||
as-module
|
as-module
|
||||||
|
codesnippets
|
||||||
contributing
|
contributing
|
||||||
|
|
||||||
Useful Links
|
Useful Links
|
||||||
@@ -69,10 +70,27 @@ Useful Links
|
|||||||
- `Issue Tracker / Bug Tracker <https://github.com/instaloader/instaloader/issues>`__
|
- `Issue Tracker / Bug Tracker <https://github.com/instaloader/instaloader/issues>`__
|
||||||
- `Version History <https://github.com/instaloader/instaloader/releases>`__
|
- `Version History <https://github.com/instaloader/instaloader/releases>`__
|
||||||
|
|
||||||
|
Disclaimer
|
||||||
|
----------
|
||||||
|
|
||||||
.. include:: ../README.rst
|
.. include:: ../README.rst
|
||||||
:start-after: disclaimer-start
|
:start-after: disclaimer-start
|
||||||
:end-before: disclaimer-end
|
:end-before: disclaimer-end
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
------------
|
||||||
|
|
||||||
|
As an open source project, Instaloader heavily depends on the contributions from
|
||||||
|
its community. See :ref:`contributing` for how you may help Instaloader to
|
||||||
|
become an even greater tool.
|
||||||
|
|
||||||
|
.. include:: contributing.rst
|
||||||
|
:start-after: donations-start
|
||||||
|
:end-before: donations-end
|
||||||
|
|
||||||
|
.. include:: contributing.rst
|
||||||
|
:start-after: ircchannel-start
|
||||||
|
:end-before: ircchannel-end
|
||||||
|
|
||||||
..
|
..
|
||||||
* :ref:`genindex`
|
* :ref:`genindex`
|
||||||
|
|||||||
@@ -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.0.3'
|
__version__ = '4.0.6'
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
+28
-21
@@ -121,8 +121,9 @@ def _main(instaloader: Instaloader, targetlist: List[str],
|
|||||||
if target[0] == '@':
|
if target[0] == '@':
|
||||||
instaloader.context.log("Retrieving followees of %s..." % target[1:])
|
instaloader.context.log("Retrieving followees of %s..." % target[1:])
|
||||||
profile = Profile.from_username(instaloader.context, target[1:])
|
profile = Profile.from_username(instaloader.context, target[1:])
|
||||||
followees = profile.get_followees()
|
for followee in profile.get_followees():
|
||||||
profiles.update([followee.username for followee in followees])
|
instaloader.save_profile_id(followee)
|
||||||
|
profiles.add(followee)
|
||||||
elif target[0] == '#':
|
elif target[0] == '#':
|
||||||
instaloader.download_hashtag(hashtag=target[1:], max_count=max_count, fast_update=fast_update,
|
instaloader.download_hashtag(hashtag=target[1:], max_count=max_count, fast_update=fast_update,
|
||||||
post_filter=post_filter)
|
post_filter=post_filter)
|
||||||
@@ -135,26 +136,32 @@ def _main(instaloader: Instaloader, targetlist: List[str],
|
|||||||
instaloader.download_saved_posts(fast_update=fast_update, max_count=max_count,
|
instaloader.download_saved_posts(fast_update=fast_update, max_count=max_count,
|
||||||
post_filter=post_filter)
|
post_filter=post_filter)
|
||||||
else:
|
else:
|
||||||
profiles.add(target)
|
profiles.add(instaloader.check_profile_id(target))
|
||||||
if len(profiles) > 1:
|
if len(profiles) > 1:
|
||||||
instaloader.context.log("Downloading {} profiles: {}".format(len(profiles), ' '.join(profiles)))
|
instaloader.context.log("Downloading {} profiles: {}".format(len(profiles),
|
||||||
# Iterate through profiles list and download them
|
' '.join([p.username for p in profiles])))
|
||||||
for target in profiles:
|
if not stories_only:
|
||||||
with instaloader.context.error_catcher(target):
|
# Iterate through profiles list and download them
|
||||||
try:
|
for target in profiles:
|
||||||
instaloader.download_profile(target, profile_pic, profile_pic_only, fast_update,
|
with instaloader.context.error_catcher(target):
|
||||||
stories, stories_only, post_filter=post_filter,
|
try:
|
||||||
storyitem_filter=storyitem_filter)
|
instaloader.download_profile(target, profile_pic, profile_pic_only,
|
||||||
except ProfileNotExistsException as err:
|
fast_update, post_filter=post_filter)
|
||||||
if instaloader.context.is_logged_in:
|
except ProfileNotExistsException as err:
|
||||||
instaloader.context.log(err)
|
if instaloader.context.is_logged_in and not stories_only:
|
||||||
instaloader.context.log("Trying again anonymously, helps in case you are just blocked.")
|
instaloader.context.log(err)
|
||||||
with instaloader.anonymous_copy() as anonymous_loader:
|
instaloader.context.log("Trying again anonymously, helps in case you are just blocked.")
|
||||||
with instaloader.context.error_catcher():
|
with instaloader.anonymous_copy() as anonymous_loader:
|
||||||
anonymous_loader.download_profile(target, profile_pic, profile_pic_only,
|
with instaloader.context.error_catcher():
|
||||||
fast_update, post_filter=post_filter)
|
anonymous_loader.download_profile(target, profile_pic, profile_pic_only,
|
||||||
else:
|
fast_update, post_filter=post_filter)
|
||||||
raise
|
else:
|
||||||
|
raise
|
||||||
|
if stories or stories_only:
|
||||||
|
with instaloader.context.error_catcher("Download stories"):
|
||||||
|
instaloader.context.log("Downloading stories")
|
||||||
|
instaloader.download_stories(userids=list(profiles), fast_update=fast_update,
|
||||||
|
filename_target=None, storyitem_filter=storyitem_filter)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nInterrupted by user.", file=sys.stderr)
|
print("\nInterrupted by user.", file=sys.stderr)
|
||||||
# Save session if it is useful
|
# Save session if it is useful
|
||||||
|
|||||||
+35
-21
@@ -11,7 +11,7 @@ from contextlib import contextmanager, suppress
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import Callable, Iterator, List, Optional, Any
|
from typing import Any, Callable, Iterator, List, Optional, Union
|
||||||
|
|
||||||
from .exceptions import *
|
from .exceptions import *
|
||||||
from .instaloadercontext import InstaloaderContext
|
from .instaloadercontext import InstaloaderContext
|
||||||
@@ -270,14 +270,15 @@ class Instaloader:
|
|||||||
with self.context.get_anonymous_session() as anonymous_session:
|
with self.context.get_anonymous_session() as anonymous_session:
|
||||||
date_object = datetime.strptime(anonymous_session.head(profile_pic_url).headers["Last-Modified"],
|
date_object = datetime.strptime(anonymous_session.head(profile_pic_url).headers["Last-Modified"],
|
||||||
'%a, %d %b %Y %H:%M:%S GMT')
|
'%a, %d %b %Y %H:%M:%S GMT')
|
||||||
|
profile_pic_extension = 'jpg'
|
||||||
if ((format_string_contains_key(self.dirname_pattern, 'profile') or
|
if ((format_string_contains_key(self.dirname_pattern, 'profile') or
|
||||||
format_string_contains_key(self.dirname_pattern, 'target'))):
|
format_string_contains_key(self.dirname_pattern, 'target'))):
|
||||||
filename = '{0}/{1}_UTC_profile_pic.{2}'.format(self.dirname_pattern.format(profile=profile.username.lower(),
|
filename = '{0}/{1}_UTC_profile_pic.{2}'.format(self.dirname_pattern.format(profile=profile.username.lower(),
|
||||||
target=profile.username.lower()),
|
target=profile.username.lower()),
|
||||||
_epoch_to_string(date_object), profile_pic_url[-3:])
|
_epoch_to_string(date_object), profile_pic_extension)
|
||||||
else:
|
else:
|
||||||
filename = '{0}/{1}_{2}_UTC_profile_pic.{3}'.format(self.dirname_pattern.format(), profile.username.lower(),
|
filename = '{0}/{1}_{2}_UTC_profile_pic.{3}'.format(self.dirname_pattern.format(), profile.username.lower(),
|
||||||
_epoch_to_string(date_object), profile_pic_url[-3:])
|
_epoch_to_string(date_object), profile_pic_extension)
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
self.context.log(filename + ' already exists')
|
self.context.log(filename + ' already exists')
|
||||||
return None
|
return None
|
||||||
@@ -409,25 +410,26 @@ class Instaloader:
|
|||||||
|
|
||||||
@_requires_login
|
@_requires_login
|
||||||
def download_stories(self,
|
def download_stories(self,
|
||||||
userids: Optional[List[int]] = None,
|
userids: Optional[List[Union[int, Profile]]] = None,
|
||||||
fast_update: bool = False,
|
fast_update: bool = False,
|
||||||
filename_target: str = ':stories',
|
filename_target: Optional[str] = ':stories',
|
||||||
storyitem_filter: Optional[Callable[[StoryItem], bool]] = None) -> None:
|
storyitem_filter: Optional[Callable[[StoryItem], bool]] = None) -> None:
|
||||||
"""
|
"""
|
||||||
Download available stories from user followees or all stories of users whose ID are given.
|
Download available stories from user followees or all stories of users whose ID are given.
|
||||||
Does not mark stories as seen.
|
Does not mark stories as seen.
|
||||||
To use this, one needs to be logged in
|
To use this, one needs to be logged in
|
||||||
|
|
||||||
:param userids: List of user IDs to be processed in terms of downloading their stories
|
:param userids: List of user IDs or Profiles to be processed in terms of downloading their stories
|
||||||
:param fast_update: If true, abort when first already-downloaded picture is encountered
|
:param fast_update: If true, abort when first already-downloaded picture is encountered
|
||||||
:param filename_target: Replacement for {target} in dirname_pattern and filename_pattern
|
:param filename_target: Replacement for {target} in dirname_pattern and filename_pattern
|
||||||
|
or None if profile name should be used instead
|
||||||
:param storyitem_filter: function(storyitem), which returns True if given StoryItem should be downloaded
|
:param storyitem_filter: function(storyitem), which returns True if given StoryItem should be downloaded
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not userids:
|
if not userids:
|
||||||
self.context.log("Retrieving all visible stories...")
|
self.context.log("Retrieving all visible stories...")
|
||||||
|
|
||||||
for user_story in self.get_stories(userids):
|
for user_story in self.get_stories([p if isinstance(p, int) else p.userid for p in userids]):
|
||||||
name = user_story.owner_username
|
name = user_story.owner_username
|
||||||
self.context.log("Retrieving stories from profile {}.".format(name))
|
self.context.log("Retrieving stories from profile {}.".format(name))
|
||||||
totalcount = user_story.itemcount
|
totalcount = user_story.itemcount
|
||||||
@@ -439,7 +441,7 @@ class Instaloader:
|
|||||||
self.context.log("[%3i/%3i] " % (count, totalcount), end="", flush=True)
|
self.context.log("[%3i/%3i] " % (count, totalcount), end="", flush=True)
|
||||||
count += 1
|
count += 1
|
||||||
with self.context.error_catcher('Download story from user {}'.format(name)):
|
with self.context.error_catcher('Download story from user {}'.format(name)):
|
||||||
downloaded = self.download_storyitem(item, filename_target)
|
downloaded = self.download_storyitem(item, filename_target if filename_target else name)
|
||||||
if fast_update and not downloaded:
|
if fast_update and not downloaded:
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -610,6 +612,24 @@ class Instaloader:
|
|||||||
if fast_update and not downloaded:
|
if fast_update and not downloaded:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def _get_id_filename(self, profile_name: str) -> str:
|
||||||
|
if ((format_string_contains_key(self.dirname_pattern, 'profile') or
|
||||||
|
format_string_contains_key(self.dirname_pattern, 'target'))):
|
||||||
|
return '{0}/id'.format(self.dirname_pattern.format(profile=profile_name.lower(),
|
||||||
|
target=profile_name.lower()))
|
||||||
|
else:
|
||||||
|
return '{0}/{1}_id'.format(self.dirname_pattern.format(), profile_name.lower())
|
||||||
|
|
||||||
|
def save_profile_id(self, profile: Profile):
|
||||||
|
"""
|
||||||
|
Store ID of profile locally.
|
||||||
|
"""
|
||||||
|
os.makedirs(self.dirname_pattern.format(profile=profile.username,
|
||||||
|
target=profile.username), exist_ok=True)
|
||||||
|
with open(self._get_id_filename(profile.username), 'w') as text_file:
|
||||||
|
text_file.write(str(profile.userid) + "\n")
|
||||||
|
self.context.log("Stored ID {0} for profile {1}.".format(profile.userid, profile.username))
|
||||||
|
|
||||||
def check_profile_id(self, profile_name: str) -> Profile:
|
def check_profile_id(self, profile_name: str) -> Profile:
|
||||||
"""
|
"""
|
||||||
Consult locally stored ID of profile with given name, check whether ID matches and whether name
|
Consult locally stored ID of profile with given name, check whether ID matches and whether name
|
||||||
@@ -622,12 +642,7 @@ class Instaloader:
|
|||||||
with suppress(ProfileNotExistsException):
|
with suppress(ProfileNotExistsException):
|
||||||
profile = Profile.from_username(self.context, profile_name)
|
profile = Profile.from_username(self.context, profile_name)
|
||||||
profile_exists = profile is not None
|
profile_exists = profile is not None
|
||||||
if ((format_string_contains_key(self.dirname_pattern, 'profile') or
|
id_filename = self._get_id_filename(profile_name)
|
||||||
format_string_contains_key(self.dirname_pattern, 'target'))):
|
|
||||||
id_filename = '{0}/id'.format(self.dirname_pattern.format(profile=profile_name.lower(),
|
|
||||||
target=profile_name.lower()))
|
|
||||||
else:
|
|
||||||
id_filename = '{0}/{1}_id'.format(self.dirname_pattern.format(), profile_name.lower())
|
|
||||||
try:
|
try:
|
||||||
with open(id_filename, 'rb') as id_file:
|
with open(id_filename, 'rb') as id_file:
|
||||||
profile_id = int(id_file.read())
|
profile_id = int(id_file.read())
|
||||||
@@ -656,15 +671,11 @@ class Instaloader:
|
|||||||
except (FileNotFoundError, ValueError):
|
except (FileNotFoundError, ValueError):
|
||||||
pass
|
pass
|
||||||
if profile_exists:
|
if profile_exists:
|
||||||
os.makedirs(self.dirname_pattern.format(profile=profile_name.lower(),
|
self.save_profile_id(profile)
|
||||||
target=profile_name.lower()), exist_ok=True)
|
|
||||||
with open(id_filename, 'w') as text_file:
|
|
||||||
text_file.write(str(profile.userid) + "\n")
|
|
||||||
self.context.log("Stored ID {0} for profile {1}.".format(profile.userid, profile_name))
|
|
||||||
return profile
|
return profile
|
||||||
raise ProfileNotExistsException("Profile {0} does not exist.".format(profile_name))
|
raise ProfileNotExistsException("Profile {0} does not exist.".format(profile_name))
|
||||||
|
|
||||||
def download_profile(self, profile_name: str,
|
def download_profile(self, profile_name: Union[str, Profile],
|
||||||
profile_pic: bool = True, profile_pic_only: bool = False,
|
profile_pic: bool = True, profile_pic_only: bool = False,
|
||||||
fast_update: bool = False,
|
fast_update: bool = False,
|
||||||
download_stories: bool = False, download_stories_only: bool = False,
|
download_stories: bool = False, download_stories_only: bool = False,
|
||||||
@@ -675,7 +686,10 @@ class Instaloader:
|
|||||||
# Get profile main page json
|
# Get profile main page json
|
||||||
# check if profile does exist or name has changed since last download
|
# check if profile does exist or name has changed since last download
|
||||||
# and update name and json data if necessary
|
# and update name and json data if necessary
|
||||||
profile = self.check_profile_id(profile_name.lower())
|
if isinstance(profile_name, str):
|
||||||
|
profile = self.check_profile_id(profile_name.lower())
|
||||||
|
else:
|
||||||
|
profile = profile_name
|
||||||
|
|
||||||
profile_name = profile.username
|
profile_name = profile.username
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,9 @@ class InstaloaderContext:
|
|||||||
:raises InvalidArgumentException: If the provided username does not exist.
|
:raises InvalidArgumentException: If the provided username does not exist.
|
||||||
:raises BadCredentialsException: If the provided password is wrong.
|
:raises BadCredentialsException: If the provided password is wrong.
|
||||||
:raises ConnectionException: If connection to Instagram failed."""
|
:raises ConnectionException: If connection to Instagram failed."""
|
||||||
|
import http.client
|
||||||
|
# pylint:disable=protected-access
|
||||||
|
http.client._MAXHEADERS = 200
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.cookies.update({'sessionid': '', 'mid': '', 'ig_pr': '1',
|
session.cookies.update({'sessionid': '', 'mid': '', 'ig_pr': '1',
|
||||||
'ig_vw': '1920', 'csrftoken': '',
|
'ig_vw': '1920', 'csrftoken': '',
|
||||||
|
|||||||
+17
-10
@@ -93,10 +93,9 @@ class Post:
|
|||||||
return b64encode(mediaid.to_bytes(9, 'big'), b'-_').decode().replace('A', ' ').lstrip().replace(' ', 'A')
|
return b64encode(mediaid.to_bytes(9, 'big'), b'-_').decode().replace('A', ' ').lstrip().replace(' ', 'A')
|
||||||
|
|
||||||
def _asdict(self):
|
def _asdict(self):
|
||||||
|
node = self._node
|
||||||
if self._full_metadata_dict:
|
if self._full_metadata_dict:
|
||||||
node = self._full_metadata_dict
|
node.update(self._full_metadata_dict)
|
||||||
else:
|
|
||||||
node = self._node
|
|
||||||
if self._owner_profile:
|
if self._owner_profile:
|
||||||
node['owner'] = self.owner_profile._asdict()
|
node['owner'] = self.owner_profile._asdict()
|
||||||
if self._location:
|
if self._location:
|
||||||
@@ -206,10 +205,7 @@ class Post:
|
|||||||
@property
|
@property
|
||||||
def typename(self) -> str:
|
def typename(self) -> str:
|
||||||
"""Type of post, GraphImage, GraphVideo or GraphSidecar"""
|
"""Type of post, GraphImage, GraphVideo or GraphSidecar"""
|
||||||
if '__typename' in self._node:
|
return self._field('__typename')
|
||||||
return self._node['__typename']
|
|
||||||
# if __typename is not in node, it is an old image or video
|
|
||||||
return 'GraphImage'
|
|
||||||
|
|
||||||
def get_sidecar_nodes(self) -> Iterator[PostSidecarNode]:
|
def get_sidecar_nodes(self) -> Iterator[PostSidecarNode]:
|
||||||
"""Sidecar nodes of a Post with typename==GraphSidecar."""
|
"""Sidecar nodes of a Post with typename==GraphSidecar."""
|
||||||
@@ -530,10 +526,11 @@ class Profile:
|
|||||||
@property
|
@property
|
||||||
def has_highlight_reels(self) -> bool:
|
def has_highlight_reels(self) -> bool:
|
||||||
"""
|
"""
|
||||||
This becomes `True` if the :class:`Profile` has any stories currently available,
|
Always returns `True` since :issue:`153`.
|
||||||
even if not viewable by the viewer.
|
|
||||||
|
Before broken, this indicated whether the :class:`Profile` had available stories.
|
||||||
"""
|
"""
|
||||||
return self._iphone_struct['has_highlight_reels']
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_public_story(self) -> bool:
|
def has_public_story(self) -> bool:
|
||||||
@@ -613,6 +610,16 @@ class Profile:
|
|||||||
self._rhx_gis,
|
self._rhx_gis,
|
||||||
self._metadata('edge_saved_media')))
|
self._metadata('edge_saved_media')))
|
||||||
|
|
||||||
|
def get_tagged_posts(self) -> Iterator[Post]:
|
||||||
|
"""Retrieve all posts where a profile is tagged."""
|
||||||
|
self._obtain_metadata()
|
||||||
|
yield from (Post(self._context, node, self) for node in
|
||||||
|
self._context.graphql_node_list("e31a871f7301132ceaab56507a66bbb7",
|
||||||
|
{'id': self.userid},
|
||||||
|
'https://www.instagram.com/{0}/'.format(self.username),
|
||||||
|
lambda d: d['data']['user']['edge_user_to_photos_of_you'],
|
||||||
|
self._rhx_gis))
|
||||||
|
|
||||||
def get_followers(self) -> Iterator['Profile']:
|
def get_followers(self) -> Iterator['Profile']:
|
||||||
"""
|
"""
|
||||||
Retrieve list of followers of given profile.
|
Retrieve list of followers of given profile.
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ NORMAL_MAX_COUNT = 2
|
|||||||
PAGING_MAX_COUNT = 15
|
PAGING_MAX_COUNT = 15
|
||||||
PRIVATE_PROFILE = "aandergr"
|
PRIVATE_PROFILE = "aandergr"
|
||||||
|
|
||||||
|
# Preserve query timestamps (rate control) between tests to not get rate limited
|
||||||
|
instaloadercontext_query_timestamps = list()
|
||||||
|
|
||||||
|
|
||||||
class TestInstaloaderAnonymously(unittest.TestCase):
|
class TestInstaloaderAnonymously(unittest.TestCase):
|
||||||
|
|
||||||
@@ -27,23 +30,31 @@ class TestInstaloaderAnonymously(unittest.TestCase):
|
|||||||
download_comments=True,
|
download_comments=True,
|
||||||
save_metadata=True)
|
save_metadata=True)
|
||||||
self.L.context.raise_all_errors = True
|
self.L.context.raise_all_errors = True
|
||||||
|
self.L.context.query_timestamps = instaloadercontext_query_timestamps
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
global instaloadercontext_query_timestamps
|
||||||
|
instaloadercontext_query_timestamps = self.L.context.query_timestamps
|
||||||
self.L.close()
|
self.L.close()
|
||||||
os.chdir('/')
|
os.chdir('/')
|
||||||
print("Removing {}".format(self.dir))
|
print("Removing {}".format(self.dir))
|
||||||
shutil.rmtree(self.dir)
|
shutil.rmtree(self.dir)
|
||||||
|
|
||||||
|
def post_paging_test(self, iterator):
|
||||||
|
previous_post = None
|
||||||
|
for post in islice(iterator, PAGING_MAX_COUNT):
|
||||||
|
print(post)
|
||||||
|
if previous_post:
|
||||||
|
self.assertTrue(post.date_utc < previous_post.date_utc)
|
||||||
|
previous_post = post
|
||||||
|
|
||||||
@unittest.SkipTest
|
@unittest.SkipTest
|
||||||
def test_public_profile_download(self):
|
def test_public_profile_download(self):
|
||||||
self.L.download_profile(PUBLIC_PROFILE, profile_pic=False, fast_update=True)
|
self.L.download_profile(PUBLIC_PROFILE, profile_pic=False, fast_update=True)
|
||||||
self.L.download_profile(PUBLIC_PROFILE, profile_pic=False, fast_update=True)
|
self.L.download_profile(PUBLIC_PROFILE, profile_pic=False, fast_update=True)
|
||||||
|
|
||||||
def test_public_profile_paging(self):
|
def test_public_profile_paging(self):
|
||||||
for count, post in enumerate(instaloader.Profile.from_username(self.L.context, PUBLIC_PROFILE).get_posts()):
|
self.post_paging_test(instaloader.Profile.from_username(self.L.context, PUBLIC_PROFILE).get_posts())
|
||||||
print(post)
|
|
||||||
if count == PAGING_MAX_COUNT:
|
|
||||||
break
|
|
||||||
|
|
||||||
def test_profile_pic_download(self):
|
def test_profile_pic_download(self):
|
||||||
self.L.download_profile(PUBLIC_PROFILE, profile_pic_only=True)
|
self.L.download_profile(PUBLIC_PROFILE, profile_pic_only=True)
|
||||||
@@ -65,6 +76,11 @@ class TestInstaloaderAnonymously(unittest.TestCase):
|
|||||||
self.assertEqual(post, post2)
|
self.assertEqual(post, post2)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def test_public_profile_tagged_paging(self):
|
||||||
|
for post in islice(instaloader.Profile.from_username(self.L.context, PUBLIC_PROFILE).get_tagged_posts(),
|
||||||
|
PAGING_MAX_COUNT):
|
||||||
|
print(post)
|
||||||
|
|
||||||
|
|
||||||
class TestInstaloaderLoggedIn(TestInstaloaderAnonymously):
|
class TestInstaloaderLoggedIn(TestInstaloaderAnonymously):
|
||||||
|
|
||||||
@@ -87,10 +103,7 @@ class TestInstaloaderLoggedIn(TestInstaloaderAnonymously):
|
|||||||
print(item)
|
print(item)
|
||||||
|
|
||||||
def test_private_profile_paging(self):
|
def test_private_profile_paging(self):
|
||||||
for count, post in enumerate(instaloader.Profile.from_username(self.L.context, PRIVATE_PROFILE).get_posts()):
|
self.post_paging_test(instaloader.Profile.from_username(self.L.context, PRIVATE_PROFILE).get_posts())
|
||||||
print(post)
|
|
||||||
if count == PAGING_MAX_COUNT:
|
|
||||||
break
|
|
||||||
|
|
||||||
def test_feed_download(self):
|
def test_feed_download(self):
|
||||||
self.L.download_feed_posts(NORMAL_MAX_COUNT)
|
self.L.download_feed_posts(NORMAL_MAX_COUNT)
|
||||||
|
|||||||
Reference in New Issue
Block a user