Linux迷+Python粉 - 遥控https://blog.pythonwood.com/2017-12-13T22:20:00+08:00树莓派安装kodi神器和红外遥控装置变身多媒体中心2017-12-13T22:20:00+08:002017-12-13T22:20:00+08:00pythonwoodtag:blog.pythonwood.com,2017-12-13:/2017/12/树莓派安装kodi神器和红外遥控装置变身多媒体中心/<h3 id="_1">总述<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h3> <p>在大学里通过<span class="caps">IPV6</span>看过<span class="caps">IPTV</span>,最近一两年直播非常火,电视盒子也火了一把。于是想用kodi看直播电视。</p> <p>kodi的低耗,无噪音,便宜的优点我觉得很适合做家庭多媒体服务中心。</p> <p>第二次用树莓派安装kodi,没有上一次那么迷茫了。把一些有价值的东西记录下来。</p> <p><img alt="遥控树莓派kodi.gif" src="https://blog.pythonwood.com/uploads/2017/遥控树莓派kodi.gif" title="遥控树莓派kodi"></p> <h3 id="kodikodi-pvr-iptvsimple">一、安装Kodi(请务必一同安装kodi-pvr-iptvsimple)<a class="headerlink" href="#kodikodi-pvr-iptvsimple" title="Permanent link">&para;</a></h3> <div class="highlight"><pre><span></span>sudo apt-get install …</pre></div><h3 id="_1">总述<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h3> <p>在大学里通过<span class="caps">IPV6</span>看过<span class="caps">IPTV</span>,最近一两年直播非常火,电视盒子也火了一把。于是想用kodi看直播电视。</p> <p>kodi的低耗,无噪音,便宜的优点我觉得很适合做家庭多媒体服务中心。</p> <p>第二次用树莓派安装kodi,没有上一次那么迷茫了。把一些有价值的东西记录下来。</p> <p><img alt="遥控树莓派kodi.gif" src="https://blog.pythonwood.com/uploads/2017/遥控树莓派kodi.gif" title="遥控树莓派kodi"></p> <h3 id="kodikodi-pvr-iptvsimple">一、安装Kodi(请务必一同安装kodi-pvr-iptvsimple)<a class="headerlink" href="#kodikodi-pvr-iptvsimple" title="Permanent link">&para;</a></h3> <div class="highlight"><pre><span></span>sudo apt-get install kodi kodi-pvr-iptvsimple </pre></div> <p>并不是raspbian安装kodi后就能看直播/电视了。如果没有安装kodi-pvr-iptvsimple,kodi侧栏的电视功能无响应,直播/<span class="caps">TV</span>的相关插件也会有问题。我花了不少时间才找到了原因。</p> <p>如果出现kodi的插件里没有&rdquo;<span class="caps">PVR</span>客户端&rdquo;选项可设置,或者搜索不到<span class="caps">PVR</span> <span class="caps">IPTV</span> Simple&nbsp;Client相关插件,或者设置时出现错误提示信息Error,通过安装kodi-pvr-iptvsimple可解决。</p> <h3 id="kodi">二、设置kodi在无需桌面环境下随机自动运行<a class="headerlink" href="#kodi" title="Permanent link">&para;</a></h3> <p>kodi可以通过非<span class="caps">GUI</span>的命令行启动,无需先启动桌面环境,非常省资源。</p> <p>我做过实测树莓派3启动到命令行只需<span class="caps">50MB</span>内存,启动kodi播放则再增加<span class="caps">100MB</span>内存。总共只需<span class="caps">150MB</span>。如果启动桌面环境,桌面环境单独占用<span class="caps">70MB</span>内存。</p> <p>先用<code>sudo raspi-config</code>命令设置boot选项,启动后自动登录到命令行模式(auto boot to&nbsp;cli)。</p> <p>然后在pi用户的.bashrc命令中追加一行</p> <div class="highlight"><pre><span></span>( cd /tmp; ps -ef | grep -v grep | grep kodi || DISPLAY=:0.0 nohup kodi ) 2&gt;&amp;1 &gt;/dev/null &amp; </pre></div> <p>这样树莓派每次都会启动到kodi,但不会多次运行kodi。</p> <h3 id="kodi_1">三、树莓派添加红外模块后实现电视遥控器控制kodi<a class="headerlink" href="#kodi_1" title="Permanent link">&para;</a></h3> <p>虽然安装快控(kodi remote control)App或者yaste&nbsp;App可以在wifi环境下通过App远程控制树莓派运行的kodi。</p> <p>然而我觉得每次先解锁手机,打开软件,然后只为点几下键体验不是很好。</p> <p>所以,在老旧已坏的遥控飞机上拆下红外模块(对讲机,其他遥控玩具都会有这个模块,支持废物利用),结合家里旧的遥控器实现红外遥控树莓派。</p> <p><img alt="遥控飞机红外接受模块" src="http://www.dgpufei.com/Public/Uploads/Article/20170115/587b2a331b16a.jpg" title="遥控飞机红外接受模块"></p> <p><strong>我跟着这个教程<a href="https://blog.newnius.com/raspberry-3b-setup-lirc.html" title="树莓派---红外遥控设置">树莓派&mdash;红外遥控设置</a>设置成功</strong>。</p> <h4 id="kodi_2">树莓派能识别红外遥控器后,就是树莓派kodi学习(映射)按键与指令对应关系的过程。<a class="headerlink" href="#kodi_2" title="Permanent link">&para;</a></h4> <p>kodi配置键名(比如KEY_OK)和kodi动作的映射关系文件路径是/usr/share/kodi/system/Lircmap.xml。</p> <p>以下面mediacenter类型的遥控设备为例,按下该设备某个键,对应lircd接受到ok指令,那么kodi执行select动作。</p> <p>为了省事,我把其中键名最简洁<remote device="mediacenter">的xml段复制后</p> <div class="highlight"><pre><span></span><span class="nt">&lt;remote</span> <span class="na">device=</span><span class="s">&quot;mediacenter&quot;</span><span class="nt">&gt;</span> ... <span class="nt">&lt;up&gt;</span>up<span class="nt">&lt;/up&gt;</span> <span class="nt">&lt;down&gt;</span>down<span class="nt">&lt;/down&gt;</span> <span class="nt">&lt;select&gt;</span>ok<span class="nt">&lt;/select&gt;</span> <span class="nt">&lt;one&gt;</span>1<span class="nt">&lt;/one&gt;</span> <span class="nt">&lt;two&gt;</span>2<span class="nt">&lt;/two&gt;</span> ... <span class="nt">&lt;/remote&gt;</span> </pre></div> <p>粘贴并修改device值</p> <div class="highlight"><pre><span></span><span class="nt">&lt;remote</span> <span class="na">device=</span><span class="s">&quot;guangdianyaokong&quot;</span><span class="nt">&gt;</span> ... <span class="nt">&lt;up&gt;</span>up<span class="nt">&lt;/up&gt;</span> <span class="nt">&lt;down&gt;</span>down<span class="nt">&lt;/down&gt;</span> <span class="nt">&lt;select&gt;</span>ok<span class="nt">&lt;/select&gt;</span> <span class="nt">&lt;one&gt;</span>1<span class="nt">&lt;/one&gt;</span> <span class="nt">&lt;two&gt;</span>2<span class="nt">&lt;/two&gt;</span> ... <span class="nt">&lt;/remote&gt;</span> </pre></div> <p>guangdianyaokong是我在/etc/lirc/lircd.conf文件的name字段名字,可自由修改。只要保持对应一致就可以了。</p> <p>我录制irrecord命令如下,省事的原因是录键名的时候对应取up,down,1,ok等简单词。</p> <div class="highlight"><pre><span></span>irrecord -d /dev/lirc0 guangdianyaokong --disable-namespace </pre></div> <h3 id="kodi_3">四、接下来自由发挥,对kodi自行研究,安装各种插件。<a class="headerlink" href="#kodi_3" title="Permanent link">&para;</a></h3> <p>按照插件库然后从插件库安装插件,或者直接按照目标插件的zip包。</p> <p><img alt="树莓派插件库列表截图" src="https://blog.pythonwood.com/uploads/2017/树莓派插件库列表截图.jpg" title="树莓派插件库列表截图"></p> <p>搜集m3u8直播列表,灌给<span class="caps">PVR</span> <span class="caps">IPTV</span>客户端使用。也可以使用<a href="http://blog.sina.com.cn/s/blog_4ae08cc00102wz42.html" title="用Kodi观看网络直播电视:新插件IPTV Tool "><span class="caps">IPTV</span> Tool</a>插件来托管<span class="caps">PVR</span> <span class="caps">IPTV</span>客户端</p> <h3 id="m3u8url">五、直播m3u8列表的url存活测试<a class="headerlink" href="#m3u8url" title="Permanent link">&para;</a></h3> <h4 id="_2">导入播放器中手动测试<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h4> <p>smplayer或者vlc都能打开m3u8文件进行网络播放。所以也能来测试是否存活。只是方法简单直接容易累。</p> <p>可打开播放器界面中打开m3u8文件;命令行则可用smplayer <m3u8_list>, 或者 vlc <m3u8_list>打开。</p> <h4 id="_3">脚本批量快速检测<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h4> <p>(todo&hellip;)</p> <h3 id="_4">提醒<a class="headerlink" href="#_4" title="Permanent link">&para;</a></h3> <p>熟悉Linux环境的话,完成一台树莓派环境配置之后,可随时备份,其它树莓派克隆环境就可以了。具体方法参考另一篇随笔。 <a href="https://blog.pythonwood.com/2017/11/树莓派SD卡Linux系统盘复制,10分钟克隆新机/">树莓派<span class="caps">SD</span>卡Linux系统盘复制,10分钟克隆新机</a></p> <h3 id="_5">参考<a class="headerlink" href="#_5" title="Permanent link">&para;</a></h3> <ol> <li> <p>Kodi 开源多媒体播放器 - 神器&nbsp;http://www.cnblogs.com/XieSir/articles/6287387.html</p> </li> <li> <p>6款树莓派kodi插件推荐&nbsp;https://www.htpcbeginner.com/raspberry-pi-kodi-addons/</p> </li> <li> <p>移动网络电视和<span class="caps">IPTV</span>的区别在哪里?&nbsp;http://www.shafa.com/articles/zJmvNRrYFs6uzjhH.html</p> </li> </ol>