public void PlayMovie(ApiMovie video) { if (video == null) { return; } if (!_parent.IsConnected()) { return; } EmbyPlayPlayList(video.Path); _parent.Trace("Attemping to Play IdEpsiode equals" + video.Path); /* * var args = new JsonObject(); * var items = new JsonObject(); * args["movieid"] = video.IdMovie; * items["item"] = args; * items["playlistid"] = 1; * var plId = new JsonObject(); * plId["playlistid"] = 1; * var item = new JsonObject(); * item["item"] = plId; * _parent.JsonCommand("Playlist.Clear", plId); * _parent.JsonCommand("Playlist.Add", items); * _parent.JsonCommand("Player.Open", item); */ }
public bool DownloadImages(ApiImageDownloadInfo apiImageDownloadInfo) { try { if (apiImageDownloadInfo == null) { return(false); } bool res = false; if (apiImageDownloadInfo.Source.Contains(_parent.IP)) { _parent.Trace("----------DOWNLOAD IMAGES: Checking for presence of Server IP Address in source to select Download Method - Server IP Found"); _parent.Trace("----------DOWNLOAD IMAGES: Source:" + apiImageDownloadInfo.Source.ToString() + ":Destination:" + apiImageDownloadInfo.Destination.ToString()); res = DownloadRemoteImageFile(apiImageDownloadInfo.Source, apiImageDownloadInfo.Destination); } else { res = Download(apiImageDownloadInfo.Source, apiImageDownloadInfo.Destination); } if (res) { if (apiImageDownloadInfo.ToThumb) { _parent.GenerateThumb(apiImageDownloadInfo.Destination, apiImageDownloadInfo.Destination, apiImageDownloadInfo.MaxHeight); } } return(res); } catch (System.Exception ex) { _parent.Log("Download Image: Does not Exist: Exception Caught:" + ex); // Maybe add this check log first -- apiImageDownloadInfo.Source = "NONE"; return(false); ; } }
public void AsyncPlayFiles(Collection <ApiAudioSong> songs) { // var songs = (Collection<ApiAudioSong>)e.Argument; _parent.Trace("-----------PLAYLIST Songs: Trying to play songs #:" + songs.Count + "and Globals.SessionID:" + Globals.SessionIDClient); if (songs == null) { return; } if (!_parent.IsConnected()) { return; } StringBuilder stringlistIds = new StringBuilder(); foreach (var apiAudioSong in songs) { stringlistIds.Append(apiAudioSong.Path).Append(","); } string ListItems = stringlistIds.ToString(0, stringlistIds.Length - 1); _parent.Trace("PLAYFILES Attempting to Play :" + ListItems); EmbyPlayPlayList(ListItems); /* * _bw.CancelAsync(); * while (_bw.IsBusy) * { * Thread.Sleep(50); * System.Windows.Forms.Application.DoEvents(); * } * _bw.RunWorkerAsync(songs); */ }
public bool DownloadImages(ApiImageDownloadInfo apiImageDownloadInfo) { try { if (apiImageDownloadInfo == null) { return(false); } bool res = false; if (apiImageDownloadInfo.Source.Contains(_parent.IP)) { _parent.Trace("----------DOWNLOAD IMAGES OKAY checking for presence of Server IP Address in source to select DOwnload Method - Server IP Found"); res = DownloadRemoteImageFile(apiImageDownloadInfo.Source, apiImageDownloadInfo.Destination); } else { res = Download(apiImageDownloadInfo.Source, apiImageDownloadInfo.Destination); } if (res) { if (apiImageDownloadInfo.ToThumb) { _parent.GenerateThumb(apiImageDownloadInfo.Destination, apiImageDownloadInfo.Destination, apiImageDownloadInfo.MaxHeight); } } return(res); } catch (System.Exception ex) { _parent.Log("Exception in Download Images Caught Should continue " + ex); return(false); ; } }
public Collection <ApiTvSeason> GetTvSeasons() { var seasons = new Collection <ApiTvSeason>(); try { _parent.Trace("Getting TV Seasons" + _parent.IP); string NPurl = "http://" + _parent.IP + ":" + _parent.Port + "/emby/Users/" + Globals.CurrentUserID + "/Items?Recursive=true&IncludeItemTypes=Season"; var request = WebRequest.CreateHttp(NPurl); request.Method = "get"; request.Timeout = 150000; _parent.Trace("Single TV Season Selection: " + _parent.IP + ":" + _parent.Port); var authString = _parent.GetAuthString(); request.Headers.Add("X-MediaBrowser-Token", Globals.EmbyAuthToken); request.Headers.Add("X-Emby-Authorization", authString); request.ContentType = "application/json; charset=utf-8"; request.Accept = "application/json; charset=utf-8"; var response = request.GetResponse(); if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK) { System.IO.Stream dataStream = response.GetResponseStream(); //REMOVETHIS System.IO.StreamReader reader = new System.IO.StreamReader(dataStream); using (var sr = new System.IO.StreamReader(response.GetResponseStream())) { string json = sr.ReadToEnd(); _parent.Trace("--------------GETTING Single TV Season Selection Result ------" + json); var deserializer = new JavaScriptSerializer(); var ItemData = deserializer.Deserialize <TVSeasons.Rootobject>(json); _parent.Trace("---------------Get Single TV Season Selection: Issue: Results.Taglines: " + ItemData.TotalRecordCount); foreach (var genre in ItemData.Items) { try { //var SingleTVData = GetSingleTVFromSeries(genre.Id); var tvShow = new ApiTvSeason { SeasonNumber = genre.IndexNumber, IdShow = Xbmc.IDtoNumber(genre.SeriesId), Show = genre.SeriesName ?? "", Thumb = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + genre.Id + "/Images/Primary" ?? "", EpisodeCount = genre.ChildCount, Fanart = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + genre.SeriesId + "/Images/Backdrop" ?? "", Hash = Xbmc.Hash(genre.Id) }; seasons.Add(tvShow); /* * var tvShow = new ApiTvShow * { * * Title = genre.Name ?? "Unknown", * Plot = SingleTVData.Overview ?? "", * Rating = genre.CommunityRating.ToString() ?? "", * IdScraper = "", * Mpaa = SingleTVData.OfficialRating ?? "Unknown", * Genre = SingleTVData.Genres.FirstOrDefault().ToString() ?? "", * Studio = SingleTVData.Studios.FirstOrDefault().Name.ToString() ?? "", * IdShow = Xbmc.IDtoNumber(genre.Id), * TotalCount = genre.RecursiveItemCount, * Path = SingleTVData.Path ?? "", * Premiered = genre.PremiereDate.ToString() ?? "", * Thumb = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + genre.Id + "/Images/Primary" ?? "", * Fanart = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + genre.Id + "/Images/Backdrop" ?? "", * Hash = Xbmc.Hash(genre.Id) * * }; * * shows.Add(tvShow);*/ } catch (Exception ex) { _parent.Trace("TV Shows Exception Caught " + ex); } } } } } catch (Exception Ex) { _parent.Trace("Another tV SHows exception" + Ex); } /* * var properties = new Jayrock.Json.JsonArray(new[] { "title" }); * var param = new JsonObject(); * param["properties"] = properties; * * * var result = (JsonObject)_parent.JsonCommand("VideoLibrary.GetTVShows", param); * * * if (result != null) * { * if (result.Contains("tvshows")) * { * foreach (JsonObject show in (JsonArray)result["tvshows"]) * { * var properties2 = * new JsonArray(new[] { "tvshowid", "fanart", "thumbnail", "season", "showtitle", "episode" }); * var param2 = new JsonObject(); * param2["properties"] = properties2; * param2["tvshowid"] = (long)(JsonNumber)show["tvshowid"]; * var result2 = (JsonObject)_parent.JsonCommand("VideoLibrary.GetSeasons", param2); * if (result2 == null) continue; * if (!result2.Contains("seasons")) continue; * foreach (JsonObject genre in (JsonArray)result2["seasons"]) * { * try * { * var tvShow = new ApiTvSeason * { * SeasonNumber = (long)(JsonNumber)genre["season"], * IdShow = (long)(JsonNumber)genre["tvshowid"], * Show = genre["showtitle"].ToString(), * Thumb = genre["thumbnail"].ToString(), * EpisodeCount = (long)(JsonNumber)genre["episode"], * Fanart = genre["fanart"].ToString(), * Hash = Xbmc.Hash(genre["thumbnail"].ToString()) * }; * seasons.Add(tvShow); * } * catch (Exception) * { * } * } * } * } * } */ return(seasons); }
public string GetMainSelection(string param) { try { _parent.Trace("Getting Music Selection Result" + _parent.IP); string NPurl = "http://" + _parent.IP + ":" + _parent.Port + "/emby/Users/" + Globals.CurrentUserID + "/Views"; var request = WebRequest.CreateHttp(NPurl); var MusicID = ""; request.Method = "get"; request.Timeout = 10000; _parent.Trace("Main Selection: " + _parent.IP + ":" + _parent.Port); var authString = _parent.GetAuthString(); request.Headers.Add("X-MediaBrowser-Token", Globals.EmbyAuthToken); request.Headers.Add("X-Emby-Authorization", authString); request.ContentType = "application/json; charset=utf-8"; request.Accept = "application/json; charset=utf-8"; var response = request.GetResponse(); if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK) { System.IO.Stream dataStream = response.GetResponseStream(); using (var sr = new System.IO.StreamReader(response.GetResponseStream())) { string json = sr.ReadToEnd(); _parent.Trace("--------------GETTING Main Selection Result ------" + json); var deserializer = new JavaScriptSerializer(); var ItemData = deserializer.Deserialize <MainSelectionforMusic.Rootobject>(json); _parent.Trace("---------------Get Main Selection: Issue: Results.Count: " + ItemData.Items.Length); foreach (var id in ItemData.Items) { if (id.Name == "Music") { _parent.Trace("----------- Get Main Selection Run ---" + param + " ID Result equals: " + id.Id); MusicID = id.Id; return(MusicID); } } } } return(""); /* * // Do again to get Album, Genre etc results * // these come from param - above is fixed to Music * // Options to pass are Latest, Playlists, Albums, Album Artists, Songs, Genres * _parent.Trace("Getting Music Next Selection Result" + _parent.IP); * NPurl = "http://" + _parent.IP + ":" + _parent.Port + "/emby/Users/" + Globals.CurrentUserID + "/Items?parentId=" + MusicID; * var request2 = WebRequest.CreateHttp(NPurl); * request2.Method = "get"; * request2.Timeout = 100000; * _parent.Trace("Main Selection: " + _parent.IP + ":" + _parent.Port); * //var authString = _parent.GetAuthString(); * request2.Headers.Add("X-MediaBrowser-Token", Globals.EmbyAuthToken); * request2.Headers.Add("X-Emby-Authorization", authString); * request2.ContentType = "application/json; charset=utf-8"; * request2.Accept = "application/json; charset=utf-8"; * var response2 = request2.GetResponse(); * if (((HttpWebResponse)response2).StatusCode == HttpStatusCode.OK) * { * System.IO.Stream dataStream = response2.GetResponseStream(); * System.IO.StreamReader reader = new System.IO.StreamReader(dataStream); * using (var sr = new System.IO.StreamReader(response2.GetResponseStream())) * { * string json = sr.ReadToEnd(); * _parent.Trace("--------------GETTING Music Next Selection Result ------" + json); * var deserializer = new JavaScriptSerializer(); * var ItemData = deserializer.Deserialize<MusicSelection.Rootobject>(json); * _parent.Trace("---------------Get Next Selection: Issue: Results.Count: " + ItemData.TotalRecordCount); * foreach (var id in ItemData.Items) * { * if (id.Name == param) * { * _parent.Trace("----------- Next Music Next Selection Run ---" + param + " ID Result equals: " + id.Id); * return id.Id; * } * } * * } * } * * * * * return null; */ } catch (Exception ex) { _parent.Trace("ERROR in Main Music Selection obtaining: " + ex); return(""); } }
public void RefreshNowPlaying() { lock (Locker) { /*if (_parent.MpcLoaded) * { * var result = _parent.MpcHcRemote.GetStatus(); * var result2 = new ArrayList(); * MpcHcRemote.ParseCSVFields(result2, result); * var data = (string[])result2.ToArray(typeof(string)); * if (data.Length > 6) * { * _nowPlaying.MediaType = "Video"; * _nowPlaying.Title = "Media Player Classic"; * _nowPlaying.Time = new TimeSpan(0, 0, 0, Convert.ToInt32("0" + data[2]) / 1000); * _nowPlaying.Duration = new TimeSpan(0, 0, 0, Convert.ToInt32("0" + data[4]) / 1000); * var percent = Math.Floor(100.0 * Convert.ToInt32("0" + data[2], CultureInfo.InvariantCulture) / Convert.ToInt32("0" + data[4], CultureInfo.InvariantCulture)); * if (Double.IsNaN(percent)) * percent = 0; * _nowPlaying.Volume = Convert.ToInt32("0" + data[7], CultureInfo.InvariantCulture); * _nowPlaying.IsMuted = data[6] == "1"; * _nowPlaying.Progress = (int)percent; * * if (data[1] == "Playing") * { * _parent.Log("XBMC PLAYER REMOTE: Playing given Changing NowPlaying to true " + data[1]); * _nowPlaying.IsPlaying = true; * _nowPlaying.IsPaused = false; * } * if (data[1] == "Paused") * { * _parent.Log("XBMC PLAYER REMOTE: Paused given Changing NowPlaying to true " + data[1]); * _nowPlaying.IsPaused = true; * _nowPlaying.IsPlaying = !_nowPlaying.IsPaused; * } * * } * if (_parent.MpcLoaded == false) * { * _nowPlaying.FileName = "Glenn MPC Stopped"; * _nowPlaying.Title = ""; * _nowPlaying.IsPlaying = false; * _nowPlaying.IsPaused = false; * } * } * else * { * if (!_parent.IsConnected()) * { * _nowPlaying.FileName = ""; * _nowPlaying.Title = ""; * _nowPlaying.IsPlaying = false; * _nowPlaying.IsPaused = false; * _parent.Log("XBMC PLAYER REMOTE: Returning as no !Player Connected"); * * return; * } * //_parent.Log("XBMC PLAYER REMOTE: Check with MPC Doesnt make it here"); * /* */ /* * var GUIproperties = new JsonObject(); * GUIproperties["properties"] = new[] * { * "currentwindow" * * * }; * * var menuresult = (JsonObject)_parent.JsonCommand("GUI.GetProperties", GUIproperties); * var GUIdeeper = (JsonObject)menuresult["currentwindow"]; * _nowPlaying.CurrentMenuLabel = GUIdeeper["label"].ToString(); * _nowPlaying.CurrentMenuID = GUIdeeper["id"].ToString(); * * * var current = -1; * var players = (JsonArray)_parent.JsonCommand("Player.GetActivePlayers", null); * * * if (players.Count > 0) * { * foreach (JsonObject player in players) * { * if (player["type"].ToString() == "picture") * continue; * current = Int32.Parse(player["playerid"].ToString()); * _nowPlaying.MediaType = (string)player["type"]; * } * } * * if (current == -1) * { * _nowPlaying.FileName = ""; * _nowPlaying.Title = ""; * _nowPlaying.IsPlaying = false; * _nowPlaying.IsPaused = false; * return; * } * * var items = new JsonObject(); * items["playerid"] = current; * items["properties"] = new[]{ * "file", * "comment", * "tvshowid", * "albumartist", * "duration", * //"id", * "album", * //"votes", * // "mpaa", * // "writer", * //"albumid", * //"type", * "genre", * "year", * //"plotoutline", * "track", * "artist", * //"season", * //"imdbnumber", * // "studio", * //"showlink", * "showtitle", * "episode", * "season", * "plot", * "director", * "studio", * "rating", * //"productioncode", * //"country", * //"premiered", * //"originaltitle", * //"artistid", * //"firstaired", * "tagline", * "thumbnail", * "fanart" * //"top250", * //"trailer" * }; * * var properties = new JsonObject(); * properties["playerid"] = current; * properties["properties"] = new[]{ * "totaltime", * "percentage", * "time", * "speed" * }; * * var appproperties = new JsonObject(); * appproperties["properties"] = new[] * { * "muted", * "volume" * }; * * var result1 = (JsonObject)_parent.JsonCommand("Player.GetProperties", properties); * var result2 = (JsonObject)_parent.JsonCommand("Player.GetItem", items); * var result3 = (JsonObject)_parent.JsonCommand("Application.GetProperties", appproperties); * * * if (result1 == null || result2 == null || result3 == null) * { * _nowPlaying.FileName = ""; * _nowPlaying.Title = ""; * _nowPlaying.IsPlaying = false; * _nowPlaying.IsPaused = false; * return; * } * * result2 = (JsonObject)(result2)["item"]; * * * * * * * * if (_nowPlaying.MediaType == "video") * { * if (result2["type"].ToString() == "channel") //if PVR Needs to go high otherwise exception * { * _nowPlaying.MediaType = "Pvr"; * _nowPlaying.IsNewMedia = true; * _nowPlaying.FileName = result2["label"].ToString(); * _nowPlaying.ThumbURL = result2["thumbnail"].ToString(); * _nowPlaying.FanartURL = result2["fanart"].ToString(); * _nowPlaying.Title = result2["label"].ToString(); * _nowPlaying.IsPaused = Convert.ToInt32("0" + result1["speed"].ToString().Replace("-", "")) == 0; * _nowPlaying.IsPlaying = !_nowPlaying.IsPaused; * var pvrtime = (JsonObject)result1["time"]; * var pvrtotal = (JsonObject)result1["totaltime"]; * _nowPlaying.Time = new TimeSpan(0, Convert.ToInt32("0" + pvrtime["hours"]), Convert.ToInt32("0" + pvrtime["minutes"]), Convert.ToInt32("0" + pvrtime["seconds"])); * _nowPlaying.Duration = new TimeSpan(0, Convert.ToInt32("0" + pvrtotal["hours"]), Convert.ToInt32("0" + pvrtotal["minutes"]), Convert.ToInt32("0" + pvrtotal["seconds"])); * _nowPlaying.Progress = Convert.ToInt32("0" + result1["percentage"].ToString().Split('.')[0]); * _nowPlaying.Volume = Convert.ToInt32("0" + result3["volume"]); * _nowPlaying.IsMuted = (bool)result3["muted"]; * return; * } * } * * _nowPlaying.IsPaused = Convert.ToInt32("0" + result1["speed"].ToString().Replace("-", "")) == 0; * _nowPlaying.IsPlaying = !_nowPlaying.IsPaused; * var time = (JsonObject)result1["time"]; * var total = (JsonObject)result1["totaltime"]; * _nowPlaying.Time = new TimeSpan(0, Convert.ToInt32("0" + time["hours"]), Convert.ToInt32("0" + time["minutes"]), Convert.ToInt32("0" + time["seconds"])); * _nowPlaying.Duration = new TimeSpan(0, Convert.ToInt32("0" + total["hours"]), Convert.ToInt32("0" + total["minutes"]), Convert.ToInt32("0" + total["seconds"])); * _nowPlaying.Progress = Convert.ToInt32("0" + result1["percentage"].ToString().Split('.')[0]); * _nowPlaying.Volume = Convert.ToInt32("0" + result3["volume"]); * _nowPlaying.IsMuted = (bool)result3["muted"]; * * _parent.MpcLoaded = _nowPlaying.Duration == new TimeSpan(0, 0, 0, 1); * * _nowPlaying.FileName = result2["file"].ToString(); * * if (_nowPlaying.MediaType == "audio") * { * _nowPlaying.MediaType = "Audio"; * _nowPlaying.Genre = _parent.JsonArrayToString((JsonArray)result2["genre"]); * _nowPlaying.Title = result2["label"].ToString(); * _nowPlaying.Year = Convert.ToInt32("0" + result2["year"]); * _nowPlaying.Track = Convert.ToInt32("0" + result2["track"]); * _nowPlaying.Artist = _parent.JsonArrayToString((JsonArray)result2["artist"]); * _nowPlaying.Album = result2["album"].ToString(); * _nowPlaying.ThumbURL = result2["thumbnail"].ToString(); * _nowPlaying.FanartURL = result2["fanart"].ToString(); * } * * if (_nowPlaying.MediaType == "video") * { * _nowPlaying.MediaType = result2["type"].ToString() == "episode" ? "TvShow" : "Movie"; * * * * _nowPlaying.Genre = _parent.JsonArrayToString((JsonArray)result2["genre"]); * _nowPlaying.Title = result2["label"].ToString(); * _nowPlaying.Year = Convert.ToInt32("0" + result2["year"]); * _nowPlaying.SeasonNumber = Convert.ToInt32("0" + result2["season"].ToString().Replace("-", "")); * _nowPlaying.EpisodeNumber = Convert.ToInt32("0" + result2["episode"].ToString().Replace("-", "")); * _nowPlaying.ShowTitle = result2["showtitle"].ToString(); * _nowPlaying.Plot = result2["plot"].ToString(); * _nowPlaying.Director = _parent.JsonArrayToString((JsonArray)result2["director"]); * _nowPlaying.Studio = _parent.JsonArrayToString((JsonArray)result2["studio"]); * _nowPlaying.Tagline = result2["tagline"].ToString(); * _nowPlaying.Rating = result2["rating"].ToString(); * _nowPlaying.ThumbURL = result2["thumbnail"].ToString(); * _nowPlaying.FanartURL = result2["fanart"].ToString(); * } */ if (!_parent.IsConnected()) { _nowPlaying.FileName = ""; _nowPlaying.Title = ""; _nowPlaying.IsPlaying = false; _nowPlaying.IsPaused = false; _parent.Log("Emby PLAYER REMOTE: Returning as no !Player Connected"); return; } try { _parent.Trace("Emby: Using Parent IP equals: " + _parent.IP); string NPurl = "http://" + _parent.IP + ":" + _parent.Port; var request = WebRequest.CreateHttp(NPurl + "/FrontView"); request.Method = "get"; //request.Timeout = 5000; _parent.Log("--------------- PLAYER CONNECTION: IP " + _parent.IP + ":" + _parent.Port); var authString = _parent.GetAuthString(); _parent.Log("------------------- Username Parent :" + _parent.UserName); _parent.Log("------------------- CurrentUserID Parent :" + _parent.CurrentUserID); _parent.Log("------------------- EMBY TOKEN EQUALS :" + Globals.EmbyAuthToken); //_parent.Log("AuthString " + authString); request.Headers.Add("X-MediaBrowser-Token", Globals.EmbyAuthToken); request.KeepAlive = false; request.Headers.Add("Authorization", authString); request.ContentType = "application/json; charset=utf-8"; // request.ContentLength = postArg.Length; request.Accept = "application/json"; var response = request.GetResponse(); if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK) { // Use MPC Remote _parent.MpcLoaded = true; System.IO.Stream dataStream = response.GetResponseStream(); //REMOVETHIS System.IO.StreamReader reader = new System.IO.StreamReader(dataStream); using (var sr = new System.IO.StreamReader(response.GetResponseStream())) { string json = sr.ReadToEnd(); _parent.Trace("--------------Using FrontView Emby Plugin Data ------" + json); var deserializer = new JavaScriptSerializer(); var server = deserializer.Deserialize <EmbyServerPlugin.ApiInfo>(json); _parent.Trace("------------- FrontView Emby Plugin: Now Checking Results :results.Count:" + server.Filename); //Check Something is Playing and Return //If Doesnt return - something must be playing. _parent.Trace("------------- FrontView Emby Plugin: server.Filename equals:" + server.Filename); if (String.IsNullOrEmpty(server.Filename)) { _nowPlaying.FileName = ""; _nowPlaying.Title = ""; _nowPlaying.IsPlaying = false; _nowPlaying.IsPaused = false; _nowPlaying.IsPlaying = false; _parent.Trace("--------------EMBY NOW PLAYING Log: Nothing is Playing"); response.Close(); return; } // OK - Ignore these filenames theme.mp3 for one // ? Video Backgrounds as well will figure out // if (server.Filename.EndsWith("theme.mp3") || server.Filename.EndsWith("theme.mp4")) { _nowPlaying.FileName = ""; _nowPlaying.Title = ""; _nowPlaying.IsPlaying = false; _nowPlaying.IsPaused = false; _nowPlaying.IsPlaying = false; _parent.Trace("--------------Emby Now Playing Theme Video NowPlaying IGNORE This. Filename:" + server.Filename); response.Close(); return; } //Something must be playing- at least something with a filename //We will find out how full proof that is later. //_nowPlaying.IsNewMedia = true; _parent.Trace("-------------- Emby Emby Plugin: IsNewMedia:" + _nowPlaying.IsNewMedia); if (server.Filename != null) { if (server.IsPaused == true) { _nowPlaying.IsPlaying = false; _nowPlaying.IsPaused = true; } if (server.IsPaused == false) { _nowPlaying.IsPlaying = true; _nowPlaying.IsPaused = false; } if (server.MediaType == "Audio") { _nowPlaying.MediaType = "Audio"; _nowPlaying.Album = server.Album; _nowPlaying.Year = Convert.ToInt32("0" + server.Year); _nowPlaying.Track = Convert.ToInt32("0" + server.EpisodeNumber); _nowPlaying.Title = server.Title; _nowPlaying.FileName = server.Filename; _parent.Log("------------- EMBY Trying to get Audio Images"); _parent.Log("------------- EMBY IMAGES: FanartURL " + "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Backdrop"); _nowPlaying.FanartURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.BackdropItemId + "/Images/Primary"; _nowPlaying.ThumbURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Primary"; _nowPlaying.Artist = server.Artist; } if (server.MediaType == "Episode") { _nowPlaying.MediaType = "TvShow"; _nowPlaying.EpisodeNumber = Convert.ToInt32("0" + server.EpisodeNumber); _nowPlaying.SeasonNumber = Convert.ToInt32("0" + server.SeasonNumber); _nowPlaying.ShowTitle = String.IsNullOrEmpty(server.ShowTitle) ? "" : server.ShowTitle; _nowPlaying.Title = String.IsNullOrEmpty(server.Title) ? "Blank" : server.Title; _nowPlaying.Plot = String.IsNullOrEmpty(server.Overview) ? "" : server.Overview; _nowPlaying.FileName = server.Filename; //Filename _parent.Log("------------- EMBY Trying to get Images"); _parent.Log("------------- EMBY IMAGES: FanartURL " + "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Backdrop"); _nowPlaying.FanartURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.BackdropItemId + "/Images/Backdrop"; _nowPlaying.ThumbURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Primary"; } if (server.MediaType == "ChannelVideoItem") { _nowPlaying.MediaType = "Movie"; //_nowPlaying.ShowTitle = server.NowPlayingItem.SeriesName; _nowPlaying.Title = server.Title; _nowPlaying.FileName = server.Filename; //No Filename as yet try ID _parent.Log("------------- EMBY Trying to get Images"); _parent.Log("------------- EMBY IMAGES: FanartURL " + "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Backdrop"); _nowPlaying.FanartURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Backdrop"; _nowPlaying.ThumbURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Primary"; } if (server.MediaType == "Movie") { _nowPlaying.MediaType = "Movie"; //_nowPlaying.EpisodeNumber = server.NowPlayingItem.IndexNumber; // _nowPlaying.SeasonNumber = server.NowPlayingItem.ParentIndexNumber; // _nowPlaying.ShowTitle = server.NowPlayingItem.SeriesName; _nowPlaying.Title = server.Title; _nowPlaying.Plot = server.Overview; _nowPlaying.Director = server.Director; _nowPlaying.Rating = server.Rating; _nowPlaying.FileName = server.Filename; _parent.Log("------------- EMBY Trying to get Images"); _parent.Log("------------- EMBY IMAGES: FanartURL " + "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Backdrop"); _nowPlaying.FanartURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Backdrop"; _nowPlaying.ThumbURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Primary"; } if (server.MediaType == "Video") { _nowPlaying.MediaType = "Movie"; //_nowPlaying.EpisodeNumber = server.NowPlayingItem.IndexNumber; // _nowPlaying.SeasonNumber = server.NowPlayingItem.ParentIndexNumber; // _nowPlaying.ShowTitle = server.NowPlayingItem.SeriesName; _nowPlaying.Title = server.Title; _nowPlaying.Plot = server.Overview; _nowPlaying.Director = server.Director; _nowPlaying.Rating = server.Rating; _nowPlaying.FileName = server.Filename; _parent.Log("------------- EMBY Trying to get Images"); _parent.Log("------------- EMBY IMAGES: FanartURL " + "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Backdrop"); _nowPlaying.FanartURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Backdrop"; _nowPlaying.ThumbURL = "http://" + _parent.IP + ":" + _parent.Port + "/Items/" + server.PrimaryItemId + "/Images/Primary"; } var Seconds = Convert.ToInt64(server.Duration); var TimePosition = Convert.ToInt64(server.TimePosition); var RoundSeconds = Math.Round(Seconds / 10000000.00, 1); var RoundTime = Math.Round(TimePosition / 10000000.00, 2); //_parent.Log("--------------TIME CONVERSION BUGGER: RoundSeconds:" + RoundSeconds + " Orginal Time RunTimeTicks:"+server.NowPlayingItem.RunTimeTicks); _nowPlaying.Duration = new TimeSpan(0, 0, 0, Convert.ToInt32(RoundSeconds)); _nowPlaying.Time = new TimeSpan(0, 0, 0, Convert.ToInt32(RoundTime)); double percent = (100.0 * TimePosition) / Seconds; percent = Math.Round(percent, 0); //Change to Primary Image - seems to be better format. _parent.Log("Percent of Time equals:" + percent); if (Double.IsNaN(percent)) { percent = 0; } _nowPlaying.Progress = (int)percent; _nowPlaying.IsMuted = server.IsMuted; _nowPlaying.Volume = Convert.ToInt32(server.Volume); _nowPlaying.Tagline = server.Tagline; _nowPlaying.Studio = server.Studio; if (server.AirDate.HasValue) { _nowPlaying.FirstAired = server.AirDate.Value; } response.Close(); return; } } } else //Hopefully is HTTP Status Not OK { _nowPlaying.FileName = ""; _nowPlaying.Title = ""; _nowPlaying.IsPlaying = false; _nowPlaying.IsPaused = false; _nowPlaying.IsPlaying = false; _parent.Trace("--------------EMBY NOW PLAYING Log: Nothing is Playing"); response.Close(); return; } } catch (Exception ex) { _parent.Log("Exception in NowPlaying EMBY System" + ex); _parent.MpcLoaded = false; return; } } }
public bool Command(string cmd, string parameter) { if (Globals.ClientSupportsRemoteControl == null) { _parent.Log("EMBY COMMAND: ClientSupportsRemote currently null rechecking..."); Globals.ClientSupportsRemoteControl = _parent.GetPlaybackClientSupportsRemote(); _parent.Log("EMBY COMMAND: ClientSupportsRemote now:" + Globals.ClientSupportsRemoteControl); } if (Globals.ClientSupportsRemoteControl == false) { _parent.Log("-----EMBY COMMAND: Current Client DOES NOT SUPPORT REMOTE CONTROL -- No Command Sent"); _parent.Log("-----EMBY COMMAND: GLobals SupportsRemote " + Globals.ClientSupportsRemoteControl + "Global ClientID:" + Globals.SessionIDClient); return(false); } if (String.IsNullOrEmpty(Globals.SessionIDClient)) { Globals.SessionIDClient = _parent.GetYatseInfoPlayingClient(); } HttpWebRequest request; var returnContent = false; var authString = _parent.GetAuthString(); var uri = @"http://" + _parent.IP + ":" + _parent.Port + "/emby/Sessions/" + Globals.SessionIDClient + "/Playing/"; if (!String.IsNullOrEmpty(cmd)) { uri += cmd; } _parent.Log(" ---------EMBY PLAY COMMAND: TESTING URL:" + uri + ":::::"); try { request = (HttpWebRequest)WebRequest.Create(new Uri(uri)); request.Headers.Add("X-MediaBrowser-Token", Globals.EmbyAuthToken); request.Headers.Add("X-Emby-Authorization", authString); request.ContentType = "application/json"; ASCIIEncoding encoder = new ASCIIEncoding(); byte[] data = encoder.GetBytes(""); request.ContentLength = data.Length; request.Expect = "application/json"; request.Method = "POST"; request.Timeout = 1000; _parent.Log("Emby COMMAND : " + cmd); _parent.Trace(uri); using (var response = (HttpWebResponse)request.GetResponse()) { using (var stream = response.GetResponseStream()) { if (stream != null) { using (var reader = new StreamReader(stream, Encoding.UTF8)) { var reqContent = reader.ReadToEnd(); _parent.Trace(reqContent); returnContent = true; } } } } } catch (WebException e) { _parent.Log("ERROR - EMBY Command : " + cmd + " - " + e.Message); if (e.Status == WebExceptionStatus.Timeout) { // _parent.MpcLoaded = false; } } return(returnContent); }