示例#1
0
  public ModelAndView wap(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    List<MusicFolder> folders = settingsService.getAllMusicFolders();

    if (folders.isEmpty()) {
      map.put("noMusic", true);
    } else {

      SortedMap<MusicIndex, SortedSet<MusicIndex.Artist>> allArtists =
          musicIndexService.getIndexedArtists(folders);

      // If an index is given as parameter, only show music files for this index.
      String index = request.getParameter("index");
      if (index != null) {
        SortedSet<MusicIndex.Artist> artists = allArtists.get(new MusicIndex(index));
        if (artists == null) {
          map.put("noMusic", true);
        } else {
          map.put("artists", artists);
        }
      }

      // Otherwise, list all indexes.
      else {
        map.put("indexes", allArtists.keySet());
      }
    }

    return new ModelAndView("wap/index", "model", map);
  }
示例#2
0
  public CacheDao() {

    File subsonicHome = SettingsService.getSubsonicHome();
    File dbDir = new File(subsonicHome, "cache");
    dbFile = new File(dbDir, "cache.dat");

    if (!dbDir.exists()) {
      dbDir.mkdirs();
    }

    //        if (dbFile.exists()) {
    //            try {
    //                Defragment.defrag(dbFile.getPath());
    //            }catch (IOException e) {
    //                e.printStackTrace();
    //            }
    //        }

    try {
      openDatabase(dbFile);
    } catch (Throwable x) {
      LOG.error("Failed to open " + dbFile + ", deleting it: " + x);

      dbFile.delete();
      openDatabase(dbFile);
    }
  }
示例#3
0
 private List<MediaFile> getMultiFolderChildren(List<MediaFile> mediaFiles) throws IOException {
   SortedSet<MediaFile> result =
       new TreeSet<MediaFile>(new MediaFileComparator(settingsService.isSortAlbumsByYear()));
   for (MediaFile mediaFile : mediaFiles) {
     if (mediaFile.isFile()) {
       mediaFile = mediaFileService.getParentOf(mediaFile);
     }
     result.addAll(mediaFileService.getChildrenOf(mediaFile, true, true, true));
   }
   return new ArrayList<MediaFile>(result);
 }
  private synchronized File getImageCacheDirectory(int size) {
    File dir = new File(SettingsService.getSubsonicHome(), "thumbs");
    dir = new File(dir, String.valueOf(size));
    if (!dir.exists()) {
      if (dir.mkdirs()) {
        LOG.info("Created thumbnail cache " + dir);
      } else {
        LOG.error("Failed to create thumbnail cache " + dir);
      }
    }

    return dir;
  }
  protected void doSubmitAction(Object cmd) throws Exception {
    NetworkSettingsCommand command = (NetworkSettingsCommand) cmd;

    settingsService.setPortForwardingEnabled(command.isPortForwardingEnabled());
    settingsService.setUrlRedirectionEnabled(command.isUrlRedirectionEnabled());
    settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom()));

    if (!settingsService.isLicenseValid() && settingsService.getUrlRedirectTrialExpires() == null) {
      Date expiryDate = new Date(System.currentTimeMillis() + TRIAL_DAYS * 24L * 3600L * 1000L);
      settingsService.setUrlRedirectTrialExpires(expiryDate);
    }

    if (settingsService.getServerId() == null) {
      Random rand = new Random(System.currentTimeMillis());
      settingsService.setServerId(String.valueOf(Math.abs(rand.nextLong())));
    }

    settingsService.save();
    networkService.initPortForwarding();
    networkService.initUrlRedirection(true);
  }
示例#6
0
  private void setSieblingAlbums(MediaFile dir, Map<String, Object> map) throws IOException {
    MediaFile parent = mediaFileService.getParentOf(dir);

    if (dir.isAlbum() && !mediaFileService.isRoot(parent)) {
      List<MediaFile> sieblings = mediaFileService.getChildrenOf(parent, false, true, true);
      sieblings.remove(dir);

      int limit = settingsService.getCoverArtLimit();
      if (limit == 0) {
        limit = Integer.MAX_VALUE;
      }
      if (sieblings.size() > limit) {
        sieblings = sieblings.subList(0, limit);
      }
      map.put("sieblingAlbums", sieblings);
    }
  }
