mirror of
https://github.com/skoobasteeve/useful-scripts.git
synced 2026-03-21 16:08:56 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
935b4d4e8b | ||
|
|
a39903d110 | ||
| 394a92efaa | |||
| d914434618 | |||
| 2217c1d773 | |||
| 8a8cf03861 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1 @@
|
|||||||
.vscode
|
.vscode
|
||||||
__pycache__
|
|
||||||
@@ -45,10 +45,10 @@ folder_encode () {
|
|||||||
FILENAME=$(basename "$FILE")
|
FILENAME=$(basename "$FILE")
|
||||||
if [[ $RES -gt 1920 ]]; then
|
if [[ $RES -gt 1920 ]]; then
|
||||||
echo "File is 4K or higher, encoding using CRF $QUALITY_4K"
|
echo "File is 4K or higher, encoding using CRF $QUALITY_4K"
|
||||||
ffmpeg -i "$FILE" -c:v libx264 -preset slow -tune film -crf "$QUALITY_4K" -maxrate 25M -bufsize 25M -c:a copy "$INPUT_SOURCE"/output/"$FILENAME" || echo "ERROR Line $LINENO: File not encoded, unknown error occurred." 1>&2
|
ffmpeg -i "$FILE" -c:v libx264 -preset slow -tune film -crf "$QUALITY_4K" -c:a copy "$INPUT_SOURCE"/output/"$FILENAME" || echo "ERROR Line $LINENO: File not encoded, unknown error occurred." 1>&2
|
||||||
elif [[ $RES -le 1920 ]] && [[ -n $RES ]]; then
|
elif [[ $RES -le 1920 ]] && [[ -n $RES ]]; then
|
||||||
echo "File is HD or lower, encoding using CRF $QUALITY_HD"
|
echo "File is HD or lower, encoding using CRF $QUALITY_HD"
|
||||||
ffmpeg -i "$FILE" -c:v libx264 -preset slow -tune film -crf "$QUALITY_HD" -maxrate 15M -bufsize 15M -c:a copy "$INPUT_SOURCE"/output/"$FILENAME" || echo "ERROR Line $LINENO: File not encoded, unknown error occurred." 1>&2
|
ffmpeg -i "$FILE" -c:v libx264 -preset slow -tune film -crf "$QUALITY_HD" -c:a copy "$INPUT_SOURCE"/output/"$FILENAME" || echo "ERROR Line $LINENO: File not encoded, unknown error occurred." 1>&2
|
||||||
else
|
else
|
||||||
echo "ERROR Line $LINENO: Source file $FILE is not a valid video file" 1>&2
|
echo "ERROR Line $LINENO: Source file $FILE is not a valid video file" 1>&2
|
||||||
echo "Skipping..."
|
echo "Skipping..."
|
||||||
@@ -67,10 +67,10 @@ file_encode () {
|
|||||||
RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=noprint_wrappers=1:nokey=1 "$INPUT_SOURCE")
|
RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=noprint_wrappers=1:nokey=1 "$INPUT_SOURCE")
|
||||||
if [[ $RES -gt 1920 ]]; then
|
if [[ $RES -gt 1920 ]]; then
|
||||||
echo "File is 4K or higher, encoding using CRF $QUALITY_4K"
|
echo "File is 4K or higher, encoding using CRF $QUALITY_4K"
|
||||||
ffmpeg -i "$INPUT_SOURCE" -c:v libx264 -preset slow -tune film -crf "$QUALITY_4K" -maxrate 25M -bufsize 25M -c:a copy "$FILEDIR"/output/"$FILENAME" || echo "ERROR Line $LINENO: File not encoded, unknown error occurred." 1>&2
|
ffmpeg -i "$INPUT_SOURCE" -c:v libx264 -preset slow -tune film -crf "$QUALITY_4K" -c:a copy "$FILEDIR"/output/"$FILENAME" || echo "ERROR Line $LINENO: File not encoded, unknown error occurred." 1>&2
|
||||||
elif [[ $RES -le 1920 ]] && [[ -n $RES ]]; then
|
elif [[ $RES -le 1920 ]] && [[ -n $RES ]]; then
|
||||||
echo "File is HD or lower, encoding using CRF $QUALITY_HD"
|
echo "File is HD or lower, encoding using CRF $QUALITY_HD"
|
||||||
ffmpeg -i "$INPUT_SOURCE" -c:v libx264 -preset slow -tune film -crf "$QUALITY_HD" -maxrate 15M -bufsize 15M -c:a copy "$FILEDIR"/output/"$FILENAME" || echo "ERROR Line $LINENO: File not encoded, unknown error occurred." 1>&2
|
ffmpeg -i "$INPUT_SOURCE" -c:v libx264 -preset slow -tune film -crf "$QUALITY_HD" -c:a copy "$FILEDIR"/output/"$FILENAME" || echo "ERROR Line $LINENO: File not encoded, unknown error occurred." 1>&2
|
||||||
else
|
else
|
||||||
echo "ERROR Line $LINENO: Source file $INPUT_SOURCE is not a valid video file" 1>&2
|
echo "ERROR Line $LINENO: Source file $INPUT_SOURCE is not a valid video file" 1>&2
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,144 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import requests
|
|
||||||
from datetime import datetime
|
|
||||||
import os
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
|
|
||||||
tmdb_api_token = os.environ.get("TMDB_API_TOKEN")
|
|
||||||
sa_api_token = os.environ.get("SA_API_TOKEN")
|
|
||||||
|
|
||||||
tmdb_url = "https://api.themoviedb.org/3"
|
|
||||||
tmdb_headers = {
|
|
||||||
'Authorization': f'Bearer {tmdb_api_token}',
|
|
||||||
'Content-Type': 'application/json;charset=utf-8',
|
|
||||||
'Accept': 'application/json;charset=utf-8'
|
|
||||||
}
|
|
||||||
|
|
||||||
sa_url = "https://streaming-availability.p.rapidapi.com/get/basic"
|
|
||||||
sa_headers = {
|
|
||||||
'x-rapidapi-host': "streaming-availability.p.rapidapi.com",
|
|
||||||
'x-rapidapi-key': sa_api_token
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# def get_args():
|
|
||||||
# parser = argparse.ArgumentParser(
|
|
||||||
# description='Search movie streaming availability.')
|
|
||||||
|
|
||||||
# parser.add_argument('--year', type=int, help='Specify movie release year')
|
|
||||||
# return parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
def tmdb_lookup(tmdb_url, tmdb_headers, movie):
|
|
||||||
tmdb_params = {
|
|
||||||
"language": "en-US",
|
|
||||||
"query": movie,
|
|
||||||
"page": 1,
|
|
||||||
"include_adult": False
|
|
||||||
}
|
|
||||||
|
|
||||||
# if args.year:
|
|
||||||
# tmdb_params["primary_release_year"] = args.year
|
|
||||||
|
|
||||||
tmdb_search = requests.get(f"{tmdb_url}/search/movie", params=tmdb_params,
|
|
||||||
headers=tmdb_headers).json()
|
|
||||||
|
|
||||||
if not tmdb_search["results"]:
|
|
||||||
print("I'm having trouble finding that movie. " +
|
|
||||||
"Check your spelling and try again.")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
movie_id = tmdb_search['results'][0]['id']
|
|
||||||
movie_title = tmdb_search['results'][0]['title']
|
|
||||||
movie_release_check = tmdb_search['results'][0]['release_date']
|
|
||||||
|
|
||||||
if movie_release_check:
|
|
||||||
movie_release = datetime.strptime(
|
|
||||||
tmdb_search['results'][0]['release_date'], "%Y-%m-%d")
|
|
||||||
movie_year = movie_release.year
|
|
||||||
else:
|
|
||||||
movie_year = "???"
|
|
||||||
|
|
||||||
movie_rating = tmdb_search['results'][0]['vote_average']
|
|
||||||
|
|
||||||
return movie_id, movie_title, movie_year, movie_rating
|
|
||||||
|
|
||||||
|
|
||||||
def sa_lookup(sa_url, sa_headers, movie_id):
|
|
||||||
sa_params = {
|
|
||||||
"country": "us",
|
|
||||||
"tmdb_id": f"movie/{movie_id}",
|
|
||||||
"output_language": "en"
|
|
||||||
}
|
|
||||||
|
|
||||||
sa_request = requests.request("GET", sa_url, headers=sa_headers,
|
|
||||||
params=sa_params)
|
|
||||||
|
|
||||||
if sa_request.status_code == 404:
|
|
||||||
print("I'm having trouble finding that movie on streaming. " +
|
|
||||||
"Check your spelling and try again.")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
sa_response = sa_request.json()
|
|
||||||
services = sa_response["streamingInfo"]
|
|
||||||
|
|
||||||
return sa_response, services
|
|
||||||
|
|
||||||
|
|
||||||
def services_speller(service):
|
|
||||||
if service == "hbo":
|
|
||||||
service_proper = "HBO Max"
|
|
||||||
elif service == "hulu":
|
|
||||||
service_proper = "Hulu"
|
|
||||||
elif service == "prime":
|
|
||||||
service_proper = "Amazon Prime"
|
|
||||||
elif service == "netflix":
|
|
||||||
service_proper = "Netflix"
|
|
||||||
elif service == "disney":
|
|
||||||
service_proper = "Disney+"
|
|
||||||
elif service == "apple":
|
|
||||||
service_proper = "Apple TV+"
|
|
||||||
elif service == "paramount":
|
|
||||||
service_proper = "Paramount+"
|
|
||||||
elif service == "starz":
|
|
||||||
service_proper = "STARZ"
|
|
||||||
elif service == "showtime":
|
|
||||||
service_proper = "Showtime"
|
|
||||||
else:
|
|
||||||
return service
|
|
||||||
return service_proper
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
|
|
||||||
#args = get_args()
|
|
||||||
#movie = input("Enter a movie: ")
|
|
||||||
|
|
||||||
movie_id, movie_title, movie_release, movie_rating = tmdb_lookup(
|
|
||||||
tmdb_url, tmdb_headers, movie, args)
|
|
||||||
|
|
||||||
print(f"\n{movie_title} ({movie_release})")
|
|
||||||
print(f"https://themoviedb.org/movie/{movie_id}")
|
|
||||||
print(f"Rating: {movie_rating}\n")
|
|
||||||
|
|
||||||
sa_response, services = sa_lookup(sa_url, sa_headers, movie_id)
|
|
||||||
|
|
||||||
if not services:
|
|
||||||
print("Streaming not available :(")
|
|
||||||
|
|
||||||
for s in services:
|
|
||||||
leaving_epoch = sa_response["streamingInfo"][s]["us"]["leaving"]
|
|
||||||
leaving_date = datetime.fromtimestamp(
|
|
||||||
int(leaving_epoch)).strftime('%Y-%m-%d')
|
|
||||||
link = sa_response["streamingInfo"][s]["us"]["link"]
|
|
||||||
|
|
||||||
print(f"Available on {services_speller(s)}")
|
|
||||||
|
|
||||||
if leaving_epoch != 0:
|
|
||||||
print(f"Will be leaving on {leaving_date}")
|
|
||||||
|
|
||||||
print(f"Watch here: {link}\n")
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
from telegram.ext import Updater, CommandHandler, CallbackContext, MessageHandler, Filters
|
|
||||||
import logging
|
|
||||||
from telegram import Update
|
|
||||||
import os
|
|
||||||
from datetime import datetime
|
|
||||||
import movie_check
|
|
||||||
|
|
||||||
tmdb_api_token = os.environ.get("TMDB_API_TOKEN")
|
|
||||||
sa_api_token = os.environ.get("SA_API_TOKEN")
|
|
||||||
|
|
||||||
tmdb_url = "https://api.themoviedb.org/3"
|
|
||||||
tmdb_headers = {
|
|
||||||
'Authorization': f'Bearer {tmdb_api_token}',
|
|
||||||
'Content-Type': 'application/json;charset=utf-8',
|
|
||||||
'Accept': 'application/json;charset=utf-8'
|
|
||||||
}
|
|
||||||
|
|
||||||
sa_url = "https://streaming-availability.p.rapidapi.com/get/basic"
|
|
||||||
sa_headers = {
|
|
||||||
'x-rapidapi-host': "streaming-availability.p.rapidapi.com",
|
|
||||||
'x-rapidapi-key': sa_api_token
|
|
||||||
}
|
|
||||||
|
|
||||||
bot_token = os.environ.get("TG_BOT_TOKEN")
|
|
||||||
|
|
||||||
updater = Updater(token=bot_token, use_context=True)
|
|
||||||
dispatcher = updater.dispatcher
|
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
||||||
level=logging.INFO)
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# def start(update: Update, context: CallbackContext):
|
|
||||||
# context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
|
|
||||||
|
|
||||||
|
|
||||||
# def echo(update: Update, context: CallbackContext):
|
|
||||||
# context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
|
|
||||||
|
|
||||||
|
|
||||||
def movie_lookup(movie):
|
|
||||||
logger.info('movie check started')
|
|
||||||
movie_id, movie_title, movie_year, movie_rating = movie_check.tmdb_lookup(tmdb_url, tmdb_headers, movie)
|
|
||||||
sa_response, services = movie_check.sa_lookup(sa_url, sa_headers, movie_id)
|
|
||||||
tg_reply = f"{movie_title} ({movie_year})\nhttps://themoviedb.org/movie/{movie_id}\nRating: {movie_rating}"
|
|
||||||
|
|
||||||
if not services:
|
|
||||||
tg_reply = tg_reply + "\n\nStreaming not available :("
|
|
||||||
else:
|
|
||||||
for s in services:
|
|
||||||
leaving_epoch = sa_response["streamingInfo"][s]["us"]["leaving"]
|
|
||||||
leaving_date = datetime.fromtimestamp(
|
|
||||||
int(leaving_epoch)).strftime('%Y-%m-%d')
|
|
||||||
link = sa_response["streamingInfo"][s]["us"]["link"]
|
|
||||||
|
|
||||||
s_pretty = movie_check.services_speller(s)
|
|
||||||
tg_reply = tg_reply + f"\n\nAvailable on {s_pretty}"
|
|
||||||
|
|
||||||
if leaving_epoch != 0:
|
|
||||||
tg_reply = tg_reply + f"Will be leaving on {leaving_date}"
|
|
||||||
|
|
||||||
tg_reply = tg_reply + f"\nWatch here: {link}"
|
|
||||||
return tg_reply
|
|
||||||
|
|
||||||
|
|
||||||
# def input_movie(update: Update, context: CallbackContext):
|
|
||||||
# movie = ' '.join(context.args)
|
|
||||||
# # logger.info(movie)
|
|
||||||
# # movie_info = movie_lookup(movie)
|
|
||||||
# context.bot.send_message(chat_id=update.effective_chat.id, text=movie)
|
|
||||||
|
|
||||||
def echo(update: Update, context: CallbackContext):
|
|
||||||
movie = update.message.text
|
|
||||||
movie_info = movie_lookup(movie)
|
|
||||||
context.bot.send_message(chat_id=update.effective_chat.id, text=movie_info)
|
|
||||||
|
|
||||||
def unknown(update: Update, context: CallbackContext):
|
|
||||||
context.bot.send_message(chat_id=update.effective_chat.id, text="Sorry, I didn't understand that command.")
|
|
||||||
|
|
||||||
|
|
||||||
# start_handler = CommandHandler('start', start)
|
|
||||||
# dispatcher.add_handler(start_handler)
|
|
||||||
|
|
||||||
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
|
|
||||||
dispatcher.add_handler(echo_handler)
|
|
||||||
|
|
||||||
# movie_handler = CommandHandler('input_movie', input_movie)
|
|
||||||
# dispatcher.add_handler(movie_handler)
|
|
||||||
|
|
||||||
unknown_handler = MessageHandler(Filters.command, unknown)
|
|
||||||
dispatcher.add_handler(unknown_handler)
|
|
||||||
|
|
||||||
|
|
||||||
updater.start_polling()
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user