tempus/app/src/main/java/com/cappielloantonio/play/model/Media.java

458 lines
13 KiB
Java
Raw Normal View History

2020-11-20 15:38:08 +01:00
package com.cappielloantonio.play.model;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
2020-11-20 15:38:08 +01:00
import androidx.annotation.NonNull;
import com.cappielloantonio.play.subsonic.models.Child;
2022-02-07 17:37:25 +01:00
import com.cappielloantonio.play.subsonic.models.PodcastEpisode;
2020-11-20 15:38:08 +01:00
2022-02-07 09:47:46 +01:00
public class Media implements Parcelable {
private static final String TAG = "Media";
2022-02-07 17:37:25 +01:00
public static final String MEDIA_TYPE_MUSIC = "music";
public static final String MEDIA_TYPE_PODCAST = "podcast";
public static final String MEDIA_TYPE_AUDIOBOOK = "audiobook";
public static final String MEDIA_TYPE_VIDEO = "video";
2022-02-07 09:48:15 +01:00
public static final float MEDIA_PLAYBACK_SPEED_080 = 0.8f;
public static final float MEDIA_PLAYBACK_SPEED_100 = 1.0f;
public static final float MEDIA_PLAYBACK_SPEED_125 = 1.25f;
public static final float MEDIA_PLAYBACK_SPEED_150 = 1.50f;
public static final float MEDIA_PLAYBACK_SPEED_175 = 1.75f;
public static final float MEDIA_PLAYBACK_SPEED_200 = 2.0f;
2020-11-24 10:52:00 +01:00
public static final String RECENTLY_PLAYED = "RECENTLY_PLAYED";
public static final String MOST_PLAYED = "MOST_PLAYED";
public static final String RECENTLY_ADDED = "RECENTLY_ADDED";
public static final String BY_GENRE = "BY_GENRE";
2020-11-25 08:21:30 +01:00
public static final String BY_GENRES = "BY_GENRES";
2020-11-24 10:52:00 +01:00
public static final String BY_ARTIST = "BY_ARTIST";
2020-11-28 14:50:15 +01:00
public static final String BY_YEAR = "BY_YEAR";
public static final String STARRED = "STARRED";
2021-04-26 19:37:05 +02:00
public static final String DOWNLOADED = "DOWNLOADED";
public static final String FROM_ALBUM = "FROM_ALBUM";
2021-04-18 20:23:09 +02:00
2020-11-20 15:38:08 +01:00
private String id;
private String title;
2022-02-07 17:37:25 +01:00
private String channelId;
private String streamId;
2020-11-20 15:38:08 +01:00
private String albumId;
private String albumName;
private String artistId;
private String artistName;
2022-02-07 17:37:25 +01:00
private String coverArtId;
private int trackNumber;
private int discNumber;
private int year;
private long duration;
private String description;
private String status;
private boolean starred;
2020-11-20 15:38:08 +01:00
private String path;
private long size;
private String container;
private int bitrate;
private String extension;
2020-11-22 19:11:38 +01:00
private long added;
2022-02-07 09:47:46 +01:00
private String type;
2020-11-22 19:11:38 +01:00
private int playCount;
private long lastPlay;
private int rating;
2022-02-07 17:37:25 +01:00
private long publishDate;
2022-02-07 09:47:46 +01:00
public Media(Child child) {
this.id = child.getId();
this.title = child.getTitle();
this.trackNumber = child.getTrack() != null ? child.getTrack() : 0;
this.discNumber = child.getDiscNumber() != null ? child.getDiscNumber() : 0;
this.year = child.getYear() != null ? child.getYear() : 0;
2022-03-24 22:20:00 +01:00
this.duration = child.getDuration() != null ? child.getDuration() : 0;
this.albumId = child.getAlbumId();
this.albumName = child.getAlbum();
this.artistId = child.getArtistId();
this.artistName = child.getArtist();
2022-02-07 17:37:25 +01:00
this.coverArtId = child.getCoverArtId();
this.starred = child.getStarred() != null;
this.path = child.getPath();
this.size = child.getSize() != null ? child.getSize() : 0;
this.container = child.getContentType();
2022-03-30 11:52:15 +02:00
this.bitrate = child.getBitRate() != null ? child.getBitRate() : 0;
this.extension = child.getSuffix();
this.added = child.getCreated().getTime();
2020-11-22 19:11:38 +01:00
this.playCount = 0;
this.lastPlay = 0;
this.rating = child.getUserRating() != null ? child.getUserRating() : 0;
2022-02-07 17:37:25 +01:00
this.type = child.getType();
}
public Media(PodcastEpisode podcastEpisode) {
this.id = podcastEpisode.getId();
this.title = podcastEpisode.getTitle();
this.albumName = podcastEpisode.getAlbum();
this.artistName = podcastEpisode.getArtist();
this.trackNumber = podcastEpisode.getTrack() != null ? podcastEpisode.getTrack() : 0;
this.year = podcastEpisode.getYear();
this.coverArtId = podcastEpisode.getCoverArtId();
this.duration = podcastEpisode.getDuration();
this.starred = podcastEpisode.getStarred() != null;
this.streamId = podcastEpisode.getStreamId();
this.channelId = podcastEpisode.getChannelId();
this.description = podcastEpisode.getDescription();
this.status = podcastEpisode.getStatus();
this.publishDate = podcastEpisode.getPublishDate().getTime();
this.container = podcastEpisode.getContentType();
this.bitrate = podcastEpisode.getBitRate();
this.extension = podcastEpisode.getSuffix();
2022-02-07 17:37:25 +01:00
this.type = podcastEpisode.getType();
2020-11-20 15:38:08 +01:00
}
2022-02-07 09:47:46 +01:00
public Media(Queue queue) {
2022-02-07 17:37:25 +01:00
this.id = queue.getId();
2021-07-28 15:28:32 +02:00
this.title = queue.getTitle();
this.albumId = queue.getAlbumId();
this.albumName = queue.getAlbumName();
this.artistId = queue.getArtistId();
this.artistName = queue.getArtistName();
2022-02-07 17:37:25 +01:00
this.coverArtId = queue.getCoverArtId();
2021-07-28 18:53:42 +02:00
this.duration = queue.getDuration();
2022-02-07 17:37:25 +01:00
this.streamId = queue.getStreamId();
this.channelId = queue.getChannelId();
this.publishDate = queue.getPublishingDate();
this.container = queue.getContainer();
this.bitrate = queue.getBitrate();
this.extension = queue.getExtension();
2022-02-07 17:37:25 +01:00
this.type = queue.getType();
2021-07-28 15:28:32 +02:00
}
2022-02-07 09:47:46 +01:00
public Media(Download download) {
this.id = download.getMediaID();
2021-07-29 17:12:55 +02:00
this.title = download.getTitle();
this.albumId = download.getAlbumId();
this.albumName = download.getAlbumName();
this.artistId = download.getArtistId();
this.artistName = download.getArtistName();
2021-09-02 14:18:10 +02:00
this.trackNumber = download.getTrackNumber();
2022-02-07 17:37:25 +01:00
this.coverArtId = download.getPrimary();
2021-07-29 17:12:55 +02:00
this.duration = download.getDuration();
this.container = download.getContainer();
this.bitrate = download.getBitrate();
this.extension = download.getExtension();
this.type = download.getType();
2021-07-29 17:12:55 +02:00
}
2020-11-20 15:38:08 +01:00
public String getId() {
return id;
}
2022-02-07 17:37:25 +01:00
public void setId(String id) {
this.id = id;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public String getTitle() {
return title;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public void setTitle(String title) {
this.title = title;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public String getChannelId() {
return channelId;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public void setChannelId(String channelId) {
this.channelId = channelId;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public String getStreamId() {
return streamId;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public void setStreamId(String streamId) {
this.streamId = streamId;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public String getAlbumId() {
return albumId;
}
2022-02-07 17:37:25 +01:00
public void setAlbumId(String albumId) {
this.albumId = albumId;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public String getAlbumName() {
return albumName;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public void setAlbumName(String albumName) {
this.albumName = albumName;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public String getArtistId() {
return artistId;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public void setArtistId(String artistId) {
this.artistId = artistId;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public String getArtistName() {
return artistName;
2020-11-22 19:11:38 +01:00
}
2022-02-07 17:37:25 +01:00
public void setArtistName(String artistName) {
this.artistName = artistName;
2020-11-22 19:11:38 +01:00
}
2022-02-07 17:37:25 +01:00
public String getCoverArtId() {
return coverArtId;
2020-11-22 19:11:38 +01:00
}
2022-02-07 17:37:25 +01:00
public void setCoverArtId(String coverArtId) {
this.coverArtId = coverArtId;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public int getTrackNumber() {
return trackNumber;
2020-11-20 15:38:08 +01:00
}
public void setTrackNumber(int trackNumber) {
this.trackNumber = trackNumber;
}
2022-02-07 17:37:25 +01:00
public int getDiscNumber() {
return discNumber;
}
2020-11-20 15:38:08 +01:00
public void setDiscNumber(int discNumber) {
this.discNumber = discNumber;
}
2022-02-07 17:37:25 +01:00
public int getYear() {
return year;
}
2020-11-20 15:38:08 +01:00
public void setYear(int year) {
this.year = year;
}
2022-02-07 17:37:25 +01:00
public long getDuration() {
return duration;
}
2020-11-20 15:38:08 +01:00
public void setDuration(long duration) {
this.duration = duration;
}
2022-02-07 17:37:25 +01:00
public String getDescription() {
return description;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public void setDescription(String description) {
this.description = description;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public String getStatus() {
return status;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public void setStatus(String status) {
this.status = status;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public boolean isStarred() {
return starred;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public void setStarred(boolean starred) {
this.starred = starred;
}
2022-02-07 17:37:25 +01:00
public String getPath() {
return path;
2020-11-20 15:38:08 +01:00
}
public void setPath(String path) {
this.path = path;
}
2022-02-07 17:37:25 +01:00
public long getSize() {
return size;
}
2020-11-20 15:38:08 +01:00
public void setSize(long size) {
this.size = size;
}
2022-02-07 17:37:25 +01:00
public String getContainer() {
return container;
}
2020-11-20 15:38:08 +01:00
public void setContainer(String container) {
this.container = container;
}
public int getBitrate() {
return bitrate;
}
public void setBitrate(int bitRate) {
this.bitrate = bitRate;
}
public String getExtension() {
return extension;
2022-02-07 17:37:25 +01:00
}
public void setExtension(String extension) {
this.extension = extension;
2020-11-20 15:38:08 +01:00
}
2022-02-07 17:37:25 +01:00
public long getAdded() {
return added;
}
2020-11-22 19:11:38 +01:00
public void setAdded(long added) {
this.added = added;
}
2022-02-07 17:37:25 +01:00
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getPlayCount() {
return playCount;
2020-11-22 19:11:38 +01:00
}
2020-11-27 09:06:50 +01:00
public void setPlayCount(int playCount) {
this.playCount = playCount;
}
2022-02-07 17:37:25 +01:00
public long getLastPlay() {
return lastPlay;
}
public void setLastPlay(long lastPlay) {
this.lastPlay = lastPlay;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
2022-02-07 17:37:25 +01:00
public long getPublishDate() {
return publishDate;
}
public void setPublishDate(long publishDate) {
this.publishDate = publishDate;
}
2020-11-20 15:38:08 +01:00
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
2022-02-07 09:47:46 +01:00
Media song = (Media) o;
2020-11-20 15:38:08 +01:00
return id.equals(song.id);
}
@Override
public int hashCode() {
return id.hashCode();
}
@NonNull
2020-11-20 15:38:08 +01:00
@Override
public String toString() {
return id;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
dest.writeString(this.title);
2022-02-07 17:37:25 +01:00
dest.writeString(this.channelId);
dest.writeString(this.streamId);
2020-11-20 15:38:08 +01:00
dest.writeString(this.albumId);
dest.writeString(this.albumName);
dest.writeString(this.artistId);
dest.writeString(this.artistName);
2022-02-07 17:37:25 +01:00
dest.writeString(this.coverArtId);
dest.writeInt(this.trackNumber);
dest.writeInt(this.discNumber);
dest.writeInt(this.year);
dest.writeLong(this.duration);
dest.writeString(this.description);
dest.writeString(this.status);
dest.writeString(Boolean.toString(starred));
2020-11-20 15:38:08 +01:00
dest.writeString(this.path);
dest.writeLong(this.size);
dest.writeString(this.container);
dest.writeInt(this.bitrate);
dest.writeString(this.extension);
2020-11-22 19:11:38 +01:00
dest.writeLong(this.added);
2022-02-07 17:37:25 +01:00
dest.writeString(this.type);
2020-11-22 19:11:38 +01:00
dest.writeInt(this.playCount);
dest.writeLong(this.lastPlay);
2022-02-07 17:37:25 +01:00
dest.writeInt(this.rating);
dest.writeLong(this.publishDate);
2020-11-20 15:38:08 +01:00
}
2022-02-07 09:47:46 +01:00
protected Media(Parcel in) {
2020-11-20 15:38:08 +01:00
this.id = in.readString();
this.title = in.readString();
2022-02-07 17:37:25 +01:00
this.channelId = in.readString();
this.streamId = in.readString();
2020-11-20 15:38:08 +01:00
this.albumId = in.readString();
this.albumName = in.readString();
this.artistId = in.readString();
this.artistName = in.readString();
2022-02-07 17:37:25 +01:00
this.coverArtId = in.readString();
this.trackNumber = in.readInt();
this.discNumber = in.readInt();
this.year = in.readInt();
this.duration = in.readLong();
this.description = in.readString();
this.status = in.readString();
this.starred = Boolean.parseBoolean(in.readString());
2020-11-20 15:38:08 +01:00
this.path = in.readString();
this.size = in.readLong();
this.container = in.readString();
this.bitrate = in.readInt();
this.extension = in.readString();
2020-11-22 19:11:38 +01:00
this.added = in.readLong();
2022-02-07 17:37:25 +01:00
this.type = in.readString();
2020-11-22 19:11:38 +01:00
this.playCount = in.readInt();
this.lastPlay = in.readLong();
2022-02-07 17:37:25 +01:00
this.rating = in.readInt();
this.publishDate = in.readLong();
2020-11-20 15:38:08 +01:00
}
2022-02-07 09:47:46 +01:00
public static final Creator<Media> CREATOR = new Creator<Media>() {
public Media createFromParcel(Parcel source) {
return new Media(source);
2020-11-20 15:38:08 +01:00
}
2022-02-07 09:47:46 +01:00
public Media[] newArray(int size) {
return new Media[size];
2020-11-20 15:38:08 +01:00
}
};
}