|
本帖最后由 afusky 于 2018-7-12 15:40 编辑
参考论坛上大神写的自动下载插件,自己学习写了个插件,但是在配置的时候点击检查配置,一直报错,请问什么原因
moviedownload:
website: 'http://gaoqing.fm/'
listurl: '/?sort=最新&country=&director=&actor=&type=&year='
savepath: '/config/transmission-watchdir'
检查配置提示错误如下:
Invalid config for [moviedownload]: required key not provided @ data['platform']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/moviedownload/
代码如下
import xxx
uaList = [{'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'},
{'User-Agent': 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11'},
{'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'}]
rd = random.randint(0, len(uaList) - 1)
ua = uaList[rd]
_LOGGER = logging.getLogger(__name__)
CONF_WEBSITE = 'website'
CONF_LIST_URL = 'listurl'
CONF_SAVE_PATH = 'savepath'
DOMAIN = 'moviedownload'
ADD_COUNT=0
SERVICE_DOWNLOAD = 'Download'
SERVICE_DOWNLOAD_SCHEMA = vol.Schema({
vol.Required(CONF_WEBSITE): cv.string,
vol.Required(CONF_LIST_URL): cv.string,
vol.Required(CONF_SAVE_PATH): cv.string,
}, extra=vol.ALLOW_EXTRA)
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_WEBSITE): cv.string,
vol.Required(CONF_LIST_URL): cv.string,
vol.Required(CONF_SAVE_PATH): cv.string,
})
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config):
website = config[DOMAIN][CONF_WEBSITE]
list_url = config[DOMAIN][CONF_LIST_URL]
save_path = config[DOMAIN][CONF_SAVE_PATH]
if website == None:
_LOGGER.error('moviedownload:website is null' )
if list_url == None:
_LOGGER.error('moviedownload:list_url is null' )
if save_path == None:
_LOGGER.error('moviedownload:save_path is null' )
_LOGGER.info('>>>>>>>>>>>>>>>>>>moviedownload:paras is ok')
def down_movie_torrent(url, t_file_path):
global ADD_COUNT
data = requests.get(url, headers=ua).text
soup = bs4.BeautifulSoup(data, "html.parser")
a_torrent = soup.find_all('a')
dict = {}
#下载具体逻辑
return
def moviedownload_download(service):
_LOGGER.info('>>>>>>>>>>>>>>>> start moviedownload:'+website + list_url+',save_path:'+save_path)
threading.Thread(target=down_movie_torrent(website + list_url, save_path)).start()
hass.services.register(DOMAIN, SERVICE_DOWNLOAD, moviedownload_download,schema=SERVICE_DOWNLOAD_SCHEMA)
return True
|
|