forked from dhtdht020/osc-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.py
155 lines (117 loc) · 3.95 KB
/
metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import parsecontents
import requests
import lxml.etree
GREEN = '\033[92m'
FAIL = '\033[91m'
def get(app_name, type=None, repo="hbb1.oscwii.org"):
if parsecontents.query_verify(term=app_name, repo=repo, internal=True) is False:
print(FAIL+"Failure: App "+app_name+" could not be found on "+repo)
exit(1)
# https://hbb1.oscwii.org/unzipped_apps/wiixplorer/apps/wiixplorer/
xml = requests.get("https://" + repo + "/unzipped_apps/" + app_name + "/apps/" + app_name + "/meta.xml").text
# remove unicode declaration
xml = xml.split("\n", 1)[1]
# get information from XML
try:
root = lxml.etree.fromstring(xml)
except lxml.etree.XMLSyntaxError:
print("[Error D:001] The meta.xml file for " + app_name + " seems to be broken. Oh no. Preparing for the worst..")
try:
display_name = root.find('name').text
except Exception:
display_name = app_name
try:
developer = root.find('coder').text
except Exception:
developer = "Unknown"
try:
version = root.find('version').text
except Exception:
version = "Unknown"
try:
short_description = root.find('short_description').text
except Exception:
short_description = "Unknown"
try:
long_description = root.find('long_description').text
except Exception:
long_description = "Unknown"
try:
release_date = root.find('release_date').text
except Exception:
release_date = "Unknown"
try:
contributors = root.find('contributors').text
except Exception:
contributors = "Unknown"
# check for requested information
if type == "display_name":
return display_name
if type == "coder":
return developer
if type == "version":
return version
if type == "short_description":
return short_description
if type == "long_description":
return long_description
if type == "release_date":
return release_date
if type == "contributors":
return contributors
print("\n=========== Application Metadata ===========")
print("Application: " + display_name + "\n")
print("Developer: " + developer)
print("Version: " + version)
print("Description: " + short_description)
print("============================================\n")
# experimental, for use by xosc-dl
def icon(app_name, repo="hbb1.oscwii.org"):
icon = "https://" + repo+ "/hbb/"+ app_name + ".png"
return icon
def dictionary(app_name, repo="hbb1.oscwii.org"):
xml = requests.get("https://" + repo + "/unzipped_apps/" + app_name + "/apps/" + app_name + "/meta.xml").text
# remove unicode declaration
xml = xml.split("\n", 1)[1]
# get information from XML
try:
root = lxml.etree.fromstring(xml)
except Exception:
pass
try:
display_name = root.find('name').text
except Exception:
display_name = app_name
try:
developer = root.find('coder').text
except Exception:
developer = "Unknown"
try:
version = root.find('version').text
except Exception:
version = "Unknown"
try:
short_description = root.find('short_description').text
except Exception:
short_description = "Unknown"
try:
long_description = root.find('long_description').text
except Exception:
long_description = "Unknown"
try:
release_date = root.find('release_date').text
except Exception:
release_date = "Unknown"
try:
contributors = root.find('contributors').text
except Exception:
contributors = "Unknown"
meta = {"display_name": display_name,
"coder": developer,
"version": version,
"short_description": short_description,
"long_description": long_description,
"release_date": release_date,
"contributors": contributors
}
return meta