Search in sources :

Example 1 with MusicFolder

use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.

the class MediaScannerServiceTestCase method testSpecialCharactersInFilename.

@Test
public void testSpecialCharactersInFilename() throws Exception {
    Resource resource = resourceLoader.getResource("MEDIAS/piano.mp3");
    String directoryName = "Muff1nman’s /Music";
    String fileName = "Muff1nman’s/Piano.mp3";
    File artistDir = temporaryFolder.newFolder(directoryName);
    File musicFile = artistDir.toPath().resolve(fileName).toFile();
    IOUtils.copy(resource.getInputStream(), new FileOutputStream(musicFile));
    MusicFolder musicFolder = new MusicFolder(1, temporaryFolder.getRoot(), "Music", true, new Date());
    musicFolderDao.createMusicFolder(musicFolder);
    settingsService.clearMusicFolderCache();
    TestCaseUtils.execScan(mediaScannerService);
    MediaFile mediaFile = mediaFileService.getMediaFile(musicFile);
    assertEquals(mediaFile.getFile().toString(), musicFile.toString());
    System.out.println(mediaFile.getFile().getPath());
    assertNotNull(mediaFile);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) FileOutputStream(java.io.FileOutputStream) Resource(org.springframework.core.io.Resource) MediaFile(org.libresonic.player.domain.MediaFile) File(java.io.File) MusicFolder(org.libresonic.player.domain.MusicFolder) Date(java.util.Date) Test(org.junit.Test)

Example 2 with MusicFolder

use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.

the class MusicFolderDaoTestCase method testUpdateMusicFolder.

@Test
public void testUpdateMusicFolder() {
    MusicFolder musicFolder = new MusicFolder(new File("path"), "name", true, new Date());
    musicFolderDao.createMusicFolder(musicFolder);
    musicFolder = musicFolderDao.getAllMusicFolders().get(0);
    musicFolder.setPath(new File("newPath"));
    musicFolder.setName("newName");
    musicFolder.setEnabled(false);
    musicFolder.setChanged(new Date(234234L));
    musicFolderDao.updateMusicFolder(musicFolder);
    MusicFolder newMusicFolder = musicFolderDao.getAllMusicFolders().get(0);
    assertMusicFolderEquals(musicFolder, newMusicFolder);
}
Also used : MusicFolder(org.libresonic.player.domain.MusicFolder) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 3 with MusicFolder

use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.

the class MusicFolderTestData method getTestMusicFolders.

public static List<MusicFolder> getTestMusicFolders() {
    List<MusicFolder> liste = new ArrayList<>();
    File musicDir = new File(MusicFolderTestData.resolveMusicFolderPath());
    MusicFolder musicFolder = new MusicFolder(1, musicDir, "Music", true, new Date());
    liste.add(musicFolder);
    File music2Dir = new File(MusicFolderTestData.resolveMusic2FolderPath());
    MusicFolder musicFolder2 = new MusicFolder(2, music2Dir, "Music2", true, new Date());
    liste.add(musicFolder2);
    return liste;
}
Also used : ArrayList(java.util.ArrayList) MusicFolder(org.libresonic.player.domain.MusicFolder) File(java.io.File) Date(java.util.Date)

Example 4 with MusicFolder

use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.

the class MoreController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();
    User user = securityService.getCurrentUser(request);
    String uploadDirectory = null;
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    if (musicFolders.size() > 0) {
        uploadDirectory = new File(musicFolders.get(0).getPath(), "Incoming").getPath();
    }
    StringBuilder jamstashUrl = new StringBuilder("http://jamstash.com/#/settings?u=" + StringUtil.urlEncode(user.getUsername()) + "&url=");
    jamstashUrl.append(StringUtil.urlEncode(NetworkService.getBaseUrl(request)));
    Player player = playerService.getPlayer(request, response);
    ModelAndView result = new ModelAndView();
    result.addObject("model", map);
    map.put("user", user);
    map.put("uploadDirectory", uploadDirectory);
    map.put("genres", mediaFileService.getGenres(false));
    map.put("currentYear", Calendar.getInstance().get(Calendar.YEAR));
    map.put("musicFolders", musicFolders);
    map.put("clientSidePlaylist", player.isExternalWithPlaylist() || player.isWeb());
    map.put("brand", settingsService.getBrand());
    map.put("jamstashUrl", jamstashUrl);
    return result;
}
Also used : Player(org.libresonic.player.domain.Player) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) MusicFolder(org.libresonic.player.domain.MusicFolder) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with MusicFolder

use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.

the class RESTController method getArtists.

@RequestMapping(value = "/rest/getArtists", method = { RequestMethod.GET, RequestMethod.POST })
public void getArtists(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    ArtistsID3 result = new ArtistsID3();
    result.setIgnoredArticles(settingsService.getIgnoredArticles());
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<Artist> artists = artistDao.getAlphabetialArtists(0, Integer.MAX_VALUE, musicFolders);
    SortedMap<MusicIndex, List<MusicIndex.SortableArtistWithArtist>> indexedArtists = musicIndexService.getIndexedArtists(artists);
    for (Map.Entry<MusicIndex, List<MusicIndex.SortableArtistWithArtist>> entry : indexedArtists.entrySet()) {
        IndexID3 index = new IndexID3();
        result.getIndex().add(index);
        index.setName(entry.getKey().getIndex());
        for (MusicIndex.SortableArtistWithArtist sortableArtist : entry.getValue()) {
            index.getArtist().add(createJaxbArtist(new ArtistID3(), sortableArtist.getArtist(), username));
        }
    }
    Response res = createResponse();
    res.setArtists(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : Artist(org.libresonic.player.domain.Artist) MusicFolder(org.libresonic.player.domain.MusicFolder) HttpServletResponse(javax.servlet.http.HttpServletResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MusicFolder (org.libresonic.player.domain.MusicFolder)37 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 HttpServletResponse (javax.servlet.http.HttpServletResponse)21 Artist (org.libresonic.player.domain.Artist)7 File (java.io.File)6 org.libresonic.restapi (org.libresonic.restapi)6 Date (java.util.Date)5 MediaFile (org.libresonic.player.domain.MediaFile)5 User (org.libresonic.player.domain.User)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 SearchResult (org.libresonic.player.domain.SearchResult)3 Share (org.libresonic.player.domain.Share)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 FileOutputStream (java.io.FileOutputStream)1 DateFormat (java.text.DateFormat)1 HashMap (java.util.HashMap)1 MusicFolderSettingsCommand (org.libresonic.player.command.MusicFolderSettingsCommand)1 Player (org.libresonic.player.domain.Player)1