Skip to content

Commit

Permalink
Merge pull request #268 from kagemomiji/issue212-transcoding-repository
Browse files Browse the repository at this point in the history
#212 implement repository for transcoding
  • Loading branch information
kagemomiji authored Aug 21, 2023
2 parents e3d7631 + eee9f43 commit 560d655
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class PlayerSettingsCommand {
private boolean transcodingSupported;
private String transcodeDirectory;
private List<Transcoding> allTranscodings;
private int[] activeTranscodingIds;
private List<Integer> activeTranscodingIds;
private EnumHolder[] technologyHolders;
private EnumHolder[] transcodeSchemeHolders;
private Player[] players;
Expand Down Expand Up @@ -149,11 +149,11 @@ public void setAllTranscodings(List<Transcoding> allTranscodings) {
this.allTranscodings = allTranscodings;
}

public int[] getActiveTranscodingIds() {
public List<Integer> getActiveTranscodingIds() {
return activeTranscodingIds;
}

public void setActiveTranscodingIds(int[] activeTranscodingIds) {
public void setActiveTranscodingIds(List<Integer> activeTranscodingIds) {
this.activeTranscodingIds = activeTranscodingIds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ protected void formBackingObject(HttpServletRequest request, Model model) throws
command.setTechnologyName(player.getTechnology().name());
command.setAllTranscodings(transcodingService.getAllTranscodings());
List<Transcoding> activeTranscodings = transcodingService.getTranscodingsForPlayer(player);
int[] activeTranscodingIds = new int[activeTranscodings.size()];
for (int i = 0; i < activeTranscodings.size(); i++) {
activeTranscodingIds[i] = activeTranscodings.get(i).getId();
}
command.setActiveTranscodingIds(activeTranscodingIds);
command.setActiveTranscodingIds(activeTranscodings.stream().map(Transcoding::getId).toList());
}

command.setTranscodingSupported(transcodingService.isDownsamplingSupported(null));
Expand Down Expand Up @@ -157,7 +153,7 @@ protected String doSubmitAction(@ModelAttribute("command") PlayerSettingsCommand
playerService.updatePlayer(player);
}

transcodingService.setTranscodingsForPlayer(player, command.getActiveTranscodingIds());
transcodingService.setTranscodingsForPlayerByIds(player, command.getActiveTranscodingIds());

redirectAttributes.addFlashAttribute("settings_toast", true);
return "redirect:playerSettings.view?id=" + command.getPlayerId();
Expand Down

This file was deleted.

77 changes: 77 additions & 0 deletions airsonic-main/src/main/java/org/airsonic/player/domain/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,91 @@
You should have received a copy of the GNU General Public License
along with Airsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2023 (C) Y.Tory
Copyright 2016 (C) Airsonic Authors
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
*/
package org.airsonic.player.domain;

import org.apache.commons.lang.StringUtils;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

/**
* Represents a remote player. A player has a unique ID, a user-defined name, a
* logged-on user, miscellaneous identifiers, and an associated playlist.
*
* @author Sindre Mehus
*/
@Entity
@Table(name = "player")
public class Player {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column(name = "name", nullable = true)
private String name;

@Column(name = "technology", nullable = false)
@Enumerated(EnumType.STRING)
private PlayerTechnology technology = PlayerTechnology.WEB;

@Column(name = "client_id", nullable = true)
private String clientId;

@Column(name = "type", nullable = true)
private String type;

@Column(name = "username", nullable = true)
private String username;

@Column(name = "ip_address", nullable = true)
private String ipAddress;

@Column(name = "dynamic_ip", nullable = false)
private boolean dynamicIp = true;

@Column(name = "auto_control_enabled")
private boolean autoControlEnabled = true;

@Column(name = "m3u_bom_enabled")
private boolean m3uBomEnabled = true;

@Column(name = "last_seen", nullable = true)
private Instant lastSeen;

@Column(name = "transcode_scheme", nullable = false)
@Enumerated(EnumType.STRING)
private TranscodeScheme transcodeScheme = TranscodeScheme.OFF;

@ManyToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@JoinTable(
name = "player_transcoding",
joinColumns = {@JoinColumn(name = "player_id")},
inverseJoinColumns = {@JoinColumn(name = "transcoding_id")}
)
private List<Transcoding> transcodings = new ArrayList<>();

@Transient
private PlayQueue playQueue;

/**
Expand Down Expand Up @@ -326,6 +382,27 @@ public String getShortDescription() {
return "Player " + id;
}

/**
* Returns the transcodings for the player.
*/
public List<Transcoding> getTranscodings() {
return transcodings;
}

/**
* Sets the transcodings for the player.
*/
public void setTranscodings(List<Transcoding> transcodings) {
this.transcodings = transcodings;
}

/**
* Adds a transcoding to the player.
*/
public void addTranscoding(Transcoding transcoding) {
transcodings.add(transcoding);
}

/**
* Returns a string representation of the player.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@
You should have received a copy of the GNU General Public License
along with Airsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2023 (C) Y.Tory
Copyright 2016 (C) Airsonic Authors
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
*/
package org.airsonic.player.domain;

import org.airsonic.player.util.StringUtil;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
Expand All @@ -32,17 +43,41 @@
*
* @author Sindre Mehus
*/
@Entity
@Table(name = "transcoding")
public class Transcoding {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column(nullable = false)
private String name;

@Column(name = "source_formats", nullable = false)
private String sourceFormats;

@Column(name = "target_format", nullable = false)
private String targetFormat;

@Column(nullable = false)
private String step1;

@Column(nullable = true)
private String step2;

@Column(nullable = true)
private String step3;

@Column(name = "default_active", nullable = false)
private boolean defaultActive;

@ManyToMany(mappedBy = "transcodings")
private List<Player> players = new ArrayList<>();

public Transcoding() {
}

/**
* Creates a new transcoding specification.
*
Expand Down Expand Up @@ -206,6 +241,28 @@ public void setDefaultActive(boolean defaultActive) {
this.defaultActive = defaultActive;
}

/**
* Returns the players that use this transcoding
*/
public List<Player> getPlayers() {
return players;
}

/**
* Adds a player that uses this transcoding
*/
public void addPlayer(Player player) {
players.add(player);
}

/**
* Sets the players that use this transcoding
* @param players
*/
public void setPlayers(List<Player> players) {
this.players = players;
}

public boolean equals(Object o) {
if (this == o) {
return true;
Expand Down
Loading

0 comments on commit 560d655

Please sign in to comment.