Search in sources :

Example 21 with MediaFile

use of org.libresonic.player.domain.MediaFile 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 22 with MediaFile

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

the class VideoPlayerController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = securityService.getCurrentUser(request);
    Map<String, Object> map = new HashMap<String, Object>();
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    MediaFile file = mediaFileService.getMediaFile(id);
    mediaFileService.populateStarredDate(file, user.getUsername());
    Integer duration = file.getDurationSeconds();
    String playerId = playerService.getPlayer(request, response).getId();
    String url = NetworkService.getBaseUrl(request);
    String streamUrl = url + "/stream?id=" + file.getId() + "&player=" + playerId;
    String coverArtUrl = url + "/coverArt.view?id=" + file.getId();
    map.put("video", file);
    map.put("streamUrl", streamUrl);
    map.put("remoteStreamUrl", streamUrl);
    map.put("remoteCoverArtUrl", coverArtUrl);
    map.put("duration", duration);
    map.put("bitRates", BIT_RATES);
    map.put("defaultBitRate", DEFAULT_BIT_RATE);
    map.put("user", user);
    return new ModelAndView("videoPlayer", "model", map);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with MediaFile

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

the class PlaylistDao method setFilesInPlaylist.

public void setFilesInPlaylist(int id, List<MediaFile> files) {
    update("delete from playlist_file where playlist_id=?", id);
    int duration = 0;
    for (MediaFile file : files) {
        update("insert into playlist_file (playlist_id, media_file_id) values (?, ?)", id, file.getId());
        if (file.getDurationSeconds() != null) {
            duration += file.getDurationSeconds();
        }
    }
    update("update playlist set file_count=?, duration_seconds=?, changed=? where id=?", files.size(), duration, new Date(), id);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile)

Example 24 with MediaFile

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

the class PodcastService method getChannelDirectory.

private File getChannelDirectory(PodcastChannel channel) {
    File podcastDir = new File(settingsService.getPodcastFolder());
    File channelDir = new File(podcastDir, StringUtil.fileSystemSafe(channel.getTitle()));
    if (!channelDir.exists()) {
        boolean ok = channelDir.mkdirs();
        if (!ok) {
            throw new RuntimeException("Failed to create directory " + channelDir);
        }
        MediaFile mediaFile = mediaFileService.getMediaFile(channelDir);
        mediaFile.setComment(channel.getDescription());
        mediaFileService.updateMediaFile(mediaFile);
    }
    return channelDir;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) MediaFile(org.libresonic.player.domain.MediaFile) File(java.io.File)

Example 25 with MediaFile

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

the class SonosService method addItemToPlaylist.

private void addItemToPlaylist(int playlistId, String id, int index) {
    if (StringUtils.isBlank(id)) {
        return;
    }
    GetMetadata parameters = new GetMetadata();
    parameters.setId(id);
    parameters.setIndex(0);
    parameters.setCount(Integer.MAX_VALUE);
    GetMetadataResponse metadata = getMetadata(parameters);
    List<MediaFile> newSongs = new ArrayList<MediaFile>();
    for (AbstractMedia media : metadata.getGetMetadataResult().getMediaCollectionOrMediaMetadata()) {
        if (StringUtils.isNumeric(media.getId())) {
            MediaFile mediaFile = mediaFileService.getMediaFile(Integer.parseInt(media.getId()));
            if (mediaFile != null && mediaFile.isFile()) {
                newSongs.add(mediaFile);
            }
        }
    }
    List<MediaFile> existingSongs = playlistService.getFilesInPlaylist(playlistId);
    if (index == -1) {
        index = existingSongs.size();
    }
    existingSongs.addAll(index, newSongs);
    playlistService.setFilesInPlaylist(playlistId, existingSongs);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile)

Aggregations

MediaFile (org.libresonic.player.domain.MediaFile)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ModelAndView (org.springframework.web.servlet.ModelAndView)8 File (java.io.File)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 MusicFolder (org.libresonic.player.domain.MusicFolder)5 Playlist (org.libresonic.player.domain.Playlist)5 Player (org.libresonic.player.domain.Player)4 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 RedirectView (org.springframework.web.servlet.view.RedirectView)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 Test (org.junit.Test)2 Share (org.libresonic.player.domain.Share)2 TransferStatus (org.libresonic.player.domain.TransferStatus)2