2020-05-05 04:20:36 +00:00
|
|
|
# MIT licensed
|
2020-08-14 10:25:48 +00:00
|
|
|
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
2020-05-05 04:20:36 +00:00
|
|
|
# Copyright (c) 2020 Sunlei <guizaicn@gmail.com>
|
|
|
|
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
2020-08-14 12:04:05 +00:00
|
|
|
from nvchecker.api import session
|
2020-05-05 04:20:36 +00:00
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
async def get_version(name, conf, *, cache, **kwargs):
|
2020-05-05 04:20:36 +00:00
|
|
|
sparkle = conf['sparkle']
|
2020-08-14 10:25:48 +00:00
|
|
|
return await cache.get(sparkle, get_version_impl)
|
2020-05-05 04:20:36 +00:00
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
async def get_version_impl(sparkle):
|
2020-08-17 08:21:02 +00:00
|
|
|
res = await session.get(sparkle)
|
|
|
|
root = ElementTree.fromstring(res.body)
|
2020-05-05 04:20:36 +00:00
|
|
|
item = root.find('./channel/item[1]/enclosure')
|
|
|
|
|
|
|
|
version_string = item.get('{http://www.andymatuschak.org/xml-namespaces/sparkle}shortVersionString')
|
|
|
|
build_number = item.get('{http://www.andymatuschak.org/xml-namespaces/sparkle}version')
|
|
|
|
|
|
|
|
if (version_string and version_string.isdigit()) and (build_number and not build_number.isdigit()):
|
|
|
|
version_string, build_number = build_number, version_string
|
|
|
|
|
|
|
|
version = []
|
|
|
|
|
|
|
|
if version_string:
|
|
|
|
version.append(version_string)
|
2020-05-05 08:37:02 +00:00
|
|
|
if build_number and (build_number not in version):
|
2020-05-05 04:20:36 +00:00
|
|
|
version.append(build_number)
|
|
|
|
|
|
|
|
return '-'.join(version) if version else None
|