package cn.com.ctop.crawler.modules.music.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * 快手音乐信息
 * @author jeecg-boot
 * @date   2020-09-15
 * @version V1.0
 */
@Data
@TableName("ctop_music_info_kuaishou")
@Accessors(chain = true)
public class MusicInfoKuaishou {

	/**id*/
	@TableId
    private String id;
	private Long musicianUid;
	private String image;
	private Long chorus;
	private Long duration;
	private Long begin;
	private Long end;
	private String name;
	private Integer type;
	private String lrcUrl;
	private String audioUrl;
	private String avatarUrl;
	private String snippetUrl;
	private Long snippetDuration;
	private Long singingCount;
	private String url;
	private String expTag;
	private String imageUrl;
	private Long photoCount;
	private Long usageCount;
	private String artist;
	private Integer genreId;
	private String lrc;
	private Integer audioType;
	private String isOriginal;
	private Date createTime;
	private Date updateTime;
	private Long musicChannel;

	public MusicInfoKuaishou(JSONObject music,Long channelType) {
		this.musicianUid = music.getLong("musicianUid");
		this.image = music.getString("image");
		this.chorus = music.getLong("chorus");
		this.duration = music.getLong("duration");
		this.begin = music.getLong("begin");
		this.end = music.getLong("end");
		this.name = music.getString("name");
		this.id = music.getString("id")+"-"+channelType;
		this.type = music.getInteger("type");
		JSONArray lrcUrls = music.getJSONArray("lrcUrls");
		if(null!=lrcUrls&&!lrcUrls.isEmpty()){
			this.lrcUrl = lrcUrls.getJSONObject(0).getString("url");
		}
		JSONArray audioUrls = music.getJSONArray("audioUrls");
		if(null!=audioUrls&&!audioUrls.isEmpty()){
			this.audioUrl = audioUrls.getJSONObject(0).getString("url");
		}
		this.avatarUrl = music.getString("avatarUrl");
		JSONArray snippetUrls = music.getJSONArray("snippetUrls");
		if(null!=snippetUrls&&!snippetUrls.isEmpty()){
			this.snippetUrl = snippetUrls.getJSONObject(0).getString("url");
		}
		this.singingCount = music.getLong("singingCount");
		this.snippetDuration = music.getLong("snippetDuration");
		this.url = music.getString("url");
		this.expTag = music.getString("expTag");
		JSONArray imageUrls = music.getJSONArray("imageUrls");
		if(null!=imageUrls&&!imageUrls.isEmpty()){
			this.imageUrl = imageUrls.getJSONObject(0).getString("url");
		}
		this.photoCount = music.getLong("photoCount");
		this.usageCount = music.getLong("usageCount");
		this.artist = music.getString("artist");
		this.genreId = music.getInteger("genreId");
		this.lrc = music.getString("lrc");
		this.audioType = music.getInteger("audioType");

		Boolean isOriginal = music.getBoolean("isOriginal");
		if(null == isOriginal){
			isOriginal = false;
		}
		if(isOriginal){
			this.isOriginal = "true";
		}else{
			this.isOriginal = "false";
		}
		this.createTime = new Date();
		this.updateTime = new Date();
		this.musicChannel = channelType;
	}

	public MusicInfoKuaishou() {

	}
}
