Calling twitterdl.py as subprocess

This commit is contained in:
JC Francois 2020-03-29 13:41:49 +02:00
parent 2090d214b6
commit 6fa2019618
2 changed files with 9 additions and 6 deletions

1
twitterdl.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#! /usr/bin/env python3
import argparse import argparse
import requests import requests

View File

@ -29,7 +29,7 @@ import datetime, time
import re import re
from pathlib import Path from pathlib import Path
from mastodon import Mastodon, MastodonError, MastodonAPIError, MastodonIllegalArgumentError from mastodon import Mastodon, MastodonError, MastodonAPIError, MastodonIllegalArgumentError
import twitterdl import subprocess
import json.decoder import json.decoder
import shutil import shutil
@ -128,12 +128,14 @@ def cleanup_tweet_text(tt_iter, tweet_uri, get_vids):
if get_vids: if get_vids:
# Download video from twitter and store in filesystem # Download video from twitter and store in filesystem
# TODO set output location to ./output/twit_account # TODO set output location to ./output/twit_account
twitter_dl = twitterdl.TwitterDownloader(tweet_uri, target_width=500)
try: try:
twitter_dl.download() dl_feedback = subprocess.run(["./twitterdl.py", tweet_uri, "-w 500"], capture_output=True)
except json.JSONDecodeError: if dl_feedback.returncode != 0:
print("ERROR: Could not get playlist") # TODO Log dl_feedback.stderr
tweet_text += '\n\n[Video embedded in original tweet]' tweet_text += '\n\n[Video embedded in original tweet]'
except OSError:
print("Could not execute twitterdl.py (is it there? Is it set as executable?)")
sys.exit(-1)
else: else:
tweet_text += '\n\n[Video embedded in original tweet]' tweet_text += '\n\n[Video embedded in original tweet]'