1.搭建下载机,使用transmission,可以下载源码自己编译安装,也可以直接apt-get install transmission-daemon
安装完成后,通过/etc/init.d/transmission-daemon启动的话是以transmission用户启动,如果下载路径的权限不是transmission用户的话会有权限问题,我这边是在rc.local中通过root启动
点击(此处)折叠或打开
- killall -9 transmission-daemon
- /usr/bin/transmission-daemon -f --log-error &
点击(此处)折叠或打开
- "download-dir": "/home/pi/NetPlayer/static",
- "rpc-password": "111111",
- "rpc-username": "youname",
- "rpc-whitelist-enabled": false,
2.搭建简单在线播放
浏览器只支持Chrome(移动端的原生Android浏览器也可以,AppleWebKit内核的应该都可以,Google有钱,买了MP4的H264编码),视频格式只支持MP4的H264编码格式,差不多也够用了,服务端通过Nginx+uwsgi+web.py搭建,搭建方法参考我前面的博文《nginx+uwsgi+web.py简单配置》,代码目录结构如下:
点击(此处)折叠或打开
- NetPlayer
- NetPlayer.py
- static(下载机的下载路径)
- moive.mp4
- templates
- index.html
点击(此处)折叠或打开
- #!/usr/bin/env python
- # coding: utf-8
- import web
- import os
- urls = (
- '/', 'mp4view'
- )
- BASE_DIR = os.path.dirname(os.path.abspath(__file__))
- TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates')
- STATIC_DIR = os.path.join(BASE_DIR, 'static')
- print("%s" % TEMPLATES_DIR)
- render = web.template.render(TEMPLATES_DIR)
- app = web.application(urls, globals())
- class mp4view:
- def GET(self):
- fileList = []
- files = os.listdir(STATIC_DIR)
- for f in files:
- if(os.path.isfile(STATIC_DIR + '/' + f)):
- fileList.append(f)
- return render.index(fileList)
- if __name__ == "__main__":
- print "everything from here"
- app.run()
- else :
- application = app.wsgifunc()
点击(此处)折叠或打开
- $def with (mp4s)
- <ul>
- $for mp4 in mp4s:
- <li id="$mp4"><a href="/static/$mp4">$mp4</a></li>
- </ul>