Skip to content

Commit

Permalink
Merge pull request #6 from TobiGr/apk-url
Browse files Browse the repository at this point in the history
Add more release data (apk, version, version_code) for GitHub and F-Droid
  • Loading branch information
TobiGr committed Jul 4, 2018
2 parents 67ab414 + 418d486 commit 1bca377
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def fetch_data_and_assemble_response(self):

repo_url = "https://api.github.com/repos/TeamNewPipe/NewPipe"

release_github_url = "https://github.com/TeamNewPipe/NewPipe/releases/"

contributors_url = "https://github.com/TeamNewPipe/NewPipe"

translations_url = "https://hosted.weblate.org/api/components/" \
Expand All @@ -121,6 +123,7 @@ def fetch(request: tornado.httpclient.HTTPRequest):
responses = yield tornado.gen.multi((
fetch(make_request(repo_url)),
fetch(make_request(stable_url)),
fetch(make_request(release_github_url)),
fetch(make_request(contributors_url)),
fetch(make_request(translations_url)),
))
Expand All @@ -130,21 +133,44 @@ def fetch(request: tornado.httpclient.HTTPRequest):
self.__class__._last_failed_request = datetime.now()
return False

repo_data, stable_data, \
repo_data, stable_data, release_github_data, \
contributors_data, translations_data = [x.body for x in responses]

def assemble_release_data(data: str):
if isinstance(data, bytes):
data = data.decode()

versions = re.findall("commit=(.*)", data)
def assemble_release_data(version_data: str):
if isinstance(version_data, bytes):
version_data = version_data.decode()

versions = re.findall("commit=(.*)", version_data)
version_codes = re.findall("Build:(.*)", version_data)
version_code = version_codes[-1].split(",")[-1]
return {
"version": versions[-1],
"version_code": int(version_code),
"apk": "https://f-droid.org/repo/org.schabi.newpipe_" + version_code + ".apk",
}

repo = json.loads(repo_data)

# scrape latest GitHub version and apk from website
elem = html.fromstring(release_github_data)
tags = elem.cssselect('.release-body li.d-block a[href$=".apk"]')
if len(tags) == 0:
release_github_apk = -1
else:
try:
release_github_apk = "https://github.com" + tags[0].get('href')
except:
release_github_apk = -1
tags = elem.cssselect('.release-header h1.release-title a')
if len(tags) == 0:
release_github_version = -1
else:
try:
release_github_version = tags[0].text
except:
release_github_version = -1

# scrape contributors from website
elem = html.fromstring(contributors_data)
tags = elem.cssselect(".numbers-summary a[href$=contributors] .num")
if len(tags) != 1:
Expand All @@ -166,7 +192,15 @@ def assemble_release_data(data: str):
"translations": int(translations["count"]),
},
"flavors": {
"stable": assemble_release_data(stable_data),
"github": {
"stable": {
"version": release_github_version,
"apk": release_github_apk,
}
},
"f-droid": {
"stable": assemble_release_data(stable_data),
}
}
}

Expand Down

0 comments on commit 1bca377

Please sign in to comment.