示例#1
0
        //更新店铺时语音转mp3
        public async Task <string> SendVoiceToAliOss(int itemId, int itemType, string sourceTempUrl)
        {
            if (itemId <= 0 || itemType <= 0 || string.IsNullOrEmpty(sourceTempUrl))
            {
                return(string.Empty);
            }
            C_Attachment model = GetModelByType(itemId, itemType);

            if (model == null)
            {
                model            = new C_Attachment();
                model.itemId     = itemId;
                model.itemType   = itemType;
                model.createDate = DateTime.Now;
                model.thumbnail  = "";
            }
            model.filepath = sourceTempUrl;
            try
            {
                if (!model.filepath.Contains("temp"))//不是新上传的,停止操作!
                {
                    return(string.Empty);
                }
                var    bucket      = ConfigurationManager.AppSettings["BucketName"];
                int    whichDomain = 1;
                string TemplateId  = string.Empty;
                string PipelineId  = string.Empty;
                TemplateId = ConfigurationManager.AppSettings["VoiceTemplateId"] ?? "42d5aac40e6a50bf13045a40aeb83b6f";
                PipelineId = ConfigurationManager.AppSettings["PipelineId"] ?? "4bc9dd15cb3d48e39e0824e19c41defb";
                var finalVoiceKey    = string.Empty;
                var finalVoiceFolder = AliOSSHelper.GetOssVoiceKey("mp3", false, "voice/folder", out finalVoiceKey, whichDomain);
                //上传的本地音频。并且不是mp3|| 微信语音
                if (!string.IsNullOrEmpty(model.VoiceServerId))
                {
                    //转换mp3
                    bool submitResult = await AliMTSHelper.SubmitJobs(model.filepath, finalVoiceKey, bucket, TemplateId, PipelineId, "", whichDomain);

                    if (submitResult)
                    {//转换成功。更新路径
                        model.thumbnail = finalVoiceKey;
                    }//音频转换失败
                    else
                    {
                        log4net.LogHelper.WriteInfo(this.GetType(), "语音给AliOSS转换格式失败!ID为" + model.id + "==" + model.filepath);
                    }
                }//mp3移动
                else
                {
                    //本地音频mp3格式从temp 拷贝
                    Task <bool> moveResult = Task <bool> .Factory.StartNew(
                        () =>
                    {
                        return(AliOSSHelper.CopyObect(model.filepath ?? "", finalVoiceKey));
                    }
                        );

                    if (await moveResult)
                    {//移动成功。更新路径
                        model.thumbnail = finalVoiceKey;
                    }
                    // 移动失败
                    else
                    {
                        log4net.LogHelper.WriteInfo(this.GetType(), "本地音频AliOSS临时文件夹移动到正式文件夹失败!ID为" + sourceTempUrl);
                        return("");
                    }
                }
                if (model.id == 0)
                {
                    Add(model);
                }
                else
                {
                    MySqlParameter[] param = new MySqlParameter[] { new MySqlParameter("@itemId", itemId),
                                                                    new MySqlParameter("@filepath", model.filepath),
                                                                    new MySqlParameter("@thumbnail", model.thumbnail),
                                                                    new MySqlParameter("@id", model.id) };
                    string sql = "update C_Attachment set itemId=@itemId,filepath=@filepath,thumbnail=@thumbnail where id=@id";
                    SqlMySql.ExecuteNonQuery(Utility.dbEnum.MINIAPP.ToString(), System.Data.CommandType.Text, sql, param);
                    RemoveRedis(model.itemId, model.itemType);
                }
                return("");
            }
            catch (Exception ex)
            {
                log4net.LogHelper.WriteError(this.GetType(), new Exception("voiceid" + model.id + "移动语音失败:" + ex.Message));
                return(string.Empty);
            }
        }
