Esempio n. 1
0
        /// <summary>
        ///     获取上传的文件,返回list集合
        /// </summary>
        /// <param name="type">0:图片,1:音频,2:视频</param>
        /// <returns></returns>
        public List <FileUpload> FileUpload(int type)
        {
            var flv = new List <string> {
                ".avi", ".rmvb", ".wmv", ".flv"
            };

            var listfileUpload = new List <FileUpload>();

            HttpFileCollectionBase files = Request.Files;

            for (int i = 0; i < files.Count; i++)
            {
                var    fileUpload = new FileUpload();
                string fileName   = Path.GetFileName(files[i].FileName);
                string fileExten  = Path.GetExtension(fileName); //扩展名

                if (type != 2 || (type == 2 && flv.Contains(fileExten.ToLower())))
                {
                    var SaveFileName = DateTime.Now.ToString("yyyymmddhhmmss") +
                                       (new Random().Next(10, 99).ToString()) + i.ToString();

                    var oldName    = SaveFileName + fileExten;
                    var converName = SaveFileName + ".flv";
                    fileUpload.FileName = oldName;
                    if (type == 2)
                    {
                        fileUpload.FileName = converName;
                    }

                    //保存的文件名,防止名称冲突
                    fileUpload.FileType = type;
                    fileUpload.RealName = fileName;
                    listfileUpload.Add(fileUpload);

                    if (!Directory.Exists(Server.MapPath("../ClientBin/UploadFile")))
                    {
                        Directory.CreateDirectory(Server.MapPath("../ClientBin/UploadFile"));
                    }

                    string path = "../ClientBin/UploadFile/";

                    if (type == 2)
                    {
                        files[i].SaveAs(Server.MapPath(path + oldName));
                        if (fileExten.ToLower() != ".flv")
                        {
                            var    mc = new MediaConvert(oldName, converName);
                            Thread th = new Thread(new ThreadStart(mc.ConvertMedia));
                            th.Start();
                        }
                    }
                    else
                    {
                        files[i].SaveAs(Server.MapPath(path + fileUpload.FileName));
                    }
                }
            }
            return(listfileUpload);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }