pax_global_header 0000666 0000000 0000000 00000000064 14575653726 0014536 g ustar 00root root 0000000 0000000 52 comment=5f3d558793b537a74480241ac6981479f5938cd3
woob-master-5f3d558793b537a74480241ac6981479f5938cd3-modules-instagram/ 0000775 0000000 0000000 00000000000 14575653726 0024027 5 ustar 00root root 0000000 0000000 woob-master-5f3d558793b537a74480241ac6981479f5938cd3-modules-instagram/modules/ 0000775 0000000 0000000 00000000000 14575653726 0025477 5 ustar 00root root 0000000 0000000 woob-master-5f3d558793b537a74480241ac6981479f5938cd3-modules-instagram/modules/instagram/ 0000775 0000000 0000000 00000000000 14575653726 0027464 5 ustar 00root root 0000000 0000000 woob-master-5f3d558793b537a74480241ac6981479f5938cd3-modules-instagram/modules/instagram/__init__.py0000664 0000000 0000000 00000001505 14575653726 0031576 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2020 Vincent A
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from .module import InstagramModule
__all__ = ['InstagramModule']
woob-master-5f3d558793b537a74480241ac6981479f5938cd3-modules-instagram/modules/instagram/browser.py 0000664 0000000 0000000 00000004034 14575653726 0031522 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2020 Vincent A
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
# flake8: compatible
import json
from woob.browser import PagesBrowser, URL
from woob.browser.cache import CacheMixin
from .pages import HomePage, OtherPage
class InstagramBrowser(CacheMixin, PagesBrowser):
BASEURL = 'https://www.instagram.com'
pagination = URL(r'/graphql/query/', OtherPage)
home = URL(r'/(?P[^/]+)/', HomePage)
def __init__(self, user, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user = user
self.is_updatable = True
open = CacheMixin.open_with_cache
def iter_images(self):
self.home.go(user=self.user)
user_id = self.page.get_user_id()
author = self.page.get_author_name()
def set_author(obj):
obj.author = author
return obj
yield from map(set_author, self.page.iter_images())
while True:
after = self.page.get_end_cursor()
if not after:
return
self.pagination.go(params={
'query_hash': 'bfa387b2992c3a52dcbe447467b4b771',
'variables': json.dumps({
'id': user_id,
'first': 12,
'after': after,
}),
})
yield from map(set_author, self.page.iter_images())
woob-master-5f3d558793b537a74480241ac6981479f5938cd3-modules-instagram/modules/instagram/module.py 0000664 0000000 0000000 00000003540 14575653726 0031325 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2020 Vincent A
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
# flake8: compatible
from woob.tools.backend import Module, BackendConfig
from woob.tools.value import Value
from woob.capabilities.image import CapImage, BaseImage, Thumbnail
from woob.capabilities.collection import CapCollection
from .browser import InstagramBrowser
__all__ = ['InstagramModule']
class InstagramModule(Module, CapImage, CapCollection):
NAME = 'instagram'
DESCRIPTION = 'Instagram'
MAINTAINER = 'Vincent A'
EMAIL = 'dev@indigo.re'
LICENSE = 'LGPLv3+'
VERSION = '3.6'
BROWSER = InstagramBrowser
CONFIG = BackendConfig(
Value('user')
)
def create_default_browser(self):
return self.create_browser(self.config['user'].get())
def iter_resources(self, types, split_path):
for type in types:
if issubclass(type, BaseImage):
yield from self.browser.iter_images()
break
def fill_img(self, img, fields):
if 'data' in fields and img.url:
img.data = self.browser.open(img.url).content
OBJECTS = {
BaseImage: fill_img,
Thumbnail: fill_img,
}
woob-master-5f3d558793b537a74480241ac6981479f5938cd3-modules-instagram/modules/instagram/pages.py 0000664 0000000 0000000 00000007472 14575653726 0031147 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2020 Vincent A
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
# flake8: compatible
import re
from woob.browser.elements import method, DictElement, ItemElement
from woob.browser.filters.json import Dict
from woob.browser.filters.standard import FromTimestamp, Env
from woob.browser.pages import JsonPage
from woob.capabilities.image import BaseImage, Thumbnail
from woob.capabilities.file import LICENSES
class shared_image_element(ItemElement):
klass = BaseImage
obj_id = Dict('node/id')
obj_title = obj_id
obj_ext = 'jpg'
obj_license = LICENSES.COPYRIGHT
obj_url = Dict('node/display_url')
class single_element(shared_image_element):
# entry with a single pic
obj_date = FromTimestamp(Dict('node/taken_at_timestamp'))
obj_description = Dict('node/accessibility_caption', default=None)
def obj_thumbnail(self):
return Thumbnail(Dict('node/thumbnail_src')(self))
class env_image_element(shared_image_element):
# entry with multiple pics
# this is a child node of an entry, it shares some info with its siblings nodes
obj_date = Env('date')
obj_description = Env('description')
obj_thumbnail = Env('thumbnail')
class children_elements(DictElement):
item_xpath = 'node/edge_sidecar_to_children/edges'
item = env_image_element
def parse(self, el):
self.env['date'] = FromTimestamp(Dict('node/taken_at_timestamp'))(self)
self.env['description'] = Dict('node/accessibility_caption', default=None)(self)
self.env['thumbnail'] = Thumbnail(Dict('node/thumbnail_src')(self))
class single_or_multiple_element(DictElement):
# for each entry, there can be:
# - 1 single picture (single_element)
# - or several pictures (children edges)
def __iter__(self):
if 'edge_sidecar_to_children' in self.el['node']:
return iter(children_elements(self.page, self, self.el))
return iter(single_element(self.page, self, self.el))
class ListPageMixin:
def get_end_cursor(self):
if not self.subdoc['edge_owner_to_timeline_media']['page_info']['has_next_page']:
return
return self.subdoc['edge_owner_to_timeline_media']['page_info']['end_cursor']
class HomePage(ListPageMixin, JsonPage):
def build_doc(self, text):
text = re.search(r'_sharedData = (\{.*?\});