mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 12:02:16 +02:00
parent
9e14ad4bf8
commit
4898c8aff8
@ -22,6 +22,8 @@ package com.ichi2.anki.multimediacard.beolingus.parsing;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class parses beolingus pages
|
* This class parses beolingus pages
|
||||||
*/
|
*/
|
||||||
@ -40,7 +42,8 @@ public class BeolingusParser {
|
|||||||
Matcher m = PRONUNC_PATTERN.matcher(html);
|
Matcher m = PRONUNC_PATTERN.matcher(html);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
if (m.group(2).equals(wordToSearchFor)) {
|
if (m.group(2).equals(wordToSearchFor)) {
|
||||||
return "http://dict.tu-chemnitz.de" + m.group(1);
|
Timber.d("pronunciation URL is https://dict.tu-chemnitz.de" + m.group(1));
|
||||||
|
return "https://dict.tu-chemnitz.de" + m.group(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "no";
|
return "no";
|
||||||
@ -51,9 +54,12 @@ public class BeolingusParser {
|
|||||||
* @return {@code "no"}, or the http address of the mp3 file
|
* @return {@code "no"}, or the http address of the mp3 file
|
||||||
*/
|
*/
|
||||||
public static String getMp3AddressFromPronounciation(String pronunciationPageHtml) {
|
public static String getMp3AddressFromPronounciation(String pronunciationPageHtml) {
|
||||||
|
// Only log the page if you need to work with the regex
|
||||||
|
// Timber.d("pronunciationPageHtml is " + pronunciationPageHtml);
|
||||||
Matcher m = MP3_PATTERN.matcher(pronunciationPageHtml);
|
Matcher m = MP3_PATTERN.matcher(pronunciationPageHtml);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
return "http://dict.tu-chemnitz.de" + m.group(1);
|
Timber.d("MP3 address is https://dict.tu-chemnitz.de" + m.group(1));
|
||||||
|
return "https://dict.tu-chemnitz.de" + m.group(1);
|
||||||
}
|
}
|
||||||
return "no";
|
return "no";
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class BeolingusParserTest {
|
|||||||
+ "alt=\"[anhören]\" title=\"Wasser\" border=\"0\" align=\"top\" /></a>";
|
+ "alt=\"[anhören]\" title=\"Wasser\" border=\"0\" align=\"top\" /></a>";
|
||||||
|
|
||||||
String pronunciationUrl = BeolingusParser.getPronunciationAddressFromTranslation(html, "Wasser");
|
String pronunciationUrl = BeolingusParser.getPronunciationAddressFromTranslation(html, "Wasser");
|
||||||
assertEquals("http://dict.tu-chemnitz.de/dings.cgi?speak=de/0/7/52qA5FttGIU;text=Wasser", pronunciationUrl);
|
assertEquals("https://dict.tu-chemnitz.de/dings.cgi?speak=de/0/7/52qA5FttGIU;text=Wasser", pronunciationUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -23,6 +23,6 @@ public class BeolingusParserTest {
|
|||||||
String html = "<td><a href=\"/speak-de/0/7/52qA5FttGIU.mp3\">Mit Ihrem";
|
String html = "<td><a href=\"/speak-de/0/7/52qA5FttGIU.mp3\">Mit Ihrem";
|
||||||
|
|
||||||
String mp3 = BeolingusParser.getMp3AddressFromPronounciation(html);
|
String mp3 = BeolingusParser.getMp3AddressFromPronounciation(html);
|
||||||
assertEquals("http://dict.tu-chemnitz.de/speak-de/0/7/52qA5FttGIU.mp3", mp3);
|
assertEquals("https://dict.tu-chemnitz.de/speak-de/0/7/52qA5FttGIU.mp3", mp3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user