mirror of
https://github.com/bellingcat/snscrape.git
synced 2026-06-12 20:38:29 +03:00
@@ -111,6 +111,7 @@ class Medium:
|
|||||||
class Photo(Medium):
|
class Photo(Medium):
|
||||||
previewUrl: str
|
previewUrl: str
|
||||||
fullUrl: str
|
fullUrl: str
|
||||||
|
altText: typing.Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
@@ -126,12 +127,14 @@ class Video(Medium):
|
|||||||
variants: typing.List[VideoVariant]
|
variants: typing.List[VideoVariant]
|
||||||
duration: typing.Optional[float] = None
|
duration: typing.Optional[float] = None
|
||||||
views: typing.Optional[int] = None
|
views: typing.Optional[int] = None
|
||||||
|
altText: typing.Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class Gif(Medium):
|
class Gif(Medium):
|
||||||
thumbnailUrl: str
|
thumbnailUrl: str
|
||||||
variants: typing.List[VideoVariant]
|
variants: typing.List[VideoVariant]
|
||||||
|
altText: typing.Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
@@ -949,10 +952,13 @@ class _TwitterAPIScraper(snscrape.base.Scraper):
|
|||||||
if format not in ('jpg', 'png'):
|
if format not in ('jpg', 'png'):
|
||||||
_logger.warning(f'Skipping photo with unknown format on tweet {tweetId}: {format!r}')
|
_logger.warning(f'Skipping photo with unknown format on tweet {tweetId}: {format!r}')
|
||||||
return
|
return
|
||||||
return Photo(
|
mKwargs = {
|
||||||
previewUrl = f'{baseUrl}?format={format}&name=small',
|
'previewUrl': f'{baseUrl}?format={format}&name=small',
|
||||||
fullUrl = f'{baseUrl}?format={format}&name=large',
|
'fullUrl': f'{baseUrl}?format={format}&name=large',
|
||||||
)
|
}
|
||||||
|
if medium.get('ext_alt_text'):
|
||||||
|
mKwargs['altText'] = medium['ext_alt_text']
|
||||||
|
return Photo(**mKwargs)
|
||||||
elif medium['type'] == 'video' or medium['type'] == 'animated_gif':
|
elif medium['type'] == 'video' or medium['type'] == 'animated_gif':
|
||||||
variants = []
|
variants = []
|
||||||
for variant in medium['video_info']['variants']:
|
for variant in medium['video_info']['variants']:
|
||||||
@@ -970,6 +976,8 @@ class _TwitterAPIScraper(snscrape.base.Scraper):
|
|||||||
cls = Video
|
cls = Video
|
||||||
elif medium['type'] == 'animated_gif':
|
elif medium['type'] == 'animated_gif':
|
||||||
cls = Gif
|
cls = Gif
|
||||||
|
if medium.get('ext_alt_text'):
|
||||||
|
mKwargs['altText'] = medium['ext_alt_text']
|
||||||
return cls(**mKwargs)
|
return cls(**mKwargs)
|
||||||
else:
|
else:
|
||||||
_logger.warning(f'Unsupported medium type on tweet {tweetId}: {medium["type"]!r}')
|
_logger.warning(f'Unsupported medium type on tweet {tweetId}: {medium["type"]!r}')
|
||||||
|
|||||||
Reference in New Issue
Block a user