Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: get the service by ID #4

Open
TorstenH82 opened this issue Apr 24, 2024 · 0 comments
Open

Idea: get the service by ID #4

TorstenH82 opened this issue Apr 24, 2024 · 0 comments

Comments

@TorstenH82
Copy link

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;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant