DOE AGORA Qualquer valor

Baixar fotos do Instagram

Baixar fotos do Instagram 

Aqui descrevemos como usar o Instaloader para baixar fotos do Instagram. Se você ainda não tem o Instaloader instalado, consulte Instalar o Instaloader .

Uso 

Para baixar todas as fotos e vídeos de um perfil , bem como a foto do perfil , faça

instaloader profile [profile ...]

onde profileé o nome de um perfil que você deseja baixar. Em vez de apenas um perfil, você também pode especificar uma lista de perfis.

Para atualizar posteriormente sua cópia local desses perfis, você pode executar

instaloader --fast-update profile [profile ...]

Se --fast-updatefor fornecido, o Instaloader para ao chegar à primeira imagem já baixada.

Como alternativa, você pode usar --latest-stampspara que o Instaloader armazene a hora em que cada perfil foi baixado pela última vez e baixe apenas a mídia mais recente:

instaloader --latest-stamps -- profile [profile ...]

Com esta opção é possível mover ou excluir a mídia baixada e ainda manter o arquivo atualizado.

Ao atualizar os perfis, o Instaloader detecta automaticamente as alterações no nome do perfil e renomeia o diretório de destino de acordo.

O Instaloader também pode ser usado para baixar perfis privados . Para isso, invoque-o com

instaloader --login=your_username profile [profile ...]

Ao fazer login, o Instaloader armazena os cookies de sessão em um arquivo em seu diretório inicial, que será reutilizado posteriormente na próxima vez --login . Assim, você pode baixar perfis privados de forma não interativa quando já possui um arquivo de cookie de sessão válido.

O que baixar 

