mirror of
https://github.com/sifacaii/VlcJellyfin
synced 2025-06-03 00:58:06 -04:00
添加jellyfin client
This commit is contained in:
parent
12a2e96926
commit
ea9fae71dc
@ -18,6 +18,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.owen.tvrecyclerview.widget.V7GridLayoutManager;
|
import com.owen.tvrecyclerview.widget.V7GridLayoutManager;
|
||||||
import com.owen.tvrecyclerview.widget.V7LinearLayoutManager;
|
import com.owen.tvrecyclerview.widget.V7LinearLayoutManager;
|
||||||
@ -27,7 +28,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class DetailActivity extends BaseActivity implements JAdapter.OnItemClickListener {
|
public class DetailActivity extends BaseActivity implements JAdapter.OnItemClickListener {
|
||||||
private String TAG = "详情:";
|
private String TAG = "详情:";
|
||||||
private Activity mActivity;
|
|
||||||
private String ItemId;
|
private String ItemId;
|
||||||
private ImageView tvCover;
|
private ImageView tvCover;
|
||||||
private TextView tvTitle;
|
private TextView tvTitle;
|
||||||
@ -46,11 +46,10 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
|||||||
setContentView(R.layout.activity_detail);
|
setContentView(R.layout.activity_detail);
|
||||||
getSupportActionBar().hide();
|
getSupportActionBar().hide();
|
||||||
|
|
||||||
if (Utils.UserId.equals("") || Utils.AccessToken.equals("")) {
|
if (JfClient.UserId.equals("") || JfClient.AccessToken.equals("")) {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
mActivity = this;
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,58 +70,47 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
|||||||
if (ItemId.equals("")) {
|
if (ItemId.equals("")) {
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
showLoadingDialog("加载中……");
|
showLoadingDialog("加载中……");
|
||||||
initData(ItemId);
|
initData(ItemId);
|
||||||
}
|
}
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initData(String itemId) {
|
private void initData(String itemId) {
|
||||||
String detailUrl = "/Users/" + Utils.UserId + "/Items/" + itemId;
|
JfClient.GetItemInfo(itemId, new JfClient.JJCallBack() {
|
||||||
|
|
||||||
String detailStr = Utils.okhttpSend(detailUrl);
|
|
||||||
if (detailStr != "") {
|
|
||||||
JsonObject detailObj = new Gson().fromJson(detailStr, JsonObject.class);
|
|
||||||
String Id = detailObj.get("Id").getAsString();
|
|
||||||
String Name = Utils.getJsonString(detailObj, "Name").getAsString();
|
|
||||||
|
|
||||||
if (detailObj.has("ImageTags")) {
|
|
||||||
JsonObject ImageTags = detailObj.get("ImageTags").getAsJsonObject();
|
|
||||||
if (ImageTags.has("Primary")) {
|
|
||||||
String imgid = ImageTags.get("Primary").getAsString();
|
|
||||||
String finalPicUrl = Utils.getImgUrl(itemId, imgid);
|
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void onSuccess(JsonObject detailObj) {
|
||||||
|
fillDetails(detailObj);
|
||||||
|
}
|
||||||
|
}, new JfClient.JJCallBack() {
|
||||||
|
@Override
|
||||||
|
public void onError(String str) {
|
||||||
|
Log.d(TAG, "onError: " + str);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillDetails(JsonObject detailObj) {
|
||||||
|
String Id = detailObj.get("Id").getAsString();
|
||||||
|
String Name = JfClient.strFromGson(detailObj, "Name");
|
||||||
|
String imgurl = JfClient.GetImgUrl(detailObj);
|
||||||
Picasso.get()
|
Picasso.get()
|
||||||
.load(finalPicUrl)
|
.load(imgurl)
|
||||||
.placeholder(R.drawable.img_loading_placeholder)
|
.placeholder(R.drawable.img_loading_placeholder)
|
||||||
.error(R.drawable.img_loading_placeholder)
|
.error(R.drawable.img_loading_placeholder)
|
||||||
.into(tvCover);
|
.into(tvCover);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String Genres = Utils.getJsonString(detailObj, "Genres").toString();
|
|
||||||
String OfficialRating = Utils.getJsonString(detailObj, "OfficialRating").getAsString();
|
|
||||||
String CommunityRating = Utils.getJsonString(detailObj, "CommunityRating").getAsString();
|
|
||||||
String ProductionYear = Utils.getJsonString(detailObj, "ProductionYear").getAsString();
|
|
||||||
String Overview = Utils.getJsonString(detailObj, "Overview").getAsString();
|
|
||||||
|
|
||||||
String finalGenres = Genres;
|
JsonElement genres = JfClient.jeFromGson(detailObj, "Genres");
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
String Genres = genres == null ? "" : genres.getAsJsonArray().toString();
|
||||||
@Override
|
String OfficialRating = JfClient.strFromGson(detailObj, "OfficialRating");
|
||||||
public void run() {
|
String CommunityRating = JfClient.strFromGson(detailObj, "CommunityRating");
|
||||||
|
String ProductionYear = JfClient.strFromGson(detailObj, "ProductionYear");
|
||||||
|
String Overview = JfClient.strFromGson(detailObj, "Overview");
|
||||||
|
|
||||||
tvTitle.setText(Name);
|
tvTitle.setText(Name);
|
||||||
tvGenres.setText("年份:" + ProductionYear + " 风格:" + finalGenres);
|
tvGenres.setText("年份:" + ProductionYear + " 风格:" + Genres);
|
||||||
tvRating.setText("评分:" + CommunityRating + " 评级:" + OfficialRating);
|
tvRating.setText("评分:" + CommunityRating + " 评级:" + OfficialRating);
|
||||||
tvOverview.setText("简介: " + Overview);
|
tvOverview.setText("简介: " + Overview);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JsonArray MediaStreams = null;
|
JsonArray MediaStreams = null;
|
||||||
if (detailObj.has("MediaStreams")) {
|
if (detailObj.has("MediaStreams")) {
|
||||||
@ -146,36 +134,25 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
|||||||
String finalVideo = video;
|
String finalVideo = video;
|
||||||
String finalAudio = audio;
|
String finalAudio = audio;
|
||||||
String finalSubtitle = subtitle;
|
String finalSubtitle = subtitle;
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
tvVideo.setText("视频:" + finalVideo);
|
tvVideo.setText("视频:" + finalVideo);
|
||||||
tvAudio.setText("音频:" + finalAudio);
|
tvAudio.setText("音频:" + finalAudio);
|
||||||
tvSubtitle.setText("字幕:" + finalSubtitle);
|
tvSubtitle.setText("字幕:" + finalSubtitle);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//填充列表
|
//填充列表
|
||||||
String type = Utils.getJsonString(detailObj, "Type").getAsString();
|
String type = JfClient.strFromGson(detailObj, "Type");
|
||||||
if (type.equals("Series")) {
|
if (type.equals("Series")) {
|
||||||
fillSeason(ItemId);
|
fillSeason(ItemId);
|
||||||
} else if (type.equals("Season")) {
|
} else if (type.equals("Season")) {
|
||||||
String SeriesId = detailObj.get("SeriesId").getAsString();
|
String SeriesId = detailObj.get("SeriesId").getAsString();
|
||||||
fillEpisodes(SeriesId, ItemId);
|
fillEpisodes(SeriesId, ItemId);
|
||||||
} else if (type.equals("Episode")) {
|
} else if (type.equals("Episode")) {
|
||||||
String SeriesId = Utils.getJsonString(detailObj, "SeriesId").getAsString();
|
String SeriesId = JfClient.strFromGson(detailObj, "SeriesId");
|
||||||
String SeasonId = Utils.getJsonString(detailObj, "SeasonId").getAsString();
|
String SeasonId = JfClient.strFromGson(detailObj, "SeasonId");
|
||||||
fillEpisodes(SeriesId, SeasonId);
|
fillEpisodes(SeriesId, SeasonId);
|
||||||
} else if (type.equals("Movie")) {
|
} else if (type.equals("Movie")) {
|
||||||
mAA.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
fillMovie(detailObj);
|
fillMovie(detailObj);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillMovie(JsonObject item) {
|
private void fillMovie(JsonObject item) {
|
||||||
@ -203,16 +180,13 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
|||||||
|
|
||||||
if (item.has("PartCount")) {
|
if (item.has("PartCount")) {
|
||||||
String Id = Utils.getJsonString(item, "Id").getAsString();
|
String Id = Utils.getJsonString(item, "Id").getAsString();
|
||||||
String AddPartUrl = "/Videos/" + Id + "/AdditionalParts?userId=" + Utils.UserId;
|
JfClient.GetAddPart(Id, new JfClient.JJCallBack() {
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void onSuccess(JsonArray parts) {
|
||||||
String AddPartStr = Utils.okhttpSend(AddPartUrl);
|
fillItems(parts);
|
||||||
fillItems(AddPartStr);
|
|
||||||
}
|
}
|
||||||
}).start();
|
}, null);
|
||||||
}else {
|
} else {
|
||||||
dismissLoadingDialog();
|
dismissLoadingDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,48 +197,40 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
|||||||
* @param SeriesId
|
* @param SeriesId
|
||||||
*/
|
*/
|
||||||
private void fillSeason(String SeriesId) {
|
private void fillSeason(String SeriesId) {
|
||||||
String SeasonsUrl = "/Shows/" + SeriesId + "/Seasons?userId=" + Utils.UserId;
|
JfClient.GetSeasons(SeriesId, new JfClient.JJCallBack() {
|
||||||
SeasonsUrl += "&Fields=ItemCounts,PrimaryImageAspectRatio,BasicSyncInfo,MediaSourceCount";
|
@Override
|
||||||
String SeasonsStr = Utils.okhttpSend(SeasonsUrl);
|
public void onSuccess(JsonArray seasons) {
|
||||||
fillItems(SeasonsStr);
|
fillItems(seasons);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 填充集
|
* 填充集
|
||||||
*
|
*
|
||||||
* @param SeriesId
|
* @param SeriesId
|
||||||
* @param seasonId
|
* @param SeasonId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private void fillEpisodes(String SeriesId, String seasonId) {
|
private void fillEpisodes(String SeriesId, String SeasonId) {
|
||||||
String EpisodesUrl = "/Shows/" + SeriesId + "/Episodes?seasonId=" + seasonId;
|
JfClient.GetEpisodes(SeriesId, SeasonId, new JfClient.JJCallBack() {
|
||||||
EpisodesUrl += "&userId=" + Utils.UserId;
|
@Override
|
||||||
EpisodesUrl += "&Fields=ItemCounts,PrimaryImageAspectRatio,BasicSyncInfo,CanDelete,MediaSourceCount,Overview";
|
public void onSuccess(JsonArray episodes) {
|
||||||
String EpisodesStr = Utils.okhttpSend(EpisodesUrl);
|
fillItems(episodes);
|
||||||
fillItems(EpisodesStr);
|
}
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillItems(String jsonStr) {
|
public void fillItems(JsonArray items) {
|
||||||
JsonObject item = Utils.JsonToObj(jsonStr, JsonObject.class);
|
|
||||||
if (item == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JsonArray items = item.get("Items").getAsJsonArray();
|
|
||||||
JAdapter jAdapter = new JAdapter(items, false);
|
JAdapter jAdapter = new JAdapter(items, false);
|
||||||
V7LinearLayoutManager layoutManager = new V7LinearLayoutManager(mGridView.getContext());
|
V7LinearLayoutManager layoutManager = new V7LinearLayoutManager(mGridView.getContext());
|
||||||
layoutManager.setOrientation(V7LinearLayoutManager.HORIZONTAL);
|
layoutManager.setOrientation(V7LinearLayoutManager.HORIZONTAL);
|
||||||
jAdapter.setOnItemClickListener(this);
|
jAdapter.setOnItemClickListener(this);
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mGridView.setVisibility(View.VISIBLE);
|
mGridView.setVisibility(View.VISIBLE);
|
||||||
mGridView.setLayoutManager(layoutManager);
|
mGridView.setLayoutManager(layoutManager);
|
||||||
mGridView.setAdapter(jAdapter);
|
mGridView.setAdapter(jAdapter);
|
||||||
dismissLoadingDialog();
|
dismissLoadingDialog();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -273,12 +239,12 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
|||||||
String type = jo.get("Type").getAsString();
|
String type = jo.get("Type").getAsString();
|
||||||
Intent intent = null;
|
Intent intent = null;
|
||||||
if (type.equals("Season")) {
|
if (type.equals("Season")) {
|
||||||
intent = new Intent(mActivity, DetailActivity.class);
|
intent = new Intent(this, DetailActivity.class);
|
||||||
intent.putExtra("itemId", itemId);
|
intent.putExtra("itemId", itemId);
|
||||||
mActivity.startActivity(intent);
|
startActivity(intent);
|
||||||
} else if (type.equals("Episode")) {
|
} else if (type.equals("Episode")) {
|
||||||
Utils.playList.clear();
|
Utils.playList.clear();
|
||||||
String Id = Utils.getJsonString(jo, "Id").getAsString();
|
String Id = JfClient.strFromGson(jo, "Id");
|
||||||
JAdapter JA = (JAdapter) mGridView.getAdapter();
|
JAdapter JA = (JAdapter) mGridView.getAdapter();
|
||||||
JsonArray ja = JA.getData();
|
JsonArray ja = JA.getData();
|
||||||
if (ja != null) {
|
if (ja != null) {
|
||||||
@ -301,25 +267,21 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 组合播放媒体
|
* 组合播放媒体
|
||||||
|
*
|
||||||
* @param item
|
* @param item
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Video getMedia(JsonObject item) {
|
public Video getMedia(JsonObject item) {
|
||||||
//String playUrl = Utils.JellyfinUrl + "/videos/" + id + "/stream.mp4?static=true&a";
|
//String playUrl = Utils.JellyfinUrl + "/videos/" + id + "/stream.mp4?static=true&a";
|
||||||
Video media = new Video();
|
Video media = new Video();
|
||||||
media.Id = Utils.getJsonString(item, "Id").getAsString();
|
media.Id = JfClient.strFromGson(item, "Id");
|
||||||
media.Name = Utils.getJsonString(item, "Name").getAsString();
|
media.Name = JfClient.strFromGson(item, "Name");
|
||||||
JsonObject ImageTags = item.get("ImageTags").getAsJsonObject();
|
media.cover = JfClient.GetImgUrl(item);
|
||||||
if (ImageTags.has("Primary")) {
|
media.Url = JfClient.GetPlayUrl(media.Id);
|
||||||
String imgid = ImageTags.get("Primary").getAsString();
|
|
||||||
media.cover = Utils.getImgUrl(media.Id, imgid);
|
|
||||||
}
|
|
||||||
media.Url = Utils.config.getJellyfinUrl() + "/videos/" + media.Id + "/stream.mp4?static=true&a";
|
|
||||||
if (item.has("UserData")) {
|
if (item.has("UserData")) {
|
||||||
JsonObject userdata = item.get("UserData").getAsJsonObject();
|
JsonObject userdata = item.get("UserData").getAsJsonObject();
|
||||||
media.startPositionTicks = userdata.get("PlaybackPositionTicks").getAsLong();
|
media.startPositionTicks = userdata.get("PlaybackPositionTicks").getAsLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
return media;
|
return media;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ public class JfClient {
|
|||||||
* @param cb
|
* @param cb
|
||||||
*/
|
*/
|
||||||
public static void GetAddPart(String itemid,JJCallBack cb,JJCallBack errcb){
|
public static void GetAddPart(String itemid,JJCallBack cb,JJCallBack errcb){
|
||||||
String AddPartUrl = "/Videos/" + itemid + "/AdditionalParts?userId=" + UserId;
|
String AddPartUrl = config.getJellyfinUrl() + "/Videos/" + itemid + "/AdditionalParts?userId=" + UserId;
|
||||||
SendGet(AddPartUrl,new JJCallBack(){
|
SendGet(AddPartUrl,new JJCallBack(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(String str) {
|
public void onSuccess(String str) {
|
||||||
@ -288,6 +288,8 @@ public class JfClient {
|
|||||||
JsonObject item = strToGson(str, JsonObject.class);
|
JsonObject item = strToGson(str, JsonObject.class);
|
||||||
if (null != item) {
|
if (null != item) {
|
||||||
cb.onSuccess(item);
|
cb.onSuccess(item);
|
||||||
|
}else{
|
||||||
|
err.onError(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},err);
|
},err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user