示例#7
0
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    Player player = playerService.getPlayer(request, response);

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("user", user);
    map.put("player", player);
    map.put("players", playerService.getPlayersForUserAndClientId(user.getUsername(), null));
    map.put("visibility", userSettings.getPlaylistVisibility());
    map.put("partyMode", userSettings.isPartyModeEnabled());
    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
  }
  private List<Entry> getEntries(Share share, Player player) throws IOException {
    List<Entry> result = new ArrayList<Entry>();
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(player.getUsername());

    if (share != null) {
      for (MediaFile file : shareService.getSharedFiles(share.getId(), musicFolders)) {
        if (file.getFile().exists()) {
          if (file.isDirectory()) {
            for (MediaFile child : mediaFileService.getChildrenOf(file, true, false, true)) {
              result.add(createEntry(child, player));
            }
          } else {
            result.add(createEntry(file, player));
          }
        }
      }
    }
    return result;
  }
  protected Object formBackingObject(HttpServletRequest request) throws Exception {
    NetworkSettingsCommand command = new NetworkSettingsCommand();
    command.setPortForwardingEnabled(settingsService.isPortForwardingEnabled());
    command.setUrlRedirectionEnabled(settingsService.isUrlRedirectionEnabled());
    command.setUrlRedirectFrom(settingsService.getUrlRedirectFrom());
    command.setPort(settingsService.getPort());

    Date trialExpires = settingsService.getUrlRedirectTrialExpires();
    command.setTrialExpires(trialExpires);
    command.setTrialExpired(trialExpires != null && trialExpires.before(new Date()));
    command.setTrial(trialExpires != null && !settingsService.isLicenseValid());

    return command;
  }
示例#10
0
  private List<MediaFile> getCoverArts(MediaFile dir, List<MediaFile> children) throws IOException {
    int limit = settingsService.getCoverArtLimit();
    if (limit == 0) {
      limit = Integer.MAX_VALUE;
    }

    List<MediaFile> coverArts = new ArrayList<MediaFile>();
    if (dir.isAlbum()) {
      coverArts.add(dir);
    } else {
      for (MediaFile child : children) {
        if (child.isAlbum()) {
          coverArts.add(child);
          if (coverArts.size() >= limit) {
            break;
          }
        }
      }
    }
    return coverArts;
  }
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    String pathInfo = request.getPathInfo();

    if (pathInfo == null || !pathInfo.startsWith("/")) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return null;
    }

    Share share = shareService.getShareByName(pathInfo.substring(1));

    if (share != null && share.getExpires() != null && share.getExpires().before(new Date())) {
      share = null;
    }

    if (share != null) {
      share.setLastVisited(new Date());
      share.setVisitCount(share.getVisitCount() + 1);
      shareService.updateShare(share);
    }

    Player player = playerService.getGuestPlayer(request);

    map.put("share", share);
    map.put("entries", getEntries(share, player));
    map.put("redirectUrl", settingsService.getUrlRedirectUrl());
    map.put("player", player.getId());

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
  }
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    //	String id = request.getParameter("id");
    //  MediaFile mediaFile = mediaFileService.getMediaFile(path);

    int listOffset = DEFAULT_LIST_OFFSET;
    int listSize = DEFAULT_LIST_SIZE;
    String listType = DEFAULT_LIST_TYPE;

    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    int userGroupId = securityService.getCurrentUserGroupId(request);

    if (request.getParameter("listOffset") != null) {
      listOffset =
          Math.max(
              0, Math.min(Integer.parseInt(request.getParameter("listOffset")), MAX_LIST_OFFSET));
    }

    if (request.getParameter("listSize") != null) {
      listSize =
          Math.max(0, Math.min(Integer.parseInt(request.getParameter("listSize")), MAX_LIST_SIZE));
    }

    if (request.getParameter("listType") != null) {
      listType = String.valueOf(request.getParameter("listType"));
    }
    List<MediaFile> songs;
    if ("topplayed".equals(listType)) {
      songs = mediaFileDao.getTopPlayedCountForUser(listOffset, listSize, username);
    } else if ("otheruser".equals(listType)) {
      songs = mediaFileDao.getLastPlayedCountForAllUser(listOffset, listSize, userGroupId);
    } else if ("overall".equals(listType)) {
      songs = mediaFileDao.getTopPlayedCountForAllUser(listOffset, listSize, userGroupId);
    } else if ("lastplayed".equals(listType)) {
      songs = mediaFileDao.getLastPlayedCountForUser(listOffset, listSize, username);
    } else {
      songs = mediaFileDao.getLastPlayedCountForAllUser(0, 1, userGroupId);
    }

    mediaFileService.populateStarredDate(songs, username);
    map.put("user", user);
    map.put("songs", songs);

    map.put("partyModeEnabled", userSettings.isPartyModeEnabled());
    map.put("player", playerService.getPlayer(request, response));

    map.put("listOffset", listOffset);
    map.put("listSize", listSize);
    map.put("listType", listType);

    //  map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null);

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
  }
