Code Monkey home page Code Monkey logo

java-radiodns's Introduction

java-radiodns

Introduction

A Java library that facilitates the resolution of an authoritative Fully Qualified Domain Name (FQDN) from the broadcast parameters of an audio service.

From this FQDN it is then possible to discover IP-based applications provided in relation to the queried audio service.

For more information about RadioDNS, please see the official documentation: http://radiodns.org/docs

Installation

Download radiodns-1.0.4.jar from the releases page and add it to your project.

The library depends on the dnsjava library.

Getting Started

Use the methods on RadioDNS to return a Service object for a given set of broadcast parameters. Use the Service object to resolve RadioDNS applications.

RadioDNS rdns = new RadioDNS();

Service service = rdns.lookupFMService("ce1", "c479", 95800);

Application application = service.getApplication(RadioDNS.RADIOVIS);

if (application != null) {
 
   Record record = application.getRecords().get(0);

   System.out.println(String.format("ApplicationId: %s Host: %s Port: %d Priority: %d Weight: %d",
        application.getApplicationId(), record.getTarget(), record.getPort(), record.getPriority(), record.getWeight()));

} else {
	System.out.println("No Results");
}

DNS Server

You can override the default DNS server to query by specifying the hostname in the RadioDNS constructor.

RadioDNS rdns = new RadioDNS("8.8.8.8");

License

Licensed under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2012 Global Radio UK Limited

java-radiodns's People

Contributors

byrion avatar jakechandrasakera avatar nickpiggott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-radiodns's Issues

Class RadioDNS contains declaration of RADIOEPG twice

  • @Version 1.0.3
    */
    public class RadioDNS {

    public static final String RADIOEPG = "radioepg";
    public static final String RADIOEPG = "radiospi";

Implementation of RADIOSPI seems not to be completed and radiodns-1.0.4.jar can't be integrated into project

Idea: get the service by ID

To simplify usage of the libary or would be great to have a function to filter the xml for the service of interest. Currently I need to do that:

HttpURLConnection conn = (HttpURLConnection) new URL(sSiUrl).openConnection();

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        XmlPullParser parser = factory.newPullParser();
        InputStream inputStream = conn.getInputStream();
        parser.setInput(inputStream, "UTF-8");

        List<StationImage> listStationImages = new ArrayList<>();

        boolean xmlFoundId = false;
        String xmlCurrentId = null;

        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
          if (eventType == XmlPullParser.START_TAG) {
            if ("service".equalsIgnoreCase(parser.getName())) {
              listStationImages.clear();
            } else if ("bearer".equalsIgnoreCase(parser.getName())) {
              String id = parser.getAttributeValue(null, "id");
              if (idToFind.equalsIgnoreCase(id)) xmlFoundId = true;
            } else if ("multimedia".equalsIgnoreCase(parser.getName())) {
              String mimeValueValue = parser.getAttributeValue(null, "mimeValue");
              String typeValue = parser.getAttributeValue(null, "type");
              String urlValue = parser.getAttributeValue(null, "url");
              if (urlValue != null) {
                // && ((mimeValueValue != null && mimeValueValue.toLowerCase().contains("image"))
                //    || (typeValue != null && typeValue.toLowerCase().contains("logo")))) {
                String widthValue = parser.getAttributeValue(null, "width");
                String heightValue = parser.getAttributeValue(null, "height");
                try {
                  int iWidth = Integer.valueOf(widthValue);
                  int iHeight = Integer.valueOf(heightValue);

                  StationImage stationImage = new StationImage(idToFind, urlValue, iWidth, iHeight);
                  listStationImages.add(stationImage);
                } catch (NumberFormatException ex1) {
                  continue;
                }
              }
            }
          } else if (eventType == XmlPullParser.END_TAG) {
            if ("service".equalsIgnoreCase(parser.getName())) {
              if (xmlFoundId) break;
            }
          }
          eventType = parser.next();
        }
        inputStream.close();

        if (listStationImages.size() == 0) {
          Logger.d(
              String.format(
                  "RadioDnsLogo: station image not found for id '%s' in '%s'", idToFind, sSiUrl));
          return RETURN_IMAGE_NOT_FOUND;
        }

Idea: Follow redirects

To simplify the usage of the libary it should be possible to get the result after following the redirects:

Currently I need to do that:

Record record = application.getRecords().get(0);
        sSiUrl = "http://" + record.getTarget().toString();
        if (sSiUrl.endsWith(".")) sSiUrl = sSiUrl.substring(0, sSiUrl.length() - 1);

        sSiUrl += ":" + record.getPort() + "/radiodns/spi/3.1/SI.xml";

sSiUrl = getUrlAfterRedirect(sSiUrl);
private String getUrlAfterRedirect(String url) throws IOException {
    HttpURLConnection conn;

    int redirect = 0;
    while (true) {
      if (redirect > 3) {
        Logger.d("RadioDnsLogo: Too many redirects!");
        return null;
      }
      URL base;
      try {
        base = new URL(url);
      } catch (MalformedURLException ex) {
        Logger.d(String.format("RadioDnsLogo: malformed url '%s'", url));
        return null;
      }

      conn = (HttpURLConnection) base.openConnection();
      switch (conn.getResponseCode()) {
        case HttpURLConnection.HTTP_MOVED_PERM:
        case HttpURLConnection.HTTP_MOVED_TEMP:
          String location = conn.getHeaderField("Location");
          location = URLDecoder.decode(location, "UTF-8");
          URL next;
          try {
            next = new URL(base, location); // Deal with relative URLs
          } catch (MalformedURLException ex) {
            Logger.d(
                String.format("RadioDnsLogo: malformed url base=%s location=%s", base, location));
            return null;
          }
          url = next.toExternalForm();
          redirect++;
          continue;
      }
      return url;
    }
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.