Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8286f3d authored by Michael W's avatar Michael W
Browse files

Dialer: Lookup: Fix Das Telefonbuch

* Since both, the URL and the website content have changed, we need to
  adapt to parse the content properly
* Also add the real website to the result if it exists, otherwise keep
  the lookup URL

Change-Id: Id428d3a8c6e6758f371fd122b1d54ab24349b2bc
parent 2061ebb1
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -27,12 +27,14 @@ public class TelefonbuchApi {
  private static final String TAG = TelefonbuchApi.class.getSimpleName();

  private static final String REVERSE_LOOKUP_URL =
      "https://www.dastelefonbuch.de/?s=a20000" +
      "&cmd=search&sort_ok=0&sp=55&vert_ok=0&aktion=23";
          "https://www.dastelefonbuch.de/R%C3%BCckw%C3%A4rts-Suche/";

  private static String NAME_REGEX ="<a id=\"name0.*?>\\s*\n?(.*?)\n?\\s*</a>";
  private static String NUMBER_REGEX = "<span\\s+class=\"ico fon.*>.*<span>(.*?)</span><br/>";
  private static String RELEVANT_CONTENT_REGEX =
          "<div class=\"vcard\">(.*)<div class=\"additional\">";
  private static String NAME_REGEX ="<div class=\"name\" title=\"(.*?)\">";
  private static String NUMBER_REGEX = "<!-- phoneTo: (.*?) -->";
  private static String ADDRESS_REGEX = "<address.*?>\n?(.*?)</address>";
  private static String WEBSITE_REGEX = "<div.*class=\"url\">.*<a.*?href=\"(.*?)\"";

  private TelefonbuchApi() {
  }
@@ -40,12 +42,12 @@ public class TelefonbuchApi {
  public static ContactInfo reverseLookup(Context context, String number) throws IOException {
    Uri uri = Uri.parse(REVERSE_LOOKUP_URL)
            .buildUpon()
        .appendQueryParameter("kw", number)
            .appendPath(number)
            .build();
    // Cut out everything we're not interested in (scripts etc.) to
    // speed up the subsequent matching.
    String output = LookupUtils.firstRegexResult(
        LookupUtils.httpGet(uri.toString(), null), ": Treffer(.*)Ende Treffer", true);
            LookupUtils.httpGet(uri.toString(), null), RELEVANT_CONTENT_REGEX, true);

    String name = parseValue(output, NAME_REGEX, true, false);
    if (name == null) {
@@ -54,12 +56,13 @@ public class TelefonbuchApi {

    String phoneNumber = parseValue(output, NUMBER_REGEX, false, true);
    String address = parseValue(output, ADDRESS_REGEX, true, true);
    String website = parseValue(output, WEBSITE_REGEX, true, false);

    ContactInfo info = new ContactInfo();
    info.name = name;
    info.address = address;
    info.formattedNumber = phoneNumber != null ? phoneNumber : number;
    info.website = uri.toString();
    info.website = website != null ? website : uri.toString();

    return info;
  }