public void setSongDownloading(ArchiveSongObj song, long id) {
   Logging.Log(LOG_TAG, "Start Downloading " + song.getFileName() + ": " + id);
   db.execSQL(
       "UPDATE songTbl "
           + "SET download_id = '"
           + id
           + "' WHERE fileName = '"
           + song.getFileName()
           + "'");
 }
 public boolean getSongIsDownloading(ArchiveSongObj song) {
   Logging.Log(LOG_TAG, "Get downloading status for " + song.getFileName());
   Cursor cur =
       db.rawQuery(
           "Select count(1) as count from songTbl "
               + "where fileName = '"
               + song.getFileName()
               + "' and download_id is not null and isDownloaded = 'false'",
           null);
   cur.moveToFirst();
   int count = cur.getInt(cur.getColumnIndex("count"));
   Logging.Log(LOG_TAG, "Result: " + count);
   cur.close();
   return count > 0;
 }
 public void addSongToNowPlaying(ArchiveSongObj s) {
   db.execSQL(
       "INSERT INTO playlistSongsTbl(playlist_id,song_id,trackNum) "
           + "Select 0,"
           + s.getID()
           + ",MAX(trackNum) "
           + "from playlistSongsTbl where playlist_id = 0");
 }
  public void setNowPlayingSongs(ArrayList<ArchiveSongObj> songs) {
    clearNowPlayingSongs();
    if (songs.size() > 0) {
      StringBuilder sql = new StringBuilder();
      sql.append("INSERT INTO playlistSongsTbl(playlist_id,song_id,trackNum)");

      int index = 0;
      for (ArchiveSongObj s : songs) {
        sql.append("SELECT 0," + s.getID() + "," + index + " ");
        if (index < songs.size() - 1) {
          sql.append("UNION ALL ");
          index++;
        }
      }
      db.execSQL(sql.toString());
    }
  }
 public void setSongDeleted(ArchiveSongObj song) {
   db.execSQL(
       "UPDATE songTbl "
           + "SET isDownloaded = 'false', download_id = null "
           + "WHERE fileName = '"
           + song.getFileName()
           + "'");
 }
 public int insertSong(ArchiveSongObj song) {
   db.execSQL(
       "INSERT INTO songTbl(fileName,songTitle,show_id,isDownloaded,folderName) "
           + "SELECT '"
           + song.getFileName()
           + "','"
           + song.toString().replaceAll("'", "''")
           + "',show._id,'false','' "
           + "FROM showTbl show "
           + "WHERE show.showIdent = '"
           + song.getShowIdentifier()
           + "' "
           + "AND NOT EXISTS (SELECT 1 FROM songTbl song WHERE song.fileName = '"
           + song.getFileName()
           + "')");
   Cursor cur =
       db.rawQuery(
           "Select _id as song_id from songTbl " + "where fileName = '" + song.getFileName() + "'",
           null);
   cur.moveToFirst();
   int id = cur.getInt(cur.getColumnIndex(PLAYLISTSONG_SONG_KEY));
   cur.close();
   if (song.hasFolder()) {
     db.execSQL("Update songTbl set folderName = '" + song.getFolder() + "' where _id = " + id);
   }
   return id;
 }
 public void insertKnownSongIntoPlaylist(int playlist_id, ArchiveSongObj song, int position) {
   if (playlist_id <= 0) {
     // Playlist not saved yet
     return;
   }
   db.execSQL(
       "INSERT INTO playlistSongsTbl(playlist_id,song_id,trackNum) "
           + "SELECT "
           + playlist_id
           + ",song._id,"
           + position
           + " FROM songTbl song "
           + "WHERE song.fileName = '"
           + song.getFileName()
           + "'");
 }