O Instaloader é compatível com os seguintes destinos:

  • profile

    Perfil público ou perfil privado com --login.

    Se um perfil já baixado foi renomeado, o Instaloader o encontra automaticamente por seu ID exclusivo e renomeia a pasta de acordo.

    Além das postagens do perfil, sua foto de perfil atual é baixada. Para cada perfil que você baixar,

    • --stories

      instrui o Instaloader a também baixar as histórias do usuário ,

    • --highlights

      para baixar os destaques desse perfil ,

    • --tagged

      para baixar postagens em que o usuário é marcado e

    • --igtv

      para baixar vídeos IGTV .

  • "#hashtag"

    Postagens com uma determinada hashtag (as aspas geralmente são necessárias).

  • %location id

    Postagens marcadas com um determinado local; o ID do local é o ID numérico com o qual o Instagram rotula um local (por exemplo, https://www.instagram.com/explore/locations/ 362629379 /plymouth-naval-memorial/). Requer --login.

    Novo na versão 4.2.

  • :stories

    As histórias atualmente visíveis de seus seguidores (requer --login).

  • :feed

    Seu feed (requer --login).

  • :saved

    Posts which are marked as saved (requires --login).

  • @profile

    All profiles that are followed by profile, i.e. the followees of profile (requires --login).

  • -post

    Replace post with the post’s shortcode to download single post. Must be preceded by -- in the argument list to not be mistaken as an option flag:

    instaloader -- -B_K4CykAOtf
    

    New in version 4.1.

Instaloader goes through all media matching the specified targets and downloads the pictures and videos and their captions. You can specify

  • --comments

    also download comments of each post,

  • --geotags

    download geotags of each post and save them as Google Maps link (requires --login),

For a reference of all supported command line options, see Command Line Options.

Filename Specification

For each target, Instaloader creates a directory named after the target, i.e. profile#hashtag%location id:feed, etc. and therein saves the posts in files named after the post’s timestamp.

--dirname-pattern allows to configure the directory name of each target. The default is --dirname-pattern={target}. In the dirname pattern, the token {target} is replaced by the target name, and {profile} is replaced by the owner of the post which is downloaded.

--filename-pattern configures the path of the post and story’s files relative to the target directory that is specified with --dirname-pattern. The default is --filename-pattern={date_utc}_UTC. The tokens {target} and {profile} are replaced like in the dirname pattern.

--title-pattern is similar to --filename-pattern, but for profile pics, hashtag profile pics, and highlight covers. The default is {date_utc}_UTC_{typename} if --dirname-pattern contains {target} or {profile}, or {target}_{date_utc}_UTC_{typename} if it does not. Some tokens are not supported for this option, see below for details.

The following tokens are defined for usage with --filename-pattern and --title-pattern:

  • {target}

    Target name (as given in Instaloader command line)

  • {profile} (same as {owner_username})

    Owner of the Post / StoryItem / ProfilePic. For hashtag profile pics and highlight covers, equivalent to {target}.

  • {owner_id}

    Unique integer ID of owner profile. For hashtag profile pics, equivalent to {target}.

  • {shortcode}

    Shortcode (identifier string). Not available for --title-pattern.

  • {mediaid}

    Integer representation of shortcode. Not available for --title-pattern.

  • {filename}

    Instagram’s internal filename.

  • {date_utc} (same as {date})

    Creation time in UTC timezone. strftime()-style formatting options are supported as format specifier. The default date format specifier used by Instaloader is:

    {date_utc:%Y-%m-%d_%H-%M-%S}
    
  • {typename}

    Type of media being saved, such as GraphImage, GraphStoryVideo, profile_pic, etc.

For example, encode the poster’s profile name in the filenames with:

instaloader --filename-pattern={date_utc}_UTC_{profile} "#hashtag"

As another example, you may instruct Instaloader to store posts in a PROFILE/YEAR/SHORTCODE.jpg directory structure:

instaloader --dirname-pattern={profile} --filename-pattern={date_utc:%Y}/{shortcode} <target> ...

Filter Posts

The options --post-filter and --storyitem-filter allow to specify criteria that posts or story items have to meet to be downloaded. If not given, all posts are downloaded.

The filter string must be a Python boolean expression where the attributes from Post or StoryItem respectively are defined.

Id est, the following attributes can be used with both --post-filter and --storyitem-filter:

  • owner_username (str), owner_id (int)

    Owner profile username / user ID.

  • date_utc (datetime), date_local (datetime)

    Creation timestamp. Since datetime objects can be created inside filter strings, this easily allows filtering by creation date. E.g.:

    instaloader --post-filter="date_utc <= datetime(2018, 5, 31)" target
    
  • is_video (bool)

    Whether Post/StoryItem is a video. For example, you may skip videos:

    instaloader --post-filter="not is_video" target
    

    This is not the same as --no-videos and --no-video-thumbnails, since sidecar posts (posts that contain multiple pictures/videos in one post) have this attribute set to False.

As --post-filter, the following attributes can be used additionally:

  • viewer_has_liked (bool)

    Whether user (with --login) has liked given post. To download the pictures from your feed that you have liked:

    instaloader --login=your_username --post-filter=viewer_has_liked :feed
    
  • likes (int), comments (int)

    Likes count / comments count. You might only want to download posts that were either liked by yourself or by many others:

    instaloader --login=your_username --post-filter="likes>100 or viewer_has_liked" profile
    
  • caption_hashtags (list of str) / caption_mentions (list of str)

    #hashtags or @mentions (lowercased) in the Post’s caption. For example, to download posts of kittens that are cute:

    instaloader --post-filter="'cute' in caption_hashtags" "#kitten"
    
  • tagged_users (list of str)

    Lowercased usernames that are tagged in the Post.

For --storyitem-filter, the following additional attributes are defined:

Metadata Text Files

Unless --no-captions is given, Instaloader creates a .txt file along with each post where the Post’s caption is saved.

You can customize what metadata to save for each Post or StoryItem with --post-metadata-txt and --storyitem-metadata-txt. The default is --post-metadata-txt={caption} and no storyitem metadata txt. These strings are formatted similar as the path patterns described in Filename Specification and the result is saved in text files, unless it is empty.

Specifying these options multiple times results in output having multiple lines, in the order they were given to Instaloader.

The field names are evaluated to Post or StoryItem attributes, and as such, the same fields are supported as in Filename Specification and Filter Posts.

For example, to save the current number of likes for each post, rather than the post’s caption:

instaloader --post-metadata-txt="{likes} likes." <target>

Note that with this feature, it is possible to easily and fastly extract additional metadata of already-downloaded posts, by reimporting their JSON files. Say, you now also want to export the number of comments the Posts had when they were downloaded:

instaloader --post-metadata-txt="{likes} likes, {comments} comments." <target>/*.json.xz

Instaloader as Cronjob

Instaloader is suitable for running as a cronjob to periodically update your personal Instagram archive. The --quiet option disables user interactions and logging of non-error messages. To non-interactively use Instaloader logged-in, create a session file:

instaloader --login=your_username

Then use the same username in your cronjob to load the session and download the given targets:

instaloader --login=your_username --quiet target [...]

O Instaloader salva o arquivo de sessão em ~/.config/instaloader/session-YOUR-USERNAMEVeja --sessionfilea opção de como substituir este caminho.

Programando Instaloader 

Se sua tarefa não puder ser feita com a interface de linha de comando do Instaloader, considere dar uma olhada no Instaloader do Módulo Python . O Instaloader expõe seus métodos e estruturas usados ​​internamente, tornando-se uma API Python poderosa e intuitiva para Instagram, permitindo personalizar ainda mais a obtenção de mídia e metadados.

Veja também exemplos avançados do Instaloader , onde coletamos alguns scripts de exemplo que usam o Instaloader para tarefas simples que não podem ser feitas com a interface de linha de comando.

Próxima seção

Opções de linha de comando

Comentários

Ebook

Postagens mais visitadas