public static void Send_Media(List <SVR_VideoLocal> locals) { //if (!ServerSettings.WebCache_XRefFileEpisode_Send) return; string uri = string.Format(@"http://{0}/api/Media", azureHostBaseAddress); List <Azure_Media_Request> inputs = new List <Azure_Media_Request>(); // send a max of 25 at a time // send a max of 25 at a time foreach (SVR_VideoLocal v in locals.Where(a => a.MediaBlob != null && a.MediaBlob.Length > 0 && a.MediaVersion == SVR_VideoLocal.MEDIA_VERSION && !string.IsNullOrEmpty(a.ED2KHash))) { Azure_Media_Request input = v.ToMediaRequest(); if (inputs.Count < 25) { inputs.Add(input); } else { string json = JsonConvert.SerializeObject(inputs); //json = Newtonsoft.Json.JsonConvert.SerializeObject(inputs); SendData(uri, json, "POST"); inputs.Clear(); } } if (inputs.Count > 0) { string json = JsonConvert.SerializeObject(inputs); SendData(uri, json, "POST"); } }
public static void Send_Media(string ed2k, Shoko.Models.PlexAndKodi.Media media) { //if (!ServerSettings.WebCache_XRefFileEpisode_Send) return; string uri = string.Format(@"http://{0}/api/Media", azureHostBaseAddress); List <Azure_Media_Request> inputs = new List <Azure_Media_Request>(); Azure_Media_Request input = media.ToMediaRequest(ed2k); inputs.Add(input); string json = JsonConvert.SerializeObject(inputs); SendData(uri, json, "POST"); }
public static Azure_Media_Request ToMediaRequest(this SVR_VideoLocal v) { Azure_Media_Request r = new Azure_Media_Request(); r.ED2K = v.ED2KHash; //Cleanup any File subtitles from media information. Media m = v.Media.DeepClone(); if (m.Parts != null && m.Parts.Count > 0) { foreach (Part p in m.Parts) { if (p.Streams != null) { List <Stream> streams = p.Streams .Where(a => a.StreamType == "3" && !String.IsNullOrEmpty(a.File)) .ToList(); if (streams.Count > 0) { streams.ForEach(a => p.Streams.Remove(a)); } } } } //Cleanup the VideoLocal id m.Id = null; int outsize; byte[] data = CompressionHelper.SerializeObject(m, out outsize); r.ED2K = v.ED2KHash; r.MediaInfo = new byte[data.Length + 4]; r.MediaInfo[0] = (byte)(outsize >> 24); r.MediaInfo[1] = (byte)((outsize >> 16) & 0xFF); r.MediaInfo[2] = (byte)((outsize >> 8) & 0xFF); r.MediaInfo[3] = (byte)(outsize & 0xFF); Array.Copy(data, 0, r.MediaInfo, 4, data.Length); r.Version = SVR_VideoLocal.MEDIA_VERSION; r.Username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) { r.Username = Constants.AnonWebCacheUsername; } r.AuthGUID = String.IsNullOrEmpty(ServerSettings.WebCacheAuthKey) ? "" : ServerSettings.WebCacheAuthKey; return(r); }
public static void Send_Media(List <SVR_VideoLocal> locals) { //if (!ServerSettings.Instance.WebCache.XRefFileEpisode_Send) return; if (locals == null || locals.Count == 0) { return; } try { string uri = $@"http://{azureHostBaseAddress}/api/Media"; List <Azure_Media_Request> inputs = new List <Azure_Media_Request>(); // send a max of 25 at a time // send a max of 25 at a time foreach (SVR_VideoLocal v in locals.Where(a => a.MediaBlob?.Length > 0 && a.MediaVersion == SVR_VideoLocal.MEDIA_VERSION && !string.IsNullOrEmpty(a.ED2KHash))) { Azure_Media_Request input = v.ToMediaRequest(); if (inputs.Count < 25) { inputs.Add(input); } else { string json = JSONHelper.Serialize(inputs); //json = Newtonsoft.Json.JsonConvert.SerializeObject(inputs); SendData(uri, json, "POST"); inputs.Clear(); } } if (inputs.Count <= 0) { string json = JSONHelper.Serialize(inputs); SendData(uri, json, "POST"); } } catch (Exception ex) { logger.Warn($"There was an error sending MediaInfo to WebCache for {locals.FirstOrDefault().ED2KHash}: {ex.Message}"); } }
public static Azure_Media_Request ToMediaRequest(this SVR_VideoLocal v) { //Cleanup any File subtitles from media information. Media m = (Media)v.Media.Clone(); if (m.Parts != null && m.Parts.Count > 0) { foreach (Part p in m.Parts) { if (p.Streams != null) { List <Stream> streams = p.Streams .Where(a => a.StreamType == 3 && !string.IsNullOrEmpty(a.File)) .ToList(); if (streams.Count > 0) { streams.ForEach(a => p.Streams.Remove(a)); } } } } //Cleanup the VideoLocal id byte[] data = CompressionHelper.SerializeObject(m, out int outsize); m.Id = 0; Azure_Media_Request r = new Azure_Media_Request { ED2K = v.ED2KHash, Version = SVR_VideoLocal.MEDIA_VERSION, Username = Constants.AnonWebCacheUsername, AuthGUID = string.Empty, MediaInfo = new byte[data.Length + 4] }; r.MediaInfo[0] = (byte)(outsize >> 24); r.MediaInfo[1] = (byte)((outsize >> 16) & 0xFF); r.MediaInfo[2] = (byte)((outsize >> 8) & 0xFF); r.MediaInfo[3] = (byte)(outsize & 0xFF); Array.Copy(data, 0, r.MediaInfo, 4, data.Length); return(r); }
public static Azure_Media_Request ToMediaRequest(this Media m, string ed2k) { byte[] data = CompressionHelper.SerializeObject(m, out int outsize); Azure_Media_Request r = new Azure_Media_Request { ED2K = ed2k, MediaInfo = new byte[data.Length + 4], Version = SVR_VideoLocal.MEDIA_VERSION, Username = Constants.AnonWebCacheUsername, AuthGUID = string.Empty }; r.MediaInfo[0] = (byte)(outsize >> 24); r.MediaInfo[1] = (byte)((outsize >> 16) & 0xFF); r.MediaInfo[2] = (byte)((outsize >> 8) & 0xFF); r.MediaInfo[3] = (byte)(outsize & 0xFF); Array.Copy(data, 0, r.MediaInfo, 4, data.Length); return(r); }
public static Azure_Media_Request ToMediaRequest(this Media m, string ed2k) { Azure_Media_Request r = new Azure_Media_Request(); byte[] data = CompressionHelper.SerializeObject(m, out int outsize); r.ED2K = ed2k; r.MediaInfo = new byte[data.Length + 4]; r.MediaInfo[0] = (byte)(outsize >> 24); r.MediaInfo[1] = (byte)((outsize >> 16) & 0xFF); r.MediaInfo[2] = (byte)((outsize >> 8) & 0xFF); r.MediaInfo[3] = (byte)(outsize & 0xFF); Array.Copy(data, 0, r.MediaInfo, 4, data.Length); r.Version = SVR_VideoLocal.MEDIA_VERSION; r.Username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) { r.Username = Constants.AnonWebCacheUsername; } r.AuthGUID = string.IsNullOrEmpty(ServerSettings.WebCacheAuthKey) ? string.Empty : ServerSettings.WebCacheAuthKey; return(r); }
public static void Send_Media(string ed2k, Shoko.Models.PlexAndKodi.Media media) { if (string.IsNullOrEmpty(ed2k)) { return; } try { string uri = $@"http://{azureHostBaseAddress}/api/Media"; List <Azure_Media_Request> inputs = new List <Azure_Media_Request>(); Azure_Media_Request input = media.ToMediaRequest(ed2k); inputs.Add(input); string json = JSONHelper.Serialize(inputs); SendData(uri, json, "POST"); } catch (Exception ex) { logger.Warn($"There was an error sending MediaInfo to WebCache for {ed2k}: {ex.Message}"); } }