Ejemplo n.º 8
0
  public static void getSongs(
      ArchiveShowObj show,
      ArrayList<ArchiveSongObj> songs,
      StaticDataStore db,
      boolean processSongs) {

    HtmlCleaner pageParser = new HtmlCleaner();
    CleanerProperties props = pageParser.getProperties();
    props.setAllowHtmlInsideAttributes(true);
    props.setAllowMultiWordAttributes(true);
    props.setRecognizeUnicodeChars(true);
    props.setOmitComments(true);

    ArrayList<String> songLinks = new ArrayList<String>();
    ArrayList<String> songTitles = new ArrayList<String>();
    String showTitle = show.getArtistAndTitle();
    String showIdent = show.getIdentifier();

    // XPATH says "Select out of all 'table' elements with attribute 'class'
    // equal to 'fileFormats' which contain element 'tr'..."
    // String songXPath = "//table[@class='fileFormats']//tr";

    // XPATH says "Select out of all 'script' elements with attribute 'type'
    // equal to 'text/javascript'..."
    String m3uXPath = "//script";
    String titlePath = "//head//title";

    if (db.getShowExists(show) && processSongs) {

      songs.addAll(db.getSongsFromShow(show.getIdentifier()));
      show.setFullTitle(db.getShow(show.getIdentifier()).getArtistAndTitle());
      return;
    }

    try {
      HttpParams params = new BasicHttpParams();
      int timeout = (int) (15 * DateUtils.SECOND_IN_MILLIS);
      HttpConnectionParams.setConnectionTimeout(params, timeout);
      HttpConnectionParams.setSoTimeout(params, timeout);
      HttpClient client = new DefaultHttpClient(params);

      HttpGet page = new HttpGet(show.getShowURL().toString());
      HttpResponse pageResponse = client.execute(page);
      StatusLine pageStatus = pageResponse.getStatusLine();
      if (pageStatus.getStatusCode() == HttpStatus.SC_OK) {
        ResponseHandler<String> pageResponseHandler = new BasicResponseHandler();
        TagNode node = pageParser.clean(pageResponseHandler.handleResponse(pageResponse));

        String queryString = show.getLinkPrefix();

        if (db.getPref("downloadFormat").equalsIgnoreCase("LBR")) {
          if (show.hasLBR()) {
            queryString += "_64kb.m3u";
          } else if (show.hasVBR()) {
            queryString += "_vbr.m3u";
          }
        } else {
          if (show.hasVBR()) {
            queryString += "_vbr.m3u";
          } else if (show.hasLBR()) {
            queryString += "_64kb.m3u";
          }
        }

        HttpGet M3Urequest = new HttpGet(queryString);

        HttpResponse M3Uresponse = client.execute(M3Urequest);
        StatusLine M3Ustatus = M3Uresponse.getStatusLine();
        if (M3Ustatus.getStatusCode() == HttpStatus.SC_OK) {
          ResponseHandler<String> M3UresponseHandler = new BasicResponseHandler();
          String m3uString = M3UresponseHandler.handleResponse(M3Uresponse);

          client.getConnectionManager().shutdown();

          // Now split the .M3U file based on newlines. This will give
          // us the download links, which we store..

          String m3uLinks[] = m3uString.split("\n");
          for (String link : m3uLinks) {
            songLinks.add(link);
          }

          // Now use an XPATH evaluation to find all of the javascript scripts on the page.
          // If one of them can be split by "IAD.mrss = ", it should have the track names
          // in it. The second half of the split is valid javascript and can be interpreted,
          // therefore, as JSON. Pull the song titles out of that, and together with the
          // download links make ArchiveSongObjs and add them to the list of songs.
          Object[] titleNodes = node.evaluateXPath(m3uXPath);
          for (Object titleNode : titleNodes) {
            //
            List x = ((TagNode) titleNode).getChildren();
            String songTitle = "";
            for (Object y : x) {
              if (y instanceof ContentNode) {
                songTitle = ((ContentNode) y).toString();
                songTitle = songTitle.trim();
                if (songTitle.startsWith("Play(")) {
                  String[] titles = songTitle.split("\\{\"title\"");
                  for (int i = 1; i < titles.length; i++) {
                    try {
                      String title =
                          titles[i].substring(
                              nthIndexOf(titles[i], '"', 1), nthIndexOf(titles[i], '"', 2));
                      songTitles.add(title.substring(title.indexOf('.') + 2));
                    } catch (StringIndexOutOfBoundsException e) {
                    }
                  }
                }
              }
            }
          }
          if (show.getShowTitle().length() < 2) {

            String s =
                ((TagNode) node.evaluateXPath(titlePath)[0])
                    .getChildren()
                    .toString()
                    .replaceFirst(Pattern.quote("["), "");
            show.setFullTitle(s.substring(0, s.lastIndexOf(": Free") - 1));
            showTitle = show.getArtistAndTitle();
            db.updateShow(show);
          }

          if (processSongs) {
            if (songLinks.size() == 0) {

            } else {
              // Do things for successful show parse
              db.insertShow(show);
            }
            // If we have the same amount of song titles as song links,
            // we should be all set.
            if (songTitles.size() == songLinks.size()) {
              for (int i = 0; i < songTitles.size(); i++) {
                String songLink = songLinks.get(i);
                String songTitle = songTitles.get(i);
                // If the show has a "selectedSong"
                // meaning that it was opened by
                // the user clicking on a song link, do
                // a comparison to see
                // if the song being added is the
                // selected song. If it is, set
                // selectedPos to the right index so
                // that the song can be played
                // once the ListView is filled.  This is
                // inefficient, though it probably doesn't make a difference,
                // but we might consider making this a bit more efficient/elegant in the future.
                // FIXME.
                //						if (show.hasSelectedSong()) {
                //							if (songLink.equals(show.getSelectedSong())) {
                //								selectedPos = i;
                //							}
                //						} else {
                //							selectedPos = -1;
                //						}
                ArchiveSongObj song = new ArchiveSongObj(songTitle, songLink, showTitle, showIdent);
                song.setID(db.insertSong(song));
                songs.add(song);
              }
              db.setShowExists(show);
              db.insertRecentShow(show);
            } else {

            }
          }

        } else {
          client.getConnectionManager().shutdown();
        }
      } else {
        client.getConnectionManager().shutdown();
      }

    } catch (XPatherException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // TODO Auto-generated method stub

  }