marvinpinto.htpc
htpc
这是一个 Ansible Galaxy 的元角色,用于安装和管理示例家庭影院电脑 (HTPC) 设置。
此项目的目标是演示如何使用 Ansible 连接 HTPC 设置所需的组件。将所有部分连接在一起一直是最困难的部分,所以希望这能简化过程。
功能
- SABnzbd 二进制新闻组下载器
- SickRage 电视节目的视频库管理器
- CouchPotato PVR 和电影视频库管理器
- Plex 电影、电视节目、音乐等的媒体服务器
- nginx 带有 Google 身份验证的前端代理(通过 OAuth2 Proxy)
- 所有组件设计在 Ubuntu 14.04 服务器上连接在一起
前提条件
你需要一个域名来托管该设置 - 本示例使用
htpc-sample.example.org
。请将htpc_dns_hostname
变量更新为你的域名。默认设置使用 Google 身份验证,因此你需要注册一个 OAuth Web 应用(说明 在这里)并记录 客户端 ID 和 _客户端密钥_。(相应的变量为
htpc_oauth_client_id
和htpc_oauth_client_secret
)你不局限于使用 Google 身份验证提供者,还有 其他有效选项!如果你选择其他提供者,记得调整
oauth2_proxy_cli_args
变量。使用以下命令生成一个随机的 32 字节字符串:
$ date +%s | sha256sum | base64 | head -c 32 ; echo
将此值作为你的
htpc_oauth_cookie_secret
。为你选择的域名 (
htpc_dns_hostname
) 获取一个 https TLS 证书。使用你的证书和私钥更新htpc_tls_cert
和htpc_tls_cert_key
变量(分别)。
角色变量
htpc
特定的角色变量均在 defaults/main.yml 中指定,而角色特定的元变量在 meta/main.yml 中。
示例
从 Ansible Galaxy 安装此模块到 './roles' 目录:
ansible-galaxy install marvinpinto.htpc -p ./roles
在剧本中使用,如下所示:
- hosts: '127.0.0.1'
become: true
roles:
- role: 'marvinpinto.htpc'
htpc_dns_hostname: 'htpc-sample.example.org'
htpc_oauth_client_id: '你的客户端 ID'
htpc_oauth_client_secret: '你的客户端密钥'
htpc_oauth_cookie_secret: 'N2U2NTI0NzljNjc2Y2VmNGVlZDZmMDg5'
htpc_authorized_users_emails: |
[email protected]
[email protected]
htpc_tls_cert: |
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
htpc_tls_cert_key: |
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
后配置设置
SABnzbd
在浏览器中访问
/sabnzbd
,并按照初始向导设置。在
/sabnzbd/config/general/
中,建议 禁用 API 密钥 (在 OAuth2 Proxy 后运行时不需要)。在
/sabnzbd/config/folders/
中:
- 临时下载文件夹:
/opt/downloads/sabnzbd-incomplete
- 完成下载文件夹:
/opt/downloads/misc
- 完成下载的权限:
777
- 脚本文件夹:
/opt/nzbtomedia
- 在
/sabnzbd/config/categories/
中:
电影处理:
- 类别:
movies
- 脚本:
nzbToCouchPotato.py
- 文件夹/路径:
/opt/downloads/unprocessed/movies
- 类别:
电视处理:
- 类别:
tv
- 脚本:
nzbToSickBeard.py
- 文件夹/路径:
/opt/downloads/tv
- 类别:
音频处理:
- 类别:
audio
- 脚本:
nzbToHeadPhones.py
- 文件夹/路径:
/opt/downloads/unprocessed/audio
- 类别:
- 在
/sabnzbd/config/switches/
中:
- 下载加密 RAR 时的操作:
abort
- 当检测到不需要的扩展时的操作:
abort
- 不需要的扩展名:
exe, com
- 仅对已验证的作业进行后处理:
off
- 忽略样本:
on
- 清理列表:
nfo, sfv
- 在
/sabnzbd/config/special/
中:
empty_postproc
:on
SickRage
- 停止 SickRage 服务:
$ service sickrage stop
- 允许 nginx 将请求代理到 SickRage
$ sed -i 's/^web_root = ""/web_root = \/sickrage/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^handle_reverse_proxy = 0/handle_reverse_proxy = 1/g' /opt/config/sickrage-config/config.ini
- 其他 SickRage 设置
$ sed -i 's/^use_failed_downloads = 0/use_failed_downloads = 1/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^log_nr = 5/log_nr = 1/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^auto_update =.*/auto_update = 0/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^version_notify =.*/version_notify = 0/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^naming_pattern =.*/naming_pattern = %S.N.S%0SE%0E.%E.N/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^web_host =.*/web_host = 127.0.0.1/g' /opt/config/sickrage-config/config.ini
- 启动 SickRage 服务:
$ service sickrage start
CouchPotato
- 停止 CouchPotato 服务:
$ service couchpotato stop
- 允许 nginx 将请求代理到 CouchPotato
$ sed -i 's/^url_base =.*/url_base = \/couchpotato/g' /opt/config/couchpotato-config/settings.conf
$ sed -i 's/^show_wizard =.*/show_wizard = 0/g' /opt/config/couchpotato-config/settings.conf
- 在
/opt/config/couchpotato-config/settings.conf
的[core]
部分添加以下键/值
host = 127.0.0.1
- 启动 CouchPotato 服务:
$ service couchpotato start
在浏览器中访问
/couchpotato/settings/general
并禁用周期性更新检查。在
/couchpotato/settings/renamer
中:
- 重命名已下载的电影:
启用
- 每次运行:
0
- 从:
/opt/downloads/unprocessed/movies
- 到:
/opt/downloads/movies
- 强制每次:
24
- 清理:
启用
- 失败后的下一个:
禁用
- 记下你的 API 密钥,并使用此值更新
htpc_couchpotato_api_key
变量
- 在
/couchpotato/settings/downloaders
中:
- Sabnzbd:
启用
- 主机:
127.0.0.1:8080
- 类别:
movies
- 删除 NZB:
启用
- 删除失败:
启用
Plex 媒体服务器
由于 Plex 只允许从本地子网发起管理操作,因此你需要为初始设置创建通往主机的 SSH 隧道。请注意,这 仅在初始设置时需要。
https://support.plex.tv/hc/en-us/articles/200288586-Installation
此 SSH 命令的一般形式如下:
ssh ip.address.of.server -L 8888:localhost:32400
然后访问 http://localhost:8888/web 可以配置你的 Plex 应用。
在 vagrant 环境中,该 ssh 命令如下:
ssh \
-p <Port> \
-i <IdentityFile> \
-L 8888:localhost:32400 \
<User>@<HostName>
其中 Port
,IdentityFile
,User
和 HostName
可以通过运行以下命令找到:
vagrant ssh-config
有关更多信息,请参阅 Plex 安装文档。
Headphones
- 停止 Headphones 服务:
$ service headphones stop
- 允许 nginx 将请求代理到 Headphones
sed -i 's/^http_root =.*/http_root = \/headphones/g' /opt/config/headphones-config/config.ini
sed -i 's/^http_host =.*/http_host = 127.0.0.1/g' /opt/config/headphones-config/config.ini
- 其他配置选项
sed -i 's/^music_encoder =.*/music_encoder = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^preferred_quality =.*/preferred_quality = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^rename_files =.*/rename_files = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^folder_format =.*/folder_format = $Type/$Artist/$Album [$Year]/g' /opt/config/headphones-config/config.ini
sed -i 's/^move_files =.*/move_files = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^cleanup_files =.*/cleanup_files = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^embed_album_art =.*/embed_album_art = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^destination_dir =.*/destination_dir = \/opt\/downloads\/audio/g' /opt/config/headphones-config/config.ini
sed -i 's/^download_dir =.*/download_dir = \/opt\/downloads\/unprocessed\/audio/g' /opt/config/headphones-config/config.ini
sed -i 's/^launch_browser =.*/launch_browser = 0/g' /opt/config/headphones-config/config.ini
sed -i 's/^api_key =.*/api_key = YOURAPIKEY/g' /opt/config/headphones-config/config.ini
sed -i 's/^encoder_multicore =.*/encoder_multicore = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^api_enabled =.*/api_enabled = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^correct_metadata =.*/correct_metadata = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^encoder =.*/encoder = libav/g' /opt/config/headphones-config/config.ini
sed -i 's/^download_scan_interval =.*/download_scan_interval = 0/g' /opt/config/headphones-config/config.ini
sed -i 's/^bitrate =.*/bitrate = 256/g' /opt/config/headphones-config/config.ini
sed -i 's/^wait_until_release_date =.*/wait_until_release_date = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^embed_lyrics =.*/embed_lyrics = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^encoderoutputformat =.*/encoderoutputformat = m4a/g' /opt/config/headphones-config/config.ini
sed -i 's/^sab_host =.*/sab_host = http:\/\/127.0.0.1:8080/g' /opt/config/headphones-config/config.ini
sed -i 's/^sab_category =.*/sab_category = audio/g' /opt/config/headphones-config/config.ini
sed -i 's/^sab_apikey =.*/sab_apikey = sabapi1234/g' /opt/config/headphones-config/config.ini
sed -i 's/^songkick_enabled =.*/songkick_enabled = 0/g' /opt/config/headphones-config/config.ini
sed -i 's/^log_dir =.*/log_dir = \/opt\/config\/headphones-config\/logs/g' /opt/config/headphones-config/config.ini
sed -i 's/^include_extras =.*/include_extras = 1/g' /opt/config/headphones-config/config.ini
sed -i 's/^extras =.*/extras = 8/g' /opt/config/headphones-config/config.ini
- 启动 Headphones 服务:
$ service headphones start
开发
使用提供的 Vagrantfile
进行本地开发和测试。
$ vagrant up --provision
This is an Ansible Galaxy meta-role of sorts to install and manage a sample Home Theatre PC (HTPC) setup.
ansible-galaxy install marvinpinto.htpc