mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-23 00:54:31 +01:00
[instagram] fix user videos extraction(fixes #15858)
This commit is contained in:
parent
46c6742d4f
commit
27b1c73f14
@ -1,6 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import itertools
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
@ -238,36 +238,25 @@ class InstagramUserIE(InfoExtractor):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _entries(self, uploader_id):
|
def _entries(self, uploader_id):
|
||||||
query = {
|
def get_count(suffix):
|
||||||
'__a': 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_count(kind):
|
|
||||||
return int_or_none(try_get(
|
return int_or_none(try_get(
|
||||||
node, lambda x: x['%ss' % kind]['count']))
|
node, lambda x: x['edge_media_' + suffix]['count']))
|
||||||
|
|
||||||
for page_num in itertools.count(1):
|
edges = self._download_json(
|
||||||
page = self._download_json(
|
'https://www.instagram.com/graphql/query/', uploader_id, query={
|
||||||
'https://instagram.com/%s/' % uploader_id, uploader_id,
|
'query_hash': '472f257a40c653c64c666ce877d59d2b',
|
||||||
note='Downloading page %d' % page_num,
|
'variables': json.dumps({
|
||||||
fatal=False, query=query)
|
'id': uploader_id,
|
||||||
if not page:
|
'first': 999999999,
|
||||||
break
|
})
|
||||||
|
})['data']['user']['edge_owner_to_timeline_media']['edges']
|
||||||
|
|
||||||
nodes = try_get(page, lambda x: x['user']['media']['nodes'], list)
|
for edge in edges:
|
||||||
if not nodes:
|
node = edge['node']
|
||||||
break
|
|
||||||
|
|
||||||
max_id = None
|
|
||||||
|
|
||||||
for node in nodes:
|
|
||||||
node_id = node.get('id')
|
|
||||||
if node_id:
|
|
||||||
max_id = node_id
|
|
||||||
|
|
||||||
if node.get('__typename') != 'GraphVideo' and node.get('is_video') is not True:
|
if node.get('__typename') != 'GraphVideo' and node.get('is_video') is not True:
|
||||||
continue
|
continue
|
||||||
video_id = node.get('code')
|
video_id = node.get('shortcode')
|
||||||
if not video_id:
|
if not video_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -276,14 +265,14 @@ class InstagramUserIE(InfoExtractor):
|
|||||||
ie=InstagramIE.ie_key(), video_id=video_id)
|
ie=InstagramIE.ie_key(), video_id=video_id)
|
||||||
|
|
||||||
description = try_get(
|
description = try_get(
|
||||||
node, [lambda x: x['caption'], lambda x: x['text']['id']],
|
node, lambda x: x['edge_media_to_caption']['edges'][0]['node']['text'],
|
||||||
compat_str)
|
compat_str)
|
||||||
thumbnail = node.get('thumbnail_src') or node.get('display_src')
|
thumbnail = node.get('thumbnail_src') or node.get('display_src')
|
||||||
timestamp = int_or_none(node.get('date'))
|
timestamp = int_or_none(node.get('taken_at_timestamp'))
|
||||||
|
|
||||||
comment_count = get_count('comment')
|
comment_count = get_count('to_comment')
|
||||||
like_count = get_count('like')
|
like_count = get_count('preview_like')
|
||||||
view_count = int_or_none(node.get('video_views'))
|
view_count = int_or_none(node.get('video_view_count'))
|
||||||
|
|
||||||
info.update({
|
info.update({
|
||||||
'description': description,
|
'description': description,
|
||||||
@ -296,12 +285,11 @@ class InstagramUserIE(InfoExtractor):
|
|||||||
|
|
||||||
yield info
|
yield info
|
||||||
|
|
||||||
if not max_id:
|
|
||||||
break
|
|
||||||
|
|
||||||
query['max_id'] = max_id
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
uploader_id = self._match_id(url)
|
username = self._match_id(url)
|
||||||
|
uploader_id = self._download_json(
|
||||||
|
'https://instagram.com/%s/' % username, username, query={
|
||||||
|
'__a': 1,
|
||||||
|
})['graphql']['user']['id']
|
||||||
return self.playlist_result(
|
return self.playlist_result(
|
||||||
self._entries(uploader_id), uploader_id, uploader_id)
|
self._entries(uploader_id), username, username)
|
||||||
|
Loading…
Reference in New Issue
Block a user