Search in sources :

Example 16 with MediaFile

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

the class M3UController method createClientSidePlaylist.

private void createClientSidePlaylist(PrintWriter out, Player player, String url) throws Exception {
    if (player.isM3uBomEnabled()) {
        out.print("");
    }
    out.println("#EXTM3U");
    List<MediaFile> result;
    synchronized (player.getPlayQueue()) {
        result = player.getPlayQueue().getFiles();
    }
    for (MediaFile mediaFile : result) {
        Integer duration = mediaFile.getDurationSeconds();
        if (duration == null) {
            duration = -1;
        }
        out.println("#EXTINF:" + duration + "," + mediaFile.getArtist() + " - " + mediaFile.getTitle());
        String urlNoAuth = url + "player=" + player.getId() + "&id=" + mediaFile.getId() + "&suffix=." + transcodingService.getSuffix(player, mediaFile, null);
        String urlWithAuth = jwtSecurityService.addJWTToken(urlNoAuth);
        out.println(urlWithAuth);
    }
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile)

Example 17 with MediaFile

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

the class StatusService method getPlayStatuses.

public synchronized List<PlayStatus> getPlayStatuses() {
    Map<String, PlayStatus> result = new LinkedHashMap<String, PlayStatus>();
    for (PlayStatus remotePlay : remotePlays) {
        if (!remotePlay.isExpired()) {
            result.put(remotePlay.getPlayer().getId(), remotePlay);
        }
    }
    List<TransferStatus> statuses = new ArrayList<TransferStatus>();
    statuses.addAll(inactiveStreamStatuses.values());
    statuses.addAll(streamStatuses);
    for (TransferStatus streamStatus : statuses) {
        Player player = streamStatus.getPlayer();
        File file = streamStatus.getFile();
        if (file == null) {
            continue;
        }
        MediaFile mediaFile = mediaFileService.getMediaFile(file);
        if (player == null || mediaFile == null) {
            continue;
        }
        Date time = new Date(System.currentTimeMillis() - streamStatus.getMillisSinceLastUpdate());
        result.put(player.getId(), new PlayStatus(mediaFile, player, time));
    }
    return new ArrayList<PlayStatus>(result.values());
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Player(org.libresonic.player.domain.Player) TransferStatus(org.libresonic.player.domain.TransferStatus) MediaFile(org.libresonic.player.domain.MediaFile) File(java.io.File) PlayStatus(org.libresonic.player.domain.PlayStatus)

Example 18 with MediaFile

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

the class EditTagsController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    MediaFile dir = mediaFileService.getMediaFile(id);
    List<MediaFile> files = mediaFileService.getChildrenOf(dir, true, false, true, false);
    Map<String, Object> map = new HashMap<String, Object>();
    if (!files.isEmpty()) {
        map.put("defaultArtist", files.get(0).getArtist());
        map.put("defaultAlbum", files.get(0).getAlbumName());
        map.put("defaultYear", files.get(0).getYear());
        map.put("defaultGenre", files.get(0).getGenre());
    }
    map.put("allGenres", JaudiotaggerParser.getID3V1Genres());
    List<Song> songs = new ArrayList<Song>();
    for (int i = 0; i < files.size(); i++) {
        songs.add(createSong(files.get(i), i));
    }
    map.put("id", id);
    map.put("songs", songs);
    return new ModelAndView("editTags", "model", map);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with MediaFile

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

the class ChangeCoverArtController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    String artist = request.getParameter("artist");
    String album = request.getParameter("album");
    MediaFile dir = mediaFileService.getMediaFile(id);
    if (StringUtils.isBlank(artist)) {
        artist = dir.getArtist();
    }
    if (StringUtils.isBlank(album)) {
        album = dir.getAlbumName();
    }
    Map<String, Object> map = new HashMap<>();
    map.put("id", id);
    map.put("artist", artist);
    map.put("album", album);
    return new ModelAndView("changeCoverArt", "model", map);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with MediaFile

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

the class MediaScannerServiceTestCase method testScanLibrary.

/**
   * Tests the MediaScannerService by scanning the test media library into an empty database.
   */
@Test
public void testScanLibrary() {
    MusicFolderTestData.getTestMusicFolders().forEach(musicFolderDao::createMusicFolder);
    settingsService.clearMusicFolderCache();
    Timer globalTimer = metrics.timer(MetricRegistry.name(MediaScannerServiceTestCase.class, "Timer.global"));
    Timer.Context globalTimerContext = globalTimer.time();
    TestCaseUtils.execScan(mediaScannerService);
    globalTimerContext.stop();
    System.out.println("--- Report of records count per table ---");
    Map<String, Integer> records = TestCaseUtils.recordsInAllTables(daoHelper);
    records.keySet().forEach(tableName -> System.out.println(tableName + " : " + records.get(tableName).toString()));
    System.out.println("--- *********************** ---");
    // Music Folder Music must have 3 children
    List<MediaFile> listeMusicChildren = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusicFolderPath());
    Assert.assertEquals(3, listeMusicChildren.size());
    // Music Folder Music2 must have 1 children
    List<MediaFile> listeMusic2Children = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusic2FolderPath());
    Assert.assertEquals(1, listeMusic2Children.size());
    System.out.println("--- List of all artists ---");
    System.out.println("artistName#albumCount");
    List<Artist> allArtists = artistDao.getAlphabetialArtists(0, 0, musicFolderDao.getAllMusicFolders());
    allArtists.forEach(artist -> System.out.println(artist.getName() + "#" + artist.getAlbumCount()));
    System.out.println("--- *********************** ---");
    System.out.println("--- List of all albums ---");
    System.out.println("name#artist");
    List<Album> allAlbums = albumDao.getAlphabetialAlbums(0, 0, true, musicFolderDao.getAllMusicFolders());
    allAlbums.forEach(album -> System.out.println(album.getName() + "#" + album.getArtist()));
    Assert.assertEquals(5, allAlbums.size());
    System.out.println("--- *********************** ---");
    List<MediaFile> listeSongs = mediaFileDao.getSongsByGenre("Baroque Instrumental", 0, 0, musicFolderDao.getAllMusicFolders());
    Assert.assertEquals(2, listeSongs.size());
    // display out metrics report
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.report();
    System.out.print("End");
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Artist(org.libresonic.player.domain.Artist) ConsoleReporter(com.codahale.metrics.ConsoleReporter) Album(org.libresonic.player.domain.Album) Timer(com.codahale.metrics.Timer) Test(org.junit.Test)

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