pyTivo on AsusWRT Merlin Router ‐ How To Guide - XIYO/asuswrt-merlin.ng-kr GitHub Wiki
고지사항
본 가이드에 제시된 솔루션과 의견은 저자 (latenitetech)의 것입니다. 다른 누군가가 이 특정 위키 문서를 편집할 때까지는 해당합니다. 이 문서는 RMerlin이나 권한을 가진 다른 사람에 의해 승인되지 않았으며, 주로 다른 초보자들이 이 놀라운 소프트웨어 모음을 최대한 활용할 수 있도록 돕기 위해 제공되었습니다. 자기 책임 하에 사용하거나, 이것이 너무 어려운 것으로 여기면 다른 곳으로 이동하십시오.
소개
pyTivo는 Tivo 장치를 위한 미디어 서버입니다. 자세한 내용은 여기에서 확인할 수 있습니다: pyTivo 공식 웹사이트
루터에서 실행되며 "항상 켜져 있는" 가용성은 대부분의 시간 동안 전력을 낭비하는 PC 기반 미디어 서버 (200+ 와트 소비) 대안으로 좋은 선택입니다. 루터에서 실행되는 pyTivo는 음악 및/또는 이미지 (사진) 서버로 가장 적합합니다. 비디오 파일을 제공할 수도 있지만 Tivo 장치에서 이미 "재생 준비"로 인코딩된 경우가 가장 좋습니다. pyTivo는 ffmpeg를 통해 변환을 지원하지만 루터의 제한된 처리 능력 때문에 비교적 만족스럽지 않을 수 있습니다. 비디오 라이브러리에서 실시간 변환이 필요한 경우 PC 기반 pyTivo 설치가 가장 적합합니다. 따라서 우리 집에서는 루터에서 음악을 제공하기 위해 pyTivo를 사용하고 (항상 켜져 있고 항상 사용 가능), 그런 다음 (전기를 절약하기 위해 그렇지 않은 경우) 크게 더 큰 비디오 라이브러리를 제공하기 위해 PC 기반 pyTivo 설치를 깨우칩니다. 고유한 이름을 가진 공유가 있는 한 pyTivo의 두 인스턴스는 문제없이 동시에 존재하고 실행될 수 있습니다.
내 Asus 루터에서는 pyTivo와 minidlna가 모두 실행되며 루터에 장착된 대형 플래시 드라이브에 설치된 동일한 미디어 라이브러리를 제공합니다. 이것들은 서로 다른 클라이언트에 서버로 작동합니다: pyTivo는 Tivo 박스에, minidlna는 DLNA 플레이어에. 내 가정에는 둘 다 있습니다.
minidlna를 자세히 살펴보면 이것도 Tivo를 지원한다는 것을 알 수 있을 것입니다 (구성 옵션 enable_tivo=yes/no). 그렇습니다 (실제로 작동하는 편이며 특히 오래된 Tivo 모델에서 작동합니다). 이 공간에서 minidlna와 관련된 문제는 다음과 같습니다:
- 장기간에 걸쳐 Tivo는 LAN 통신에 대해 두 가지 다른 방법을 사용했습니다. 원래의 디자인인 _Tivo Beacon_은 독점적인 브로드캐스트 메커니즘이었습니다. minidlna가 Tivo 지원이 활성화되면 이것을 사용합니다. 이것은 여전히 Premiere 및 이전 모델에서 작동합니다.
- 그런 다음 Tivo는 산업 표준 zeroconf 메커니즘으로 이동했습니다. zeroconf는 Apple 세계에서는 Bonjour 및 _Rendezvous_로도 알려져 있으며 Linux 세계에서는 _Avahi_로 알려져 있습니다. 현재 Roamio 및 Bolt 모델에서 Tivo는 zeroconf를 필요로 합니다. 그 이유로 minidlna는 현재의 Tivo 모델과 호환되지 않습니다.
- pyTivo는 Tivo Beacon 및 ZeroConf 통신 프로토콜을 모두 지원하므로 모든 Tivo 모델에서 작동합니다.
- 마지막으로 Premiere 또는 이전 Tivo 모델만 사용하는 경우에도 pyTivo는 minidlna보다 더 견고한 사용자 인터페이스와 더 많은 구성 옵션을 제공합니다.
pyTivo 설치는 상당히 간단합니다. 이것은 해석 언어 인 파이썬으로 작성되었으므로 네이티브 컴파일이 필요하지 않습니다. 다행히 Entware를 통해 쉽게 사용할 수 있는 파이썬 인터프리터가 필요합니다. 또한 Entware를 통해 사용할 수 있는 ffmpg를 설치하는 것이 강력하게 권장됩니다. 따라서 기본적으로 소프트웨어 구성 요소를 설치하고 라우터에서 몇 가지 간단한 구성 변경을 수행한 다음 실행할 수 있습니다.
Zeroconf (기술적 배경 - 필요하면 건너뛸 수 있습니다)
Zeroconf 프로토콜은 멀티캐스트 DNS (mDNS)를 활용하며, 특히 멀티캐스트 주소 공간 224.0.0.0을 사용합니다. 그러나 라우터의 기본 라우팅 테이블을 살펴보면 (라우터의 route 명령), AsusWRT 펌웨어는 이 mDNS 브로드캐스트 트래픽에 대한 기본 경로를 제공하지 않습니다 (이것은 라우터의 기본 역할을 수행하는 데 필요하지 않기 때문에 합리적입니다). 그러나 기본 설정에서 현재 세대의 zeroconf에 의존하는 Tivo 박스와 함께 pyTivo가 작동하지 않게됩니다. (예전 Tivo에서 _Tivo Beacon_을 사용하는 경우에는 문제 없이 작동합니다.) 이 문제를 해결하려면 웹 검색과 실험을 많이 해야 했지만, 이 문제가 무엇을 의미하는지 설명하는 글을 찾은 후에는 수정이 매우 쉬웠습니다. 라우팅 테이블에 한 줄의 경로를 추가하기만 하면 됩니다. 이것은 '단계별' 섹션에서 아래에서 볼 수 있습니다.
Step by Step
- Prerequisites:
- A Linux filesystem in which you've installed entware and a swap file (the latter isn't critical, but python does consume a bit of memory)
- You have sh (command line) access to the router via telnet or ssh.
-
Via a telnet or ssh prompt, install python, ffmpeg. and pgrep through entware:
opkg install python opkg install ffmpeg opkg install procps-ng opkg install procps-ng-pgrep
'pgrep' isn't technically required, but it's used in the init.d start-up script. It's a handy command to have around anyway.
-
Define/create a directory in the Linux filesystem to hold your pyTivo software and configuration. I've chosen to use /opt/app/pyTivo, so if you see that string referenced below, substitute the path to your pyTivo directory if you're using something else.
[Note /opt is the entware directory, so I just created another directory within the entware structure I call "app" to hold application-specific data, then created another subdirectory within it for pyTivo specific files. This is purely a matter of personal preference, so set it up as you like.] -
Bring over a copy of pyTivo and install it in the directory defined in the previous step.
-
If you're new to pyTivo, I suggest using this guide to obtain the software:
http://pytivo.sourceforge.net/wiki/index.php/Current_Releases
Then follow the instructions on that page under: New users are recommended to start here -
If you've already got pyTivo running somewhere else (e.g. a Windows box), it's actually OK just to copy that folder over. You'll just need to delete the 'bin' directory as that contains binaries for the target environment (e.g. Windows), which are obviously not compatible with the router. All the other files in the distro are just text files.
-
Edit the pyTivo.conf file as recommended in the previous instructions. Mine is shown below for example.
- On the beacon line, update to match your network's subnet (the '192.168.1' part, the 255 at the end you'll want to leave as that's the broadcast identifier)
- Update the media shares to match your rig. The string in the square brackets is the name displayed on the Tivo client.[Server] beacon = 192.168.1.255 ffmpeg = /opt/bin/ffmpeg
[Music on Router] type = music path = /mnt/AUD/Music
[Podcasts on Router] type = music path = /mnt/AUD/Podcasts
[Video on Router] force_alpha = on type = video path = /mnt/VID/Video
-
Enable zeroconf broadcast to work (as explained above in the section titled "Zeroconf"):
route add -net 224.0.0.0 netmask 224.0.0.0 br0
-
Try to start pyTivo in a telnet window:
cd /opt/app/pyTivo python pyTivo.py
You should see something like this coming back from pyTivo:
INFO:pyTivo:Last modified: Mon Nov 14 02:07:58 2016
INFO:pyTivo:Python: 2.7.12
INFO:pyTivo:System: Linux-2.6.36.4brcmarm-armv7l-with-glibc2.4
INFO:pyTivo.beacon:Scanning for TiVos...
INFO:pyTivo.beacon:FamRM Bolt
INFO:pyTivo.beacon:MBR Premiere
INFO:pyTivo.beacon:Announcing shares...
INFO:pyTivo.beacon:Registering: Music on Router
INFO:pyTivo.beacon:Registering: Podcasts on Router
INFO:pyTivo.beacon:Registering: Video on Router
INFO:pyTivo:pyTivo is ready.
Optional: to get to pyTivo's Web GUI as a user-friendly way to edit advanced config options, navigate to http://\<your router's IP>:9032/
For example, http://192.168.1.1:9032/
- Go to your Tivo and see if the shares show up.
- Music and Photo shares will appear on the 'Music and Photos' menu.
- Video shares will appear at the very bottom of your 'My Shows' list.
Select a share, navigate to a media file and start it playing. Sit back and enjoy your new capability!
A common problem with recent Tivos (those depending exclusively on zeroconf) is they are slow to respond to new media servers coming onto the network. You can force a zeroconf refresh by 'bouncing' the network on the Tivo device (e.g. unplug the network cable, wait a few seconds, then plug it in again). You should then see the pyTivo shares pop up on your Tivo's menu in a couple of seconds.
- Once you're happy with your configuration, install the following start script on the router so it will start up automatically.
- Update the line 'PYTIVO_DIR=' to match your config if it's not correct as is.
- Install to: /opt/etc/init.d/S50pyTivo
(Feel free to change the '50' to whatever number you want, it determines the start-up order of services under init.d. Lower-numbered are started first.)
Create this file (in UNIX-format, as described in https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts)
… you must save files with a UNIX encoding. Note that Windows' Notepad cannot save with a UNIX encoding - get Notepad++ instead. You can also directly edit them on the router through ssh or telnet, by using vi or nano, both included in the firmware. These two will create files already encoded in the proper format.
For Windows users, one quick option is to run nano via telnet or ssh, then just copy/paste the contents of the desired file into the nano window, and finally save to the desired directory.
#!/bin/sh
# pyTivo init.d script
# To be installed as /opt/etc/init.d/SXXpyTivo
# XX in file name reflects start order (e.g. S50pyTivo)
# the path to your pyTivo installation directory
PYTIVO_DIR=/opt/app/pyTivo
RETVAL=0
start() {
echo -n "Starting pyTivo: "
pgrep -f pyTivo.py
RETVAL=$?
[ $RETVAL -eq 0 ] && echo "pyTivo already running: Exiting" && exit 1
if [ -e $PYTIVO_DIR/NOLOG ]
then
PYTIVO_LOG=/dev/null
logger "Entware init.d:" "Starting pyTivo, logging disabled"
else
PYTIVO_LOG=$PYTIVO_DIR/pyTivo.log
logger "Entware init.d:" "Starting pyTivo, logging enabled"
fi
# Add route for broadcast packets to/from router (required for zeroconf to work w/pyTivo)
route add -net 224.0.0.0 netmask 224.0.0.0 br0
# this call actually starts pyTivo.
nohup python $PYTIVO_DIR/pyTivo.py > $PYTIVO_LOG 2>&1 &
RETVAL=$?
[ $RETVAL -eq 0 ] && echo -n "done"
echo
return $RETVAL
}
stop() {
echo -n "Stopping pyTivo: "
PID=`pgrep -f pyTivo.py`
[ "x$PID" == "x" ] && echo "pyTivo not found running: Exiting" && exit 1
logger "Entware init.d:" "Stopping pyTivo"
kill $PID
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
# Delete route previously added by 'start' block
route del -net 224.0.0.0 netmask 224.0.0.0 br0
RETVAL=$?
fi
echo
[ $RETVAL -eq 0 ] && echo -n "done"
echo
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
sleep 1
start
RETVAL=$?
;;
check)
pgrep -fa pyTivo.py
RETVAL=$?
;;
showlog)
tail -120 $PYTIVO_DIR/pyTivo.log
RETVAL=$?
;;
taillog)
tail -50 -f $PYTIVO_DIR/pyTivo.log
RETVAL=$?
;;
*)
echo "Usage: $0 \{start\|stop\|restart\|check\|showlog\|taillog\}"
exit 1
;;
esac
exit $RETVAL
- Make that start-up script executable, then start pyTivo with it (make sure you have exited the manually started instance you were testing with):
chmod a+rx /opt/etc/init.d/S50pyTivo
/opt/etc/init.d/S50pyTivo start
It now should auto-start on router reboot as well.
- The start-up script provides an easy way to enable or disable logging from pyTivo. I suggest leave it by default to create a log file under your pyTivo directory until you're sure it's running OK. But it can grow quite large as it logs a lot of messages just from normal activity. Once you're satisfied it's working correctly, you can easily turn off logging by creating a dummy file in the pyTivo directory named NOLOG, then restarting pyTivo
touch /opt/app/pyTivo/NOLOG
/opt/etc/init.d/S50pyTivo restart
Re-enable logging by deleting (or renaming) NOLOG and then restart pyTivo via the init.d script.
- Enjoy!
Avahi-Daemon (선택 사항)
pyTivo는 구현된대로 자체 포함된 독립형 zeroconf 솔루션입니다. 그것은 AsusWRT-Merlin에서 기본적으로 실행되는 내장 avahi-daemon 프로세스에 의존하지 않거나 어떤 방식으로든 사용하지 않습니다. 내장 avahi-daemon은 기본적으로 모든 라우터에서 실행되며 Apple 사용자를 대상으로 하는 iTunes 및 Time Machine 선택적 서비스를 지원하기 위해 존재하는 것으로 보입니다. 그런데 Apple 지향 서비스를 모두 비활성화한 경우에도 모든 라우터에서 기본적으로 실행됩니다. pyTivo zeroconf 코드에는 avahi-daemon과 호환된다고 설명하는 주석이 있으며 그에 대해 의심할 이유가 없습니다. 그러나 나는 이러한 Apple 서비스를 사용하지 않으므로 시스템 리소스를 절약하고 이러한 경쟁하는 zeroconf 스택 간의 원치 않는 상호 작용이 없도록 하기 위해 avahi-daemon 프로세스를 종료하는 것을 선호합니다. Apple 서비스 중 하나를 사용하고 있다면 avahi-daemon 프로세스를 실행해야 하지만 pyTivo와 이러한 Apple 서비스 간의 상호 작용이 발생할 수 있음을 유의해야 합니다. 희망적으로는 발생하지 않겠지만 제 경험이 없습니다.
avahi-daemon 프로세스를 기본적으로 시작하지 않는 방법을 모르겠으며, 이것은 펌웨어에 내장되어 있기 때문입니다. 그러나 대부분의 Linux 서비스와 마찬가지로 서비스가 시작되고 필요한 .conf 파일을 찾지 못하면 조용히 종료됩니다. 따라서 쉽게 해결할 수 있는 방법은 부팅 시 기본 avahi-daemon.conf 파일을 제거하는 것입니다. 이 파일은 로그 파일에서 시작되는 것을 볼 수 있지만 ps 또는 _pgrep_에서 실행 중인 것을 볼 수 없습니다. 이 글을 작성하는 시점에서 제 라우터에서는 이렇게 실행해 오류 없이 한 달 이상 사용되었습니다.
가장 간단한 'avahi-daemon 종료' 솔루션은 /jffs/configs에 빈 avahi-daemon.conf 파일을 설치하는 것입니다.
touch /jffs/configs/avahi-daemon.conf
그게 다입니다. 라우터가 다시 부팅될 때 시스템이 생성한 빈 .conf 파일을 설치합니다.
조금 더 복잡한 방법은 /jffs/scripts 아래에 avahi-daemon.postconf 스크립트를 설치하는 것입니다. 저는 그렇게 하고 있습니다: [위에서 설명한 UNIX 형식으로 생성하고 스크립트를 실행 가능하게 만드는 모든 주의 사항이 적용됩니다...]
#!/bin/sh
#
# /jffs/scripts/avahi-daemon.postconf
#
# AVAHI-DAEMON을 실행하고 싶지 않습니다. 이것은 우리의 사용에 아무런 목적도 없으며
# 사실 pyTivo의 일부로 실행되는 zeroconf 서비스와 간섭할 수도 있습니다.
# 이 스크립트의 유일한 목적은 시스템에서 생성한 .conf 파일을 효과적으로 제거하여
# avahi-daemon이 시작되려고 할 때 빠르게 종료되도록 하는 것입니다.
# 시스템에서 생성된 conf 파일을 저장합니다 (기본 설정을 검토하려는 경우를 위해)
logger "avahi-daemon.postconf:" "avahi-daemon이 조용히 종료되도록 시스템에서 생성된 $1 제거."
mv $1 $1.system
로그 파일에서 avahi-daemon을 종료하는 것을 볼 때 나는 그것을 종료하고 있다는 알림 항목을 보는 것을 좋아합니다. 'mv' 명령은 그것을 옆으로 옮겨 놓습니다. 그것은 제거하는 것과 같은 효과가 있지만 시스템이 기본적으로 생성한 것을 보려는 경우를 위해 그것을 보관합니다.
여기서 읽은 내용과 마찬가지로 이 변경 사항을 적용하려면 그것이 여러분에게 의미가 있다면 구현하십시오. 꺼내지 말고 그대로 두면 해당 부분을 건드리기 어렵다면 그냥 둬두십시오.
이 기사가 도움이 되었기를 바랍니다. 질문/의견이 있으십니까? http://www.snbforums.com/forums/asuswrt-merlin.42/에서 'latenitetech'로 찾아보세요. 도움이 될 수 있다면 기쁘게 도와 드리겠습니다.
-Mark