This commit is contained in:
jeancf 2023-10-31 16:05:20 +01:00
parent 7e92516f3b
commit d8e2c9fcee

View File

@ -658,7 +658,7 @@ def get_timeline(session, nitter_url):
# Download twitter page of user # Download twitter page of user
try: try:
twit_account_page = session.get(url, headers=headers, timeout=HTTPS_REQ_TIMEOUT) twit_account_page = session.get(url, timeout=HTTPS_REQ_TIMEOUT)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
logging.fatal('Host did not respond when trying to download ' + url) logging.fatal('Host did not respond when trying to download ' + url)
shutdown(-1) shutdown(-1)
@ -877,8 +877,20 @@ def process_attachments(nitter_url, attachments_container, status_id, author_acc
with open('gif_video.mp4', 'wb') as f: with open('gif_video.mp4', 'wb') as f:
for chunk in r.iter_content(chunk_size=16 * 1024): for chunk in r.iter_content(chunk_size=16 * 1024):
f.write(chunk) f.write(chunk)
# Initiate session
session = requests.Session()
logging.debug('Downloaded video of GIF animation from attachments') # Get a copy of the default headers that requests would use
headers = requests.utils.default_headers()
# Update default headers with randomly selected user agent
headers.update(
{
'User-Agent': USER_AGENTS[random.randint(0, len(USER_AGENTS) - 1)],
'Cookie': 'replaceTwitter=; replaceYouTube=; hlsPlayback=on; proxyVideos=',
}
)
ded video of GIF animation from attachments')
except: # Don't do anything if video can't be found or downloaded except: # Don't do anything if video can't be found or downloaded
logging.debug('Could not download video of GIF animation from attachments') logging.debug('Could not download video of GIF animation from attachments')
pass pass
@ -918,8 +930,20 @@ def process_attachments(nitter_url, attachments_container, status_id, author_acc
logging.debug("Media is unavailable") logging.debug("Media is unavailable")
vid_in_tweet = True vid_in_tweet = True
else: else:
logging.debug("Media is unavailable") logging.debug("Media i # Initiate session
vid_in_tweet = True session = requests.Session()
# Get a copy of the default headers that requests would use
headers = requests.utils.default_headers()
# Update default headers with randomly selected user agent
headers.update(
{
'User-Agent': USER_AGENTS[random.randint(0, len(USER_AGENTS) - 1)],
'Cookie': 'replaceTwitter=; replaceYouTube=; hlsPlayback=on; proxyVideos=',
}
)
return pics, vid_in_tweet return pics, vid_in_tweet