comparison kmbscreens/kmbscreens.py @ 116:205fc01d5eb4

kmbscreens: replace bat+c with py committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Sat, 04 Feb 2023 13:46:06 -0500
parents
children a0f8c92d46db
comparison
equal deleted inserted replaced
115:f10492e8720b 116:205fc01d5eb4
1 import os
2 import tweepy
3 import json
4 import glob
5 import subprocess
6 import random
7 API_KEY = "API_KEY"
8 API_KEY_SECRET = "API_KEY_SECRET"
9 access_tokens = []
10 if os.path.exists("./credentials.json"):
11 with open("credentials.json", "r") as f:
12 access_tokens = json.load(f)
13
14 oauth1_user_handler = None
15 try:
16 oauth1_user_handler = tweepy.OAuth1UserHandler(
17 API_KEY, API_KEY_SECRET,
18 access_tokens[0], access_tokens[1],
19 callback="oob"
20 )
21 except IndexError:
22 oauth1_user_handler = tweepy.OAuth1UserHandler(
23 API_KEY, API_KEY_SECRET,
24 callback="oob"
25 )
26
27 if not access_tokens:
28 print(oauth1_user_handler.get_authorization_url())
29 pin = input("Input PIN: ")
30 access_tokens.extend(oauth1_user_handler.get_access_token(pin))
31 with open("credentials.json", "w") as f:
32 json.dump(access_tokens, f)
33
34 episode = random.choice(list(glob.glob("D:\\Movies\\Anime\\Kill Me Baby\\*.mkv")))
35 result = subprocess.run(["ffprobe.exe", "-v", "quiet", "-of", "csv=p=0",
36 "-show_entries", "format=duration", episode],
37 capture_output=True, text=True)
38 test = random.randint(0, round(float(result.stdout.strip())))
39 result = subprocess.run(["ffmpeg.exe", "-hide_banner", "-loglevel",
40 "warning", "-i", episode, "-y", "-frames:v", "1",
41 "-ss", str(test), "screencap.jpg"])
42
43 api = tweepy.API(oauth1_user_handler)
44 with open("screencap.jpg", "rb") as f:
45 media = api.media_upload(None, file=f)
46 api.update_status("", media_ids=[media.media_id_string])