示例#2
0
        /// <summary>
        /// 更新店铺动态视频所属店铺动态id以及转移视频和图片-蔡华兴
        /// </summary>
        /// <param name="videopath"></param>
        /// <param name="oldhvid"></param>
        /// <param name="strategyId"></param>
        /// <param name="videotype"></param>
        /// <returns></returns>
        public async Task <bool> HandleVideoLogicStrategyAsync(string videopath, int oldhvid, int strategyId, int videotype)
        {
            int result = 0;

            try
            {
                if (!string.IsNullOrEmpty(videopath))
                {
                    //清除老视频
                    if (oldhvid > 0)
                    {
                        C_AttachmentVideo cattV = GetModel(oldhvid);
                        if (cattV != null)
                        {
                            Delete(oldhvid);
                            RemoveRedis(cattV.itemId, cattV.itemType);//清除缓存
                        }
                    }
                    C_AttachmentVideo cVideo  = new C_AttachmentVideo();
                    List <string>     extents = new List <string> {
                        "mp4", "ogg", "mpeg4", "webm", "MP4", "OGG", "MPEG4", "WEBM"
                    };
                    string fileType = videopath.Substring(videopath.LastIndexOf('.') + 1);

                    //判断是否需要转码
                    if (!extents.Contains(fileType))
                    {
                        var regex          = new Regex(@"(?i)\.[\S]*");
                        var tempconverpath = regex.Replace(videopath.Replace("temp/", "").Replace(fileType, "mp4"), ".mp4");
                        cVideo.convertFilePath = VideoAliMtsHelper.GetUrlFromKey(tempconverpath);

                        //转码
                        await VideoAliMtsHelper.SubMitVieoJob(videopath, cVideo.convertFilePath);

                        //获取封面图
                        var videoImgUrl = string.Empty;
                        var videoImgKey = AliOSSHelper.GetOssImgKey("jpg", false, out videoImgUrl);
                        await VideoAliMtsHelper.SubMitVieoSnapshotJob(tempconverpath, videoImgKey);

                        cVideo.itemId          = strategyId;
                        cVideo.status          = 1;
                        cVideo.createDate      = DateTime.Now;
                        cVideo.itemType        = videotype;   //;
                        cVideo.sourceFilePath  = videopath;   //视频路径
                        cVideo.videoPosterPath = videoImgUrl; //封面

                        result = Convert.ToInt32(Add(cVideo));
                    }
                    else
                    {
                        var videokey = videopath.Replace("temp/", "");
                        //临时目录移动
                        var moveResult = AliOSSHelper.CopyObect(videopath, videokey, ".mp4");
                        if (!moveResult)
                        {
                            return(false);
                        }
                        //AliOss视频copy成功
                        else
                        {
                            //获取封面图
                            var videoImgUrl = string.Empty;
                            var videoImgKey = AliOSSHelper.GetOssImgKey("jpg", false, out videoImgUrl);
                            await VideoAliMtsHelper.SubMitVieoSnapshotJob(videokey, videoImgKey);

                            cVideo.itemId         = strategyId;
                            cVideo.status         = 1;
                            cVideo.createDate     = DateTime.Now;
                            cVideo.itemType       = videotype;
                            cVideo.sourceFilePath = videokey;//视频路径
                            var regex = new Regex(@"(?i)\.[\S]*");
                            cVideo.convertFilePath = VideoAliMtsHelper.GetUrlFromKey(regex.Replace(videopath.Replace("temp/", ""), ".mp4"));
                            cVideo.videoPosterPath = videoImgUrl;//封面

                            result = Convert.ToInt32(Add(cVideo));
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(result > 0);
        }
示例#3
0
        //更新店铺时语音转mp3
        public async Task <string> SendVoiceToAliOss(int voiceId, int artId, int commentId, string content = "", bool needUpdateContent = false, bool isupdate = false)
        {
            string artcont = content;

            if (voiceId < 1)
            {
                return(string.Empty);
            }
            C_Attachment model = GetModel(voiceId);

            if (model == null)
            {
                return(string.Empty);
            }
            model.itemId = artId;
            try
            {
                if (!string.IsNullOrEmpty(model.filepath))
                {
                    if (isupdate)
                    {
                        if (!model.filepath.Contains("temp"))//不是新上传的,停止操作!
                        {
                            log4net.LogHelper.WriteInfo(this.GetType(), "观察日志:修改文章停止旧语音移动。文章ID=" + artId + "语音路径" + model.filepath);
                            return(string.Empty);
                        }
                    }
                    var    bucket      = ConfigurationManager.AppSettings["BucketName"];
                    int    whichDomain = 1;
                    string TemplateId  = string.Empty;
                    string PipelineId  = string.Empty;
                    TemplateId = ConfigurationManager.AppSettings["VoiceTemplateId"] ?? "42d5aac40e6a50bf13045a40aeb83b6f";
                    PipelineId = ConfigurationManager.AppSettings["PipelineId"] ?? "4bc9dd15cb3d48e39e0824e19c41defb";
                    var finalVoiceKey    = string.Empty;
                    var finalVoiceFolder = AliOSSHelper.GetOssVoiceKey("mp3", false, "voice/folder", out finalVoiceKey, whichDomain);
                    //上传的本地音频。并且不是mp3|| 微信语音
                    if (!string.IsNullOrEmpty(model.VoiceServerId))
                    {
                        //转换mp3
                        bool submitResult = await AliMTSHelper.SubmitJobs(model.filepath, finalVoiceKey, bucket, TemplateId, PipelineId, "", whichDomain);

                        if (submitResult)
                        {//转换成功。更新路径
                            model.thumbnail = finalVoiceKey;
                            //图文混排内容里的音频替换
                            if (needUpdateContent)
                            {
                                var voiceurl = model.filepath;
                                artcont = CRegex.Replace(artcont, voiceurl, finalVoiceKey, 0);
                            }
                        }//音频转换失败
                        else
                        {
                            log4net.LogHelper.WriteInfo(this.GetType(), "语音给AliOSS转换格式失败!ID为" + model.id + "==" + model.filepath);
                        }
                    }//mp3移动
                    else
                    {
                        //本地音频mp3格式从temp 拷贝
                        Task <bool> moveResult = Task <bool> .Factory.StartNew(
                            () =>
                        {
                            return(AliOSSHelper.CopyObect(model.thumbnail, finalVoiceKey));
                        }
                            );

                        ;
                        if (await moveResult)
                        {//移动成功。更新路径
                            model.thumbnail = finalVoiceKey;
                            //图文混排内容里的音频替换
                            if (needUpdateContent)
                            {
                                var voiceurl = model.filepath;
                                artcont = CRegex.Replace(artcont, voiceurl, finalVoiceKey, 0);
                            }
                        }
                        // 移动失败
                        else
                        {
                            log4net.LogHelper.WriteInfo(this.GetType(), "本地音频AliOSS临时文件夹移动到正式文件夹失败!ID为" + model.id);
                        }
                    }
                }

                MySqlParameter[] param = new MySqlParameter[] { new MySqlParameter("@itemId", artId),
                                                                new MySqlParameter("@filepath", model.filepath),
                                                                new MySqlParameter("@thumbnail", model.thumbnail),
                                                                new MySqlParameter("@id", model.id) };

                string sql = "update C_Attachment set itemId=@itemId,filepath=@filepath,thumbnail=@thumbnail where id=@id";
                SqlMySql.ExecuteNonQuery(Utility.dbEnum.MINIAPP.ToString(), System.Data.CommandType.Text, sql, param);
                RedisUtil.Remove(string.Format(CImageKey, model.itemId, model.itemType));
                RemoveRedis(model.itemId, model.itemType);

                return(artcont);
            }
            catch (Exception ex)
            {
                log4net.LogHelper.WriteError(this.GetType(), new Exception("voiceid" + model.id + "移动语音失败:" + ex.Message));
                return(string.Empty);
            }
        }
示例#4
0
        /// <summary>
        /// 发帖成功后,视频处理,临时文件拷贝到正式文件, 如果要转码,需要进行转码
        /// 目前一个视频附件只能有一个
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="itemType"></param>
        /// <param name="videoKey"></param>
        /// <param name="cityInfoId"></param>
        public async Task <bool> HandleVideo(int itemId, int itemType, string videoKey_Org, int cityInfoId = 0)
        {
            var cVideo = GetModel($"itemId={itemId} and itemType={itemType}");

            if (cVideo == null)
            {
                cVideo = new C_AttachmentVideo();
            }
            cVideo.createDate     = DateTime.Now;
            cVideo.itemId         = itemId;
            cVideo.itemType       = itemType;// (int)C_Enums.AttachmentVideoType.店铺动态视频;
            cVideo.sourceFilePath = videoKey_Org;
            cVideo.status         = 1;
            cVideo.cityCode       = cityInfoId;
            List <string> extents = new List <string> {
                "mp4", "ogg", "mpeg4", "webm", "MP4", "OGG", "MPEG4", "WEBM"
            };
            string fileType = "mp4";

            string[] keyExt = videoKey_Org.Split('.');
            if (keyExt.Length > 1)
            {
                fileType = keyExt[1];
            }

            //无需转换 , 直接COPY
            if (extents.Contains(fileType))
            {
                var videokey = videoKey_Org.Replace("temp/", "");
                //临时目录移动
                var moveResult = AliOSSHelper.CopyObect(videoKey_Org, videokey, ".mp4");

                cVideo.convertFilePath = VideoAliMtsHelper.GetUrlFromKey(videoKey_Org.Replace("temp/", ""));
                //AliOss视频copy成功
                if (true == moveResult)
                {
                    //获取封面图
                    var videoImgUrl = string.Empty;
                    var videoImgKey = AliOSSHelper.GetOssImgKey("jpg", false, out videoImgUrl);
                    await VideoAliMtsHelper.SubMitVieoSnapshotJob(videoKey_Org, videoImgKey);

                    cVideo.videoPosterPath = videoImgUrl;
                }
                else
                {
                    log4net.LogHelper.WriteInfo(typeof(VideoAttachmentBLL), "移动视频失败tempPath= " + videoKey_Org);
                }
            }
            else//需要转码
            {
                var regex      = new System.Text.RegularExpressions.Regex(@"(?i)\.[\S]*");
                var convertUrl = VideoAliMtsHelper.GetUrlFromKey(regex.Replace(videoKey_Org.Replace("temp/", ""), ".mp4"));
                //提交给Ali转码
                var covertResult = await VideoAliMtsHelper.SubMitVieoJob(videoKey_Org, convertUrl);

                cVideo.convertFilePath = convertUrl;
                if (covertResult)
                {
                    //获取封面图
                    var videoImgUrl = string.Empty;
                    var videoImgKey = AliOSSHelper.GetOssImgKey("jpg", false, out videoImgUrl);
                    await VideoAliMtsHelper.SubMitVieoSnapshotJob(videoKey_Org, videoImgKey);

                    cVideo.videoPosterPath = videoImgUrl;
                }
                else
                {
                    log4net.LogHelper.WriteInfo(typeof(VideoAttachmentBLL), "提交转码视频失败tempPath= " + videoKey_Org);
                }
            }
            if (cVideo.id == 0)
            {
                Add(cVideo);
            }
            else
            {
                Update(cVideo);
            }
            return(true);
        }