Exemplo n.º 1
0
        public string ToStringDetailed()
        {
            StringBuilder sb = new StringBuilder("");

            sb.Append(Environment.NewLine);
            sb.Append("VideoLocalID: " + VideoLocalID.ToString());

            sb.Append(Environment.NewLine);
            sb.Append("FileName: " + FileName);

/*            sb.Append(Environment.NewLine);
 *          sb.Append("ImportFolderID: " + ImportFolderID.ToString());*/
            sb.Append(Environment.NewLine);
            sb.Append("Hash: " + Hash);
            sb.Append(Environment.NewLine);
            sb.Append("FileSize: " + FileSize.ToString());
            sb.Append(Environment.NewLine);

            /*
             * try
             * {
             *  if (ImportFolder != null)
             *      sb.Append("ImportFolderLocation: " + ImportFolder.ImportFolderLocation);
             * }
             * catch (Exception ex)
             * {
             *  sb.Append("ImportFolderLocation: " + ex.ToString());
             * }
             *
             * sb.Append(Environment.NewLine);
             */
            return(sb.ToString());
        }
Exemplo n.º 2
0
        public string ToStringDetailed()
        {
            StringBuilder sb = new StringBuilder("");

            sb.Append(Environment.NewLine);
            sb.Append("VideoLocalID: " + VideoLocalID.ToString());
            sb.Append(Environment.NewLine);
            sb.Append("FilePath: " + FilePath);
            sb.Append(Environment.NewLine);
            sb.Append("ImportFolderID: " + ImportFolderID.ToString());
            sb.Append(Environment.NewLine);
            sb.Append("Hash: " + Hash);
            sb.Append(Environment.NewLine);
            sb.Append("FileSize: " + FileSize.ToString());
            sb.Append(Environment.NewLine);

            try
            {
                if (ImportFolder != null)
                {
                    sb.Append("ImportFolderLocation: " + ImportFolder.ImportFolderLocation);
                }
            }
            catch (Exception ex)
            {
                sb.Append("ImportFolderLocation: " + ex.ToString());
            }

            sb.Append(Environment.NewLine);

            return(sb.ToString());
        }
Exemplo n.º 3
0
        public Media GetMediaFromUser(int userID)
        {
            Media n = null;

            if (Media == null)
            {
                VideoLocal_Place pl = GetBestVideoLocalPlace();
                if (pl != null)
                {
                    IFileSystem f = pl.ImportFolder.FileSystem;
                    FileSystemResult <IObject> src = f.Resolve(pl.FullServerPath);
                    if (src != null && src.IsOk && src.Result is IFile)
                    {
                        if (pl.RefreshMediaInfo())
                        {
                            RepoFactory.VideoLocal.Save(pl.VideoLocal, true);
                        }
                    }
                }
            }
            if (Media != null)
            {
                n = Media.DeepClone();
                if (n?.Parts != null)
                {
                    foreach (Part p in n?.Parts)
                    {
                        string name = UrlSafe.Replace(Path.GetFileName(FileName), " ").Replace("  ", " ").Replace("  ", " ").Trim();
                        name = UrlSafe2.Replace(name, string.Empty).Trim().Replace("..", ".").Replace("..", ".").Replace("__", "_").Replace("__", "_").Replace(" ", "_").Replace("_.", ".");
                        while (name.StartsWith("_"))
                        {
                            name = name.Substring(1);
                        }
                        while (name.StartsWith("."))
                        {
                            name = name.Substring(1);
                        }
                        p.Key = PlexAndKodi.Helper.ReplaceSchemeHost(PlexAndKodi.Helper.ConstructVideoLocalStream(userID, VideoLocalID.ToString(), name, false));
                        if (p.Streams != null)
                        {
                            foreach (Stream s in p.Streams.Where(a => a.File != null && a.StreamType == "3"))
                            {
                                s.Key = PlexAndKodi.Helper.ReplaceSchemeHost(PlexAndKodi.Helper.ConstructFileStream(userID, s.File, false));
                            }
                        }
                    }
                }
            }
            return(n);
        }