示例#13
0
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();

    Player player = playerService.getPlayer(request, response);
    List<MediaFile> mediaFiles = getMediaFiles(request);

    if (mediaFiles.isEmpty()) {
      return new ModelAndView(new RedirectView("notFound.view"));
    }

    MediaFile dir = mediaFiles.get(0);
    if (dir.isFile()) {
      dir = mediaFileService.getParentOf(dir);
    }

    // Redirect if root directory.
    if (mediaFileService.isRoot(dir)) {
      return new ModelAndView(new RedirectView("home.view?"));
    }

    List<MediaFile> children =
        mediaFiles.size() == 1
            ? mediaFileService.getChildrenOf(dir, true, true, true)
            : getMultiFolderChildren(mediaFiles);
    String username = securityService.getCurrentUsername(request);
    UserSettings userSettings = settingsService.getUserSettings(username);

    mediaFileService.populateStarredDate(dir, username);
    mediaFileService.populateStarredDate(children, username);

    map.put("dir", dir);
    map.put("ancestors", getAncestors(dir));
    map.put("children", children);
    map.put("artist", guessArtist(children));
    map.put("album", guessAlbum(children));
    map.put("player", player);
    map.put("sieblingCoverArtScheme", CoverArtScheme.SMALL);
    map.put("user", securityService.getCurrentUser(request));
    map.put("visibility", userSettings.getMainVisibility());
    map.put("showAlbumYear", settingsService.isSortAlbumsByYear());
    map.put("updateNowPlaying", request.getParameter("updateNowPlaying") != null);
    map.put("partyMode", userSettings.isPartyModeEnabled());
    map.put("brand", settingsService.getBrand());

    try {
      MediaFile parent = mediaFileService.getParentOf(dir);
      map.put("parent", parent);
      map.put("navigateUpAllowed", !mediaFileService.isRoot(parent));
    } catch (SecurityException x) {
      // Happens if Podcast directory is outside music folder.
    }

    Integer userRating = ratingService.getRatingForUser(username, dir);
    Double averageRating = ratingService.getAverageRating(dir);

    if (userRating == null) {
      userRating = 0;
    }

    if (averageRating == null) {
      averageRating = 0.0D;
    }

    map.put("userRating", 10 * userRating);
    map.put("averageRating", Math.round(10.0D * averageRating));
    map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null);

    CoverArtScheme scheme = player.getCoverArtScheme();
    if (scheme != CoverArtScheme.OFF) {
      List<MediaFile> coverArts = getCoverArts(dir, children);
      map.put("coverArts", coverArts);
      setSieblingAlbums(dir, map);
    }

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
  }