前置环境
Debian12
Emby为Linux直装版,非docker安装
本脚本基于python运行,python3版本为python3.11,此外请确保机器可以连通telegram。
安装 Emby Scripter-X插件
在embyserver插件库中搜索并安装
在/root/notify
路径下新建EmbyPush.py
文件,并填入以下代码:
# -*- coding: utf-8 -*-
"""
@author: Monster
@software: PyCharm
@file: EmbyPush.py
@time: 2022/09/11 0:07
@fix: 23/02/16 by@suenley
"""
import json
import telebot
import requests
import sys
import os
import random
import re
#os.environ["http_proxy"] = "http://127.0.0.1:7890"
#os.environ["https_proxy"] = "http://127.0.0.1:7890"
"""播放电影
电影入库
"%item.name%" "%item.productionyear%" "%item.meta.tmdb%" "%item.meta.overview%"
电视剧入库
"%series.name%" "%season.number%" "%episode.number%" "%series.meta.tmdb%"
"""
TG_TOKEN = "M" # bot的api
TG_CHAT_ID = "" # 你的群组id
TG_CHAT_ID2 = "" # 你的群组id
TMDB_API_KEY = "" # tmdb的api
default_pic = "/root/notify/安全屋.png" # 这里填写默认图片的url,如果tmdb没有查询到图片封面就会使用默认图片
args = sys.argv
bot = telebot.TeleBot(TG_TOKEN, parse_mode='HTML')
def push_tv_telegram(season, episode, image_url, title, original_name, original_language, release_date, genres, overview):
if bool(re.search(r'\d', episode)) is False:
sys.exit()
season = season.zfill(2)
episode = episode.zfill(2)
payload = f"🎉🎉 <b>安全屋 更新啦</b> 🎉🎉\n--------------------------------\n#剧集\n📺 <u>中文片名</u>: <code>{title}</code>\n🌏 <u>原始片名</u>: <code>{original_name}</code>\n⌛ <u>季集</u>: S{season}E{episode}\n🌐 <u>原始语言</u>: {original_language}\n📅 <u>发行年份</u>: {release_date}"
if len(genres) != 0:
genres_str = '、'.join(genres)
genres_in = "\n🚩 <u>类型</u>:" + genres_str
payload += genres_in
if len(overview) != 0:
overview = "\n💬 <u>简介</u>:\n" + overview
payload += overview
img_content = requests.get(image_url).content
bot.send_photo(chat_id=TG_CHAT_ID, photo=img_content, caption=payload)
# bot.send_photo(chat_id=TG_CHAT_ID2, photo=img_content, caption=payload)
def push_movie_telegram(image_url, zh_title, original_title, original_language, release_date, genres, overview):
payload = f"🎉🎉 <b>安全屋 更新啦</b> 🎉🎉\n--------------------------------\n#电影\n🎥 <u>中文片名</u>: <code>{zh_title}</code>\n🌏 <u>原始片名</u>: <code>{original_title}</code>\n🌐 <u>原始语言</u>: {original_language}\n📅 <u>发行年份</u>: {release_date}"
if len(genres) != 0:
genres_str = '、'.join(genres)
genres_in = "\n🚩 <u>类型</u>:" + genres_str
payload += genres_in
if len(overview) != 0:
overview = "\n💬 <u>简介</u>:\n" + overview
payload += overview
img_content = requests.get(image_url).content
bot.send_photo(chat_id=TG_CHAT_ID, photo=img_content, caption=payload)
# bot.send_photo(chat_id=TG_CHAT_ID2, photo=img_content, caption=payload)
def get_movie_info(tmdb_id):
tmdb_img_url = f"https://api.themoviedb.org/3/movie/{tmdb_id}/images?api_key={TMDB_API_KEY}"
tmdb_info_url = f"https://api.themoviedb.org/3/movie/{tmdb_id}?api_key={TMDB_API_KEY}&language=zh-CN"
imgres = requests.get(tmdb_img_url).json()
infores = requests.get(tmdb_info_url).json()
# 获取电影中文名、原产地片名、原始语言、年份、流派、简介
zh_title = infores.get('title')
original_title = infores.get('original_title')
original_language = infores.get('original_language')
release_date = infores.get('release_date')[:4]
genres = [genre.get('name') for genre in infores.get('genres')]
overview = infores.get('overview')
try:
img_path = imgres['backdrops'][0]['file_path']
image_url = f"http://image.tmdb.org/t/p/original{img_path}"
except:
image_url = default_pic
return image_url, zh_title, original_title, original_language, release_date, genres, overview
def get_tv_info(tmdb_id):
tmdb_img_url = f"https://api.themoviedb.org/3/tv/{tmdb_id}/images?api_key={TMDB_API_KEY}"
tmdb_info_url = f"https://api.themoviedb.org/3/tv/{tmdb_id}?api_key={TMDB_API_KEY}&language=zh-CN"
imgres = requests.get(tmdb_img_url).json()
infores = requests.get(tmdb_info_url).json()
title = infores.get('name') # 中文片名
original_name = infores.get('original_name') # 原产地片名
original_language = infores.get('original_language') # 原始语言
release_date = infores.get('first_air_date')[:4] # 年份
genres = [genre.get('name') for genre in infores.get('genres')] # 流派
overview = infores['overview'] # 简介
id = random.randint(0, 3)
try:
try:
img_path = imgres['backdrops'][id]['file_path']
except:
try:
img_path = imgres['backdrops'][0]['file_path']
except:
img_path = imgres['posters'][0]['file_path']
image_url = f"http://image.tmdb.org/t/p/original{img_path}"
except:
image_url = default_pic
return image_url, title, original_name, original_language, release_date, genres, overview
if __name__ == '__main__':
try:
if args[2]:
tmdb_id = args[2]
if args[1] == 'movie':
image_url, zh_title, original_title, original_language, release_date, genres, overview = get_movie_info(tmdb_id)
# print(image_url, zh_title, original_title, original_language, release_date, genres, overview)
push_movie_telegram(image_url, zh_title, original_title, original_language, release_date, genres, overview)
if args[1] == 'tv':
season = args[3]
episode = args[4]
image_url, title, original_name, original_language, release_date, genres, overview = get_tv_info(tmdb_id)
push_tv_telegram(season, episode, image_url, title, original_name, original_language, release_date, genres, overview)
except:
print(f'未提供有效参数!\n示例: \npython EmbyPush.py [movie] [tmdbID]\npython EmbyPush.py [tv] [tmdbID] [S] [E]\n当前参数如下:\n{args}')
exit()
安装必要环境,在服务器终端输入
pip install telebot
[!warning]#os.environ["http_proxy"] = "http://127.0.0.1:7890"
#os.environ["https_proxy"] = "http://127.0.0.1:7890"
以上为代理环境,国内机需要取消注释并设置为自己的代理网络,国外机注释掉即可。
按照要求填写bottoken,频道、群组ID和tmdb api后,
终端执行python3 /root/notify/EmbyPush.py tv 235195 1 17
验证是否能接收到消息通知。
设置插件
进入插件设置页面,找到On Media Item Added Complete
添加如下内容:
/root/notify/EmbyPush.py movie
/usr/bin/python3
%item.meta.tmdb*%
/root/notify/EmbyPush.py tv
/usr/bin/python3
"%series.meta.tmdb%" "%season.number%" "%episode.number%"
完整版如下图:
[!tip]
填 where 那里注意下, 不是手填, 也不是点选,是从上面拖到下面横杠那里
至此大功告成,enjoy~