Exemplo n.º 4
0
        public bool RefreshMediaInfo()
        {
            try
            {
                logger.Trace($"Getting media info for: {FullServerPath}");
                Media m = null;
                List <Providers.Azure.Media> webmedias = AzureWebAPI.Get_Media(VideoLocal.ED2KHash);
                if (webmedias != null && webmedias.Count > 0)
                {
                    m = webmedias[0].GetMedia();
                }
                if (m == null)
                {
                    string name = (ImportFolder.CloudID == null)
                        ? FullServerPath.Replace("/", "\\")
                        : PlexAndKodi.Helper.ReplaceSchemeHost(PlexAndKodi.Helper.ConstructVideoLocalStream(0,
                                                                                                            VideoLocalID.ToString(), "file", false));
                    m = MediaConvert.Convert(name, GetFile()); //Mediainfo should have libcurl.dll for http
                    if (string.IsNullOrEmpty(m.Duration))
                    {
                        m = null;
                    }
                    if (m != null)
                    {
                        AzureWebAPI.Send_Media(VideoLocal.ED2KHash, m);
                    }
                }


                if (m != null)
                {
                    VideoLocal info = VideoLocal;
                    FillVideoInfoFromMedia(info, m);

                    m.Id = VideoLocalID.ToString();
                    List <JMMContracts.PlexAndKodi.Stream> subs = SubtitleHelper.GetSubtitleStreams(this);
                    if (subs.Count > 0)
                    {
                        m.Parts[0].Streams.AddRange(subs);
                    }
                    foreach (Part p in m.Parts)
                    {
                        p.Id         = null;
                        p.Accessible = "1";
                        p.Exists     = "1";
                        bool vid = false;
                        bool aud = false;
                        bool txt = false;
                        foreach (JMMContracts.PlexAndKodi.Stream ss in p.Streams.ToArray())
                        {
                            if ((ss.StreamType == "1") && !vid)
                            {
                                vid = true;
                            }
                            if ((ss.StreamType == "2") && !aud)
                            {
                                aud         = true;
                                ss.Selected = "1";
                            }
                            if ((ss.StreamType == "3") && !txt)
                            {
                                txt         = true;
                                ss.Selected = "1";
                            }
                        }
                    }
                    info.Media = m;
                    return(true);
                }
                logger.Error($"File {FullServerPath} does not exist, unable to read media information from it");
            }
            catch (Exception e)
            {
                logger.Error($"Unable to read the media information of file {FullServerPath} ERROR: {e}");
            }
            return(false);
        }
