forked from dhtdht020/osc-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.py
217 lines (167 loc) · 6.32 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import parsecontents
import requests
import lxml.etree
import dateparser
import locale
GREEN = '\033[92m'
FAIL = '\033[91m'
locale.setlocale(locale.LC_ALL, 'en_GB')
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/
try:
xml = requests.get("https://" + repo + "/unzipped_apps/" + app_name + "/apps/" + app_name + "/meta.xml").text
except requests.exceptions.SSLError:
xml = requests.get("http://" + 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"):
try:
request = requests.get("https://" + repo+ "/hbb/"+ app_name + ".png")
icon = request.content
# If icon is not there
if str(request.status_code) != "200":
icon = requests.get(
"https://raw.githubusercontent.com/dhtdht020/oscdl-updateserver/master/v1/assets/missing.png").content
except Exception:
icon = requests.get("https://raw.githubusercontent.com/dhtdht020/oscdl-updateserver/master/v1/assets/missing.png").content
return icon
def url(app_name, repo="hbb1.oscwii.org"):
app_url = "https://" + repo + "/hbb/" + app_name + "/" + app_name + ".zip"
return app_url
def dictionary(app_name, repo="hbb1.oscwii.org"):
try:
xml = requests.get("https://" + repo + "/unzipped_apps/" + app_name + "/apps/" + app_name + "/meta.xml").text
except requests.exceptions.SSLError:
xml = requests.get("http://" + 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 + " (hbbID)"
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 = "No description provided"
try:
long_description = root.find('long_description').text
except Exception:
long_description = "No description provided"
try:
try:
parsed_date = dateparser.parse(root.find('release_date').text)
if parsed_date is not None:
readable_date = parsed_date.strftime('%x')
release_date = root.find('release_date').text + " (" + readable_date + ")"
else:
release_date = root.find('release_date').text + " [RAW]"
except Exception:
release_date = root.find('release_date').text + " [RAW]"
except Exception:
release_date = "Unknown"
try:
contributors = root.find('contributors').text
except Exception:
contributors = "None"
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
def dictionary_raw(app_name, repo="hbb1.oscwii.org"):
try:
xml = requests.get("https://" + repo + "/unzipped_apps/" + app_name + "/apps/" + app_name + "/meta.xml").text
except requests.exceptions.SSLError:
xml = requests.get("http://" + 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
d = {}
for Element in root:
d[Element.tag] = root.find(Element.tag).text
return d
def raw(app_name, repo="hbb1.oscwii.org"):
try:
xml = requests.get("https://" + repo + "/unzipped_apps/" + app_name + "/apps/" + app_name + "/meta.xml").text
except requests.exceptions.SSLError:
xml = requests.get("http://" + repo + "/unzipped_apps/" + app_name + "/apps/" + app_name + "/meta.xml").text
return xml