mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-01-10 20:45:51 +01:00
Instagram user reels extractor
This commit is contained in:
parent
0b6b7742c2
commit
998965b78a
@ -874,6 +874,7 @@
|
||||
InstagramStoryIE,
|
||||
InstagramTagIE,
|
||||
InstagramUserIE,
|
||||
InstagramUserReelsIE,
|
||||
)
|
||||
from .internazionale import InternazionaleIE
|
||||
from .internetvideoarchive import InternetVideoArchiveIE
|
||||
|
@ -653,6 +653,51 @@ def _query_vars_for(data):
|
||||
}
|
||||
|
||||
|
||||
class InstagramUserReelsIE(InstagramBaseIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?instagram\.com/(?P<id>[^/]{2,})/reels/?'
|
||||
IE_DESC = 'Instagram user reels'
|
||||
IE_NAME = 'instagram:user:reels'
|
||||
|
||||
def _real_extract(self, url):
|
||||
username = self._match_valid_url(url).group('id')
|
||||
|
||||
webpage = self._download_webpage(url, username)
|
||||
user_info = self._search_json(r'"props":', webpage, 'user info', username)
|
||||
|
||||
user_id = user_info['id']
|
||||
csrf_token = self._get_cookies('https://www.instagram.com').get('csrftoken')
|
||||
|
||||
def reels():
|
||||
max_id = None
|
||||
for page in itertools.count(1):
|
||||
resp = self._download_json(
|
||||
f'{self._API_BASE_URL}/clips/user/',
|
||||
video_id=username, note=f'Downloading page {page}',
|
||||
data=urlencode_postdata({
|
||||
'include_feed_video': 'true',
|
||||
'page_size': 12,
|
||||
'target_user_id': user_id,
|
||||
**({'max_id': max_id} if max_id else {}),
|
||||
}),
|
||||
headers={
|
||||
**self._API_HEADERS,
|
||||
'X-CSRFToken': csrf_token.value,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Referer': url,
|
||||
},
|
||||
)
|
||||
|
||||
for item in resp['items']:
|
||||
yield self._extract_product(item['media'])
|
||||
|
||||
paging_info = resp['paging_info']
|
||||
if not paging_info['more_available']:
|
||||
break
|
||||
max_id = paging_info['max_id']
|
||||
|
||||
return self.playlist_result(reels(), playlist_id=username, playlist_title=f'Reels of {username}')
|
||||
|
||||
|
||||
class InstagramTagIE(InstagramPlaylistBaseIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?instagram\.com/explore/tags/(?P<id>[^/]+)'
|
||||
IE_DESC = 'Instagram hashtag search URLs'
|
||||
|
Loading…
Reference in New Issue
Block a user