Exemplo n.º 5
0
        public bool RefreshMediaInfo()
        {
            try
            {
                logger.Trace($"Getting media info for: {FullServerPath}");

                string name = (ImportFolder.CloudID == null) ? FullServerPath.Replace("/", "\\") : PlexAndKodi.Helper.ReplaceSchemeHost(PlexAndKodi.Helper.ConstructVideoLocalStream(0, VideoLocalID.ToString(), "file", false));

                Media m = MediaConvert.Convert(name, GetFile()); //Mediainfo should have libcurl.dll for http
                if (string.IsNullOrEmpty(m.Duration))
                {
                    m = null;
                }

                if (m != null)
                {
                    VideoLocal info = VideoLocal;
                    info.VideoResolution = (!string.IsNullOrEmpty(m.Width) && !string.IsNullOrEmpty(m.Height))
                        ? m.Width + "x" + m.Height
                        : string.Empty;
                    info.VideoCodec   = (!string.IsNullOrEmpty(m.VideoCodec)) ? m.VideoCodec : string.Empty;
                    info.AudioCodec   = (!string.IsNullOrEmpty(m.AudioCodec)) ? m.AudioCodec : string.Empty;
                    info.Duration     = (!string.IsNullOrEmpty(m.Duration)) ? (long)double.Parse(m.Duration, NumberStyles.Any, CultureInfo.InvariantCulture) : 0;
                    info.VideoBitrate = info.VideoBitDepth = info.VideoFrameRate = info.AudioBitrate = string.Empty;
                    List <JMMContracts.PlexAndKodi.Stream> vparts = m.Parts[0].Streams.Where(a => a.StreamType == "1").ToList();
                    if (vparts.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(vparts[0].Bitrate))
                        {
                            info.VideoBitrate = vparts[0].Bitrate;
                        }
                        if (!string.IsNullOrEmpty(vparts[0].BitDepth))
                        {
                            info.VideoBitDepth = vparts[0].BitDepth;
                        }
                        if (!string.IsNullOrEmpty(vparts[0].FrameRate))
                        {
                            info.VideoFrameRate = vparts[0].FrameRate;
                        }
                    }
                    List <JMMContracts.PlexAndKodi.Stream> aparts = m.Parts[0].Streams.Where(a => a.StreamType == "2").ToList();
                    if (aparts.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(aparts[0].Bitrate))
                        {
                            info.AudioBitrate = aparts[0].Bitrate;
                        }
                    }
                    m.Id = VideoLocalID.ToString();
                    List <JMMContracts.PlexAndKodi.Stream> subs = SubtitleHelper.GetSubtitleStreams(this);
                    if (subs.Count > 0)
                    {
                        m.Parts[0].Streams.AddRange(subs);
                    }
                    foreach (Part p in m.Parts)
                    {
                        p.Id         = null;
                        p.Accessible = "1";
                        p.Exists     = "1";
                        bool vid = false;
                        bool aud = false;
                        bool txt = false;
                        foreach (JMMContracts.PlexAndKodi.Stream ss in p.Streams.ToArray())
                        {
                            if ((ss.StreamType == "1") && !vid)
                            {
                                vid = true;
                            }
                            if ((ss.StreamType == "2") && !aud)
                            {
                                aud         = true;
                                ss.Selected = "1";
                            }
                            if ((ss.StreamType == "3") && !txt)
                            {
                                txt         = true;
                                ss.Selected = "1";
                            }
                        }
                    }
                    info.Media = m;
                    return(true);
                }
                logger.Error($"File {FullServerPath} do not exists, we're unable to read the media information from it");
            }
            catch (Exception e)
            {
                logger.Error($"Unable to read the media information of file {FullServerPath} ERROR: {e}");
            }
            return(false);
        }
Exemplo n.º 6
0
        public Media GetMediaFromUser(int userID)
        {
            Media n = null;

            if (Media == null)
            {
                if (File.Exists(FullServerPath))
                {
                    VideoLocalRepository repo = new VideoLocalRepository();
                    repo.Save(this, false);
                }
            }
            if (Media != null)
            {
                n = (Media)Media.DeepCopy();
                if (n?.Parts != null)
                {
                    foreach (Part p in n?.Parts)
                    {
                        string name = UrlSafe.Replace(Path.GetFileName(FilePath), " ").Replace("  ", " ").Replace("  ", " ").Trim();
                        name = UrlSafe2.Replace(name, string.Empty).Trim().Replace("..", ".").Replace("..", ".").Replace("__", "_").Replace("__", "_").Replace(" ", "_").Replace("_.", ".");
                        while (name.StartsWith("_"))
                        {
                            name = name.Substring(1);
                        }
                        while (name.StartsWith("."))
                        {
                            name = name.Substring(1);
                        }
                        p.Key = PlexAndKodi.Helper.ReplaceSchemeHost(PlexAndKodi.Helper.ConstructVideoLocalStream(userID, VideoLocalID.ToString(), name, false));
                        if (p.Streams != null)
                        {
                            foreach (Stream s in p.Streams.Where(a => a.File != null && a.StreamType == "3"))
                            {
                                s.Key = PlexAndKodi.Helper.ReplaceSchemeHost(PlexAndKodi.Helper.ConstructFileStream(userID, s.File, false));
                            }
                        }
                    }
                }
            }
            return(n);
        }