Exemple #1
0
  /**
   * this action allows you to give the path of a track on disk, and it will be resolved to the
   * tracks internal ID. this can then be used normally for playing music. the path coming in is
   * assumed to have forward slashes to delimit path components, but this needs to be converted to
   * whatever the actual path separator is for the current system BEFORE we try and query the
   * database, otherwise, well, it just won't work.
   *
   * <p>NB! ATM, this feature is only here for the the folder browsing stuff, so if that's not
   * turned on this this won't work.
   */
  protected void resolvePath() throws BadRequestException, SQLException, IOException {

    // check folder browsing is enabled
    Utils.checkFeatureEnabled(getProperties(), "browse.folders.enabled");

    ResultSet rs = null;
    PreparedStatement st = null;

    try {

      final Database db = getDatabase();
      final Locale locale = getLocale();
      final Request req = getRequest();
      final String path = convertPath(req.getArgument("path"));
      final String sql = Track.getSelectFromSql() + " where t.path = ? ";

      st = db.prepare(sql);
      st.setString(1, path);
      rs = st.executeQuery();

      if (!rs.next())
        throw new BadRequestException(locale.getString("www.error.trackNotFound"), 404);

      final Track track = Track.createFromResultSet(rs);
      final TResolvePath tpl = new TResolvePath();

      tpl.setTrack(track);
      getResponse().showJson(tpl.makeRenderer());

    } finally {
      Utils.close(rs);
      Utils.close(st);
    }
  }
Exemple #2
0
  /**
   * given some url arguments (ar123, al456, etc...) queries for the tracks that belong to these
   * items
   *
   * @throws java.io.IOException
   * @throws java.sql.SQLException
   * @throws com.pugh.sockso.web.BadRequestException
   */
  protected void tracks() throws IOException, SQLException, BadRequestException {

    final Request req = getRequest();
    final List<Track> tracks = Track.getTracksFromPlayArgs(getDatabase(), req.getPlayParams(true));

    showTracks(tracks);
  }
Exemple #3
0
  /**
   * saves a playlist to the database for the current user. outputs a single integer which is the
   * playlist ID if all goes well, otherwise you'll get a description of the problem.
   *
   * @throws IOException
   */
  protected void savePlaylist() throws IOException, SQLException, BadRequestException {

    final Request req = getRequest();
    final User user = getUser();
    final Locale locale = getLocale();
    final String name = req.getUrlParam(2).trim();
    final String[] args = req.getPlayParams(2);

    String result = locale.getString("www.json.error.unknown");

    // make sure data is ok first
    if (name.equals("")) result = locale.getString("www.json.error.noName");
    else if (args.length == 0) result = locale.getString("www.json.error.noArguments");
    else if (user == null) result = locale.getString("www.json.error.notLoggedIn");
    else {

      final Database db = getDatabase();
      final List<Track> vTracks = Track.getTracksFromPlayArgs(db, args);
      final Track[] tracks = new Track[vTracks.size()];

      for (int i = 0; i < vTracks.size(); i++) tracks[i] = vTracks.get(i);

      result = Integer.toString(cm.savePlaylist(name, tracks, user));
    }

    final TString tpl = new TString();
    tpl.setResult(result);
    getResponse().showJson(tpl.makeRenderer());
  }
Exemple #4
0
  /**
   * fetches the tracks from an album
   *
   * @param albumId
   * @return
   * @throws java.sql.SQLException
   */
  protected Vector<Track> getAlbumTracks(final int albumId) throws SQLException {

    ResultSet rs = null;
    PreparedStatement st = null;

    try {

      final Database db = getDatabase();
      final String sql =
          Track.getSelectFromSql() + " where t.album_id = ? " + " order by t.track_no asc ";
      st = db.prepare(sql);
      st.setInt(1, albumId);
      rs = st.executeQuery();

      return Track.createVectorFromResultSet(rs);

    } finally {
      Utils.close(rs);
      Utils.close(st);
    }
  }
Exemple #5
0
  public void testShowLatest() throws Exception {

    final TestResponse res = new TestResponse();
    final Latester b = new Latester();
    final Vector<Track> tracks = new Vector<Track>();
    final Vector<Artist> artists = new Vector<Artist>();
    final Vector<Album> albums = new Vector<Album>();
    final Artist artist = new Artist(1, "my artist");
    final Album album = new Album(artist, 1, "my album");
    final Track track = new Track(artist, null, 1, "my track", "", 1, null);

    tracks.add(track);
    artists.add(artist);
    albums.add(album);

    b.setResponse(res);
    b.showLatest(tracks, artists, albums);

    final String data = res.getOutput();

    assertTrue(data.contains(artist.getName()));
    assertTrue(data.contains(track.getName()));
  }
Exemple #6
0
  /**
   * this method outputs the tracks that lie below a given path
   *
   * @throws com.pugh.sockso.web.BadRequestException
   * @throws java.sql.SQLException
   * @throws java.io.IOException
   */
  protected void tracksForPath() throws BadRequestException, SQLException, IOException {

    Utils.checkFeatureEnabled(getProperties(), Constants.WWW_BROWSE_FOLDERS_ENABLED);

    ResultSet rs = null;
    PreparedStatement st = null;

    try {

      final Database db = getDatabase();
      final Request req = getRequest();
      final String path = req.getArgument("path");

      final TTracksForPath tpl = new TTracksForPath();
      tpl.setTracks(Track.getTracksFromPath(db, path));
      getResponse().showJson(tpl.makeRenderer());

    } finally {
      Utils.close(rs);
      Utils.close(st);
    }
  }