Beispiel #1
0
  public static Song infoParser(String songId) throws Exception {
    int songid = Integer.parseInt(songId);
    String musicDetailPageUrl = musicDetailPageUrlExtract(songId);
    Song song = new Song();
    List<String> styleList = new ArrayList<String>();
    List<String> genreList = new ArrayList<String>();
    List<String> artistList = new ArrayList<String>();
    Element songDetailSource = extractFromClassName(musicDetailPageUrl, "soBox2", 0);
    String songName =
        extractFromClassName(musicDetailPageUrl, "titT", 0)
            .getContent()
            .getTextExtractor()
            .toString();
    String date =
        songDetailSource
            .getAllElements(HTMLElementName.DD)
            .get(0)
            .getContent()
            .getTextExtractor()
            .toString();
    String videoUrl = null;
    YouTubeManager ym = new YouTubeManager("m2music");

    try {
      String genre =
          songDetailSource
              .getAllElements(HTMLElementName.DD)
              .get(1)
              .getContent()
              .getTextExtractor()
              .toString();
      StringTokenizer st1 = new StringTokenizer(genre, "/");
      while (st1.hasMoreElements()) {
        genreList.add(st1.nextToken().trim());
      }
    } catch (IndexOutOfBoundsException e) {
      styleList.add("none");
    }
    try {
      String style =
          songDetailSource
              .getAllElements(HTMLElementName.DD)
              .get(2)
              .getContent()
              .getTextExtractor()
              .toString();
      StringTokenizer st = new StringTokenizer(style, ",");
      while (st.hasMoreElements()) {
        styleList.add(st.nextToken().trim());
      }
    } catch (IndexOutOfBoundsException e) {
      styleList.add("none");
    }

    try {
      String artist =
          extractFromClassName(musicDetailPageUrl, "soTit", 1)
              .getContent()
              .getTextExtractor()
              .toString();
      StringTokenizer st2 = new StringTokenizer(artist, ",");
      while (st2.hasMoreElements()) {
        artistList.add(st2.nextToken().trim());
      }
    } catch (IndexOutOfBoundsException e) {
      styleList.add("none");
    }
    try {
      videoUrl =
          ym.retrieveVideos(songName + "+" + artistList.get(0), 1).get(0).getEmbeddedWebPlayerUrl();

    } catch (IndexOutOfBoundsException e) {
      if (ym.retrieveVideos(songName, 1).isEmpty()) {
        videoUrl = null;
      } else {
        videoUrl = ym.retrieveVideos(songName, 1).get(0).getEmbeddedWebPlayerUrl();
      }
    }

    song.setDate(date);
    song.setSongid(songid);
    song.setSongname(songName);
    song.setArtistList(artistList);
    song.setGenreList(genreList);
    song.setStyleList(styleList);
    song.setVideourl(videoUrl);

    outTest(songName, artistList, date, genreList, styleList, songId, videoUrl);
    return song;
  }