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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations