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
|
|
|
|
2022-02-22 12:13:18 +00:00
|
|
|
NAMESPACE = 'http://www.andymatuschak.org/xml-namespaces/sparkle'
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-02-22 12:13:18 +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)
|
2022-02-22 12:13:18 +00:00
|
|
|
item = root.find('./channel/item[1]/enclosure')
|
|
|
|
|
|
|
|
version_string = item.get(f'{{{NAMESPACE}}}shortVersionString')
|
|
|
|
build_number = item.get(f'{{{NAMESPACE}}}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)
|
|
|
|
if build_number and (build_number not in version):
|
|
|
|
version.append(build_number)
|
2020-05-05 04:20:36 +00:00
|
|
|
|
2022-02-22 12:13:18 +00:00
|
|
|
return '-'.join(version) if version else None
|