Scraping Genius not rendering by jQuery for some reason

This commit is contained in:
James Barnsley
2020-01-22 16:04:19 +13:00
parent bdd82b1447
commit f33e37a1d1
6 changed files with 26951 additions and 18944 deletions

View File

@ -147,7 +147,7 @@ class HttpHandler(tornado.web.RequestHandler):
# make sure the method exists
if hasattr(iris, slug):
try:
# For async methods we need to await, but it must be ommited for syncronous methods
if asyncio.iscoroutinefunction(getattr(iris, slug)):
await getattr(iris, slug)(request=self, callback=lambda response, error=False: self.handle_result(id=id, method=slug, response=response, error=error))
@ -201,9 +201,6 @@ class HttpHandler(tornado.web.RequestHandler):
'method': method
}
print(response)
print(error)
if error:
request_response['error'] = error
self.set_status(400)
@ -212,16 +209,16 @@ class HttpHandler(tornado.web.RequestHandler):
# We've been handed an AsyncHTTPClient callback. This is the case
# when our request calls subsequent external requests (eg Spotify, Genius).
# We don't need to wrap non-HTTPResponse responses as these are dicts
elif isinstance(response, tornado.httpclient.HTTPResponse) or isinstance(response, tornado.httpclient.AsyncHTTPResponse):
elif isinstance(response, tornado.httpclient.HTTPResponse):
# Digest JSON responses into JSON
content_type = response.headers.get('Content-Type')
if content_type.startswith('application/json') or content_type.startswith('text/json'):
body = json.loads(response.body)
body = json.loads(response.body.decode("utf-8") )
# Non-JSON so just copy as-is
else:
body = response.body
body = json_encode(response.body.decode("utf-8") )
request_response['result'] = body

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -100,7 +100,7 @@
// Release details
// These are automatically injected to built HTML
var build = "1579284872";
var build = "1579657760";
var version = "3.44.0";
// Construct the script tag

View File

@ -157,7 +157,7 @@ export function getTrackLyrics(uri, path) {
(response, status, xhr) => {
dispatch(uiActions.stopLoading(loader_key));
if (response && response.result) {
const html = $(response.result);
const html = $('<div/>').html(response.result).contents();
let lyrics = html.find('.lyrics');
if (lyrics.length > 0) {
lyrics = lyrics.first();

View File

@ -174,11 +174,7 @@ class Track extends React.Component {
);
}
return (
<ErrorMessage type="not-found" title="Not found">
<p>
Could not find track with URI "{encodeURIComponent(this.props.uri)}"
</p>
</ErrorMessage>
<ErrorMessage type="not-found" title="Could not load lyrics" />
);
}