|
3 | 3 | import com.grack.nanojson.JsonArray; |
4 | 4 | import com.grack.nanojson.JsonObject; |
5 | 5 | import com.grack.nanojson.JsonParser; |
| 6 | +import org.jsoup.Jsoup; |
| 7 | +import org.jsoup.nodes.Document; |
| 8 | +import org.jsoup.nodes.Element; |
| 9 | +import org.jsoup.select.Elements; |
6 | 10 | import org.mozilla.javascript.Context; |
7 | 11 | import org.mozilla.javascript.Function; |
8 | 12 | import org.mozilla.javascript.ScriptableObject; |
@@ -740,11 +744,30 @@ private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaExcepti |
740 | 744 | final String embedPageContent = downloader.get(embedUrl, getExtractorLocalization()).responseBody(); |
741 | 745 |
|
742 | 746 | // Get player url |
743 | | - final String assetsPattern = "\"assets\":.+?\"js\":\\s*(\"[^\"]+\")"; |
744 | | - String playerUrl = Parser.matchGroup1(assetsPattern, embedPageContent) |
745 | | - .replace("\\", "").replace("\"", ""); |
| 747 | + String playerUrl = null; |
| 748 | + try { |
| 749 | + final String assetsPattern = "\"assets\":.+?\"js\":\\s*(\"[^\"]+\")"; |
| 750 | + playerUrl = Parser.matchGroup1(assetsPattern, embedPageContent) |
| 751 | + .replace("\\", "").replace("\"", ""); |
| 752 | + } catch (Parser.RegexException ex) { |
| 753 | + // playerUrl is still available in the file, just somewhere else |
| 754 | + final Document doc = Jsoup.parse(embedPageContent); |
| 755 | + final Elements elems = doc.select("script").attr("name", "player_ias/base"); |
| 756 | + for (Element elem : elems) { |
| 757 | + if (elem.attr("src").contains("base.js")) { |
| 758 | + playerUrl = elem.attr("src"); |
| 759 | + } |
| 760 | + } |
| 761 | + |
| 762 | + if (playerUrl == null) { |
| 763 | + throw new ParsingException("Could not get playerUrl"); |
| 764 | + } |
| 765 | + } |
| 766 | + |
746 | 767 | if (playerUrl.startsWith("//")) { |
747 | 768 | playerUrl = HTTPS + playerUrl; |
| 769 | + } else if (playerUrl.startsWith("/")) { |
| 770 | + playerUrl = HTTPS + "//youtube.com" + playerUrl; |
748 | 771 | } |
749 | 772 |
|
750 | 773 | try { |
|
0 commit comments