diff --git a/VERSION b/VERSION index ccbccc3..c043eea 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.0 +2.2.1 diff --git a/musescore_scraper/MuseScraper.py b/musescore_scraper/MuseScraper.py index eed7c64..54ddfd4 100755 --- a/musescore_scraper/MuseScraper.py +++ b/musescore_scraper/MuseScraper.py @@ -121,9 +121,9 @@ async def get_score_tags() -> str: "Keywords": await get_score_tags(), } - imgs: List[str] = await page.evaluate(str(get_data("musescore_scraper", - "script.js", - ), "utf-8")) + imgs: List[str] = await asyncio.wait_for(page.evaluate(str(get_data("musescore_scraper", + "script.js", + ), "utf-8")), self.timeout) await page.close() diff --git a/musescore_scraper/script.js b/musescore_scraper/script.js index 76ea814..d4aa985 100755 --- a/musescore_scraper/script.js +++ b/musescore_scraper/script.js @@ -9,33 +9,48 @@ classCounts[childClass] = []; } classCounts[childClass].push(child); - if (desiredClass === undefined || classCounts[childClass].length > classCounts[desiredClass].length) { + if (desiredClass === undefined + || classCounts[childClass].length > classCounts[desiredClass].length) { desiredClass = childClass; } } - let svgs = []; + + //If it's 2 pages, the 2nd page may be already loaded, thus making generic function not work. + if (classCounts[desiredClass].length <= 2) { + let imgs = []; + for (let div of classCounts[desiredClass]) { + img = div.querySelector("img"); + if (img !== undefined) { + imgs.push(img.src); + } + } + if (imgs.length == classCounts[desiredClass].length) { + return imgs; + } + } + + let imgs = []; let i = undefined; scrollDiv.scroll({ left : 0, top : 0, - behavior : "smooth" }); return new Promise(resolve => { - function addSvg(records, observer) { + function addImg(records, observer) { for (let record of records) { //records is a list of MutationRecords if (record.target.tagName === "IMG" && record.attributeName === "src" && record.target.src !== undefined) { - svgs.push(record.target.src); + imgs.push(record.target.src); if (classCounts[desiredClass].indexOf(record.target.parentElement) == classCounts[desiredClass].length - 1) { observer.disconnect(); - resolve(svgs); + resolve(imgs); } else { @@ -45,7 +60,7 @@ } } } - let observer = new MutationObserver(addSvg); + let observer = new MutationObserver(addImg); for (let child of classCounts[desiredClass]) { observer.observe(child, { attributes: true, @@ -57,7 +72,7 @@ } else { - addSvg([{ + addImg([{ attributeName: "src", target: classCounts[desiredClass][0].querySelector("img"), }]);