示例#1
0
        /// <summary>
        /// 加载歌曲
        /// </summary>
        /// <param name="itemm">要加载的歌曲</param>
        private static void Load(SongItem itemm)
        {
            if (Config.ControlOtherPlayer)
            {
                API.SendKey(System.Windows.Input.Key.MediaStop);
            }
            DanmukuReceiver.VoteUids.Clear();

            waveout = Create();

            FileReader = new Mp3FileReader(itemm._FilePath);

            var sampleChannel = new SampleChannel(FileReader, true);

            setVolumeDelegate = vol => sampleChannel.Volume = vol;

            var postVolumeMeter = new MeteringSampleProvider(sampleChannel);

            waveout.Init(postVolumeMeter);

            waveout.PlaybackStopped += Waveout_PlaybackStopped;
            SetVol();

            lrc = itemm._FLyric ?? itemm.getFLyric();
        }
示例#2
0
        /// <summary>
        /// 添加歌曲
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddSong(object sender, RoutedEventArgs e)
        {
            var menuItem    = (MenuItem)sender;
            var contextMenu = (ContextMenu)menuItem.Parent;
            var items       = (DataGrid)contextMenu.PlacementTarget;

            if (items.SelectedCells.Count == 0)
            {
                return;
            }
            var item = items.SelectedCells[0].Item as SongsSearchModule;

            if (item == null)
            {
                return;
            }

            InputDialog i = new InputDialog("歌曲名字:", "", "添加歌曲");

            if (i.ShowDialog() == true && i.Answer != string.Empty)
            {
                SongItem song = item.SafeSearch(Config.MASTER_NAME, System.Web.HttpUtility.UrlEncode(i.Answer), Config.needLyric);
                if (song != null)
                {
                    Center.AddSong(song);
                    Center.Logg("手动添加歌曲成功:" + song.SongName);
                }
            }
            i = null;
        }
示例#3
0
 internal static void RemoveSong(SongItem song)
 {
     PluginMain.self.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
     {
         Songs.Remove(song);
     }));
 }
示例#4
0
        internal static SongItem SearchSong(string username, string str, bool?arglyric = null)
        {
            bool lrc = arglyric == null ? Config.needLyric : (bool)arglyric;

            if (CurrentModuleA == null)
            {
                Logg("没有歌曲搜索模块!", true); return(null);
            }                                         // 默认搜索模块没设置

            string str_encoded = System.Web.HttpUtility.UrlEncode(str);

            SongItem i = CurrentModuleA.SafeSearch(username, str_encoded, lrc);

            if (i == null && CurrentModuleB != null)
            {
                i = CurrentModuleB.SafeSearch(username, str_encoded, lrc);
            }

            if (i != null && i.User != username)
            {
                Logg($"搜索模块“{i.ModuleName}”因传递数据错误已被禁用", true);
                PluginMain.self.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                {
                    SearchModules.Remove(i.Module);
                    if (Mainw.Combo_SearchModuleA.SelectedIndex == -1) // 防null
                    {
                        Mainw.Combo_SearchModuleA.SelectedIndex = 0;
                    }
                }));
                return(null);
            }

            return(i);
        }
示例#5
0
        /// <summary>
        /// 主插件调用用
        /// </summary>
        /// <param name="item">要下载的歌曲信息</param>
        /// <returns>下载是否成功</returns>
        public int SafeDownload(SongItem item)
        {
            try
            {
                return(Download(item));
            }
            catch (Exception ex)
            {
                try
                {
                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    using (StreamWriter outfile = new StreamWriter(path + @"\B站彈幕姬点歌姬歌曲搜索引擎" + ModuleName + "错误报告.txt"))
                    {
                        outfile.WriteLine("请将错误报告发给 " + ModuleAuther + " 谢谢,联系方式:" + ModuleCont);
                        outfile.WriteLine("参数:filepath=" + item._FilePath + " url=" + item._DownloadURL + " id=" + item._SongID);
                        outfile.WriteLine(ModuleName + " 本地时间:" + DateTime.Now.ToString());
                        outfile.Write(ex.ToString());
                        new Thread(() =>
                        {
                            System.Windows.MessageBox.Show("点歌姬歌曲搜索引擎“" + ModuleName + @"”遇到了未处理的错误
日志已经保存在桌面,请发给引擎作者 " + ModuleAuther + ", 联系方式:" + ModuleCont);
                        }).Start();
                    }
                }
                catch (Exception)
                { }
                return(-1);
            }
        }
示例#6
0
        private static void Download(SongItem item)
        {
            try
            { Directory.CreateDirectory(Config.SongsCachePath); }
            catch (Exception) { }

            dlItem = item;
            dlItem.setStatus(SongItem.SongStatus.Downloading);

            if (item.Module.HandleDownlaod) // 如果搜索模块负责下载文件
            {
                Center.Mainw.setDownloadStatus("由搜索模块负责下载中");
                switch (item.Module.SafeDownload(item))
                {
                case 1:     // 下载成功
                    dlItem.setStatus(SongItem.SongStatus.WaitingPlay);
                    Center.Logg("歌曲下载 下载成功:" + item._SongName);
                    Center.Mainw.setDownloadStatus("搜索模块返回下载成功");
                    return;

                case 0:     // 下载失败 错误信息由module输出
                default:
                    Center.RemoveSong(item);
                    Center.Mainw.setDownloadStatus("搜索模块返回下载失败");
                    return;
                }
            }
            else // 如果搜索模块不负责下载文件
            {
                wc = new WebClient();

                wc.DownloadProgressChanged += onDownloadProgressChanged;
                wc.DownloadFileCompleted   += onDownloadFileCompleted;
                wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.450 Safari/537.35");
                try
                {
                    sw.Reset();
                    lastUpdateDownloadedSize = 0;
                    lastUpdateTime           = DateTime.Now;
                    wc.DownloadFileAsync(new Uri(item._DownloadURL), item._FilePath);
                    Center.Mainw.setDownloadStatus("正在连接服务器");
                    sw.Start();
                    DownloadWatchDog.Start();
                    downloadFlag = true; // 正在下载歌曲
                }
                catch (Exception ex)
                {
                    sw.Reset();
                    Center.Logg("下载歌曲" + item._SongName + "出错:" + ex.Message, true, true);
                    Center.Mainw.setDownloadStatus("下载失败:" + ex.Message);
                }

                while (downloadFlag)
                {
                    Thread.Sleep(500);
                }
                dlItem = null;
            }
        }
示例#7
0
        private static string GenFileName(SongItem item)
        {
            string s = item.ModuleName;

            s += item._SongID;
            s += item._SongName;
            DateTime d = DateTime.Now;

            s += d.Hour.ToString() + d.Minute.ToString() + d.Second.ToString();

            return(IllegalPathFilter(s) + ".点歌姬缓存");
        }
示例#8
0
        /// <summary>
        /// 从文件和播放列表里移除歌曲
        /// </summary>
        /// <param name="song"></param>
        private static void RemoveSong(SongItem song)
        {
            try
            {
                File.Delete(song._FilePath);
            }
            catch (System.Exception ex)
            {
                Center.Logg("播放模块 删除歌曲缓存失败:" + ex.Message);
            }

            Center.RemoveSong(song);
        }
示例#9
0
        private static void ThrowPlayException(Exception ex, SongItem song)
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            using (StreamWriter outfile = new StreamWriter(path + @"\点歌姬播放错误报告.txt"))
            {
                outfile.WriteLine("播放错误日志 **请将本文件发给宅急送队长** 本地时间:" + DateTime.Now.ToString());
                outfile.WriteLine($"歌曲信息 歌名:{song.SongName};歌手:{song.SingersText};歌曲ID:{song.SongID};");
                outfile.WriteLine("歌曲文件路径:" + song.FilePath);
                outfile.WriteLine($"搜索模块信息 名称:{song.Module.ModuleName};作者:{song.Module.ModuleAuther};联系方式:{song.Module.ModuleCont};歌词支持:{song.Module.SuppLyric.ToString()};");
                outfile.WriteLine("--------------");
                outfile.Write(ex.ToString());
            }
            new Thread(() =>
            {
                System.Windows.MessageBox.Show("点歌姬播放歌曲错误!\n请将桌面上的错误日志发给宅急送队长");
            })
            {
                Name = "点歌姬异步初始化错误弹窗", IsBackground = true
            }
            .Start();
        }
示例#10
0
        /// <summary>
        /// 检查是否在黑名单中
        /// </summary>
        /// <param name="i">歌曲信息</param>
        /// <returns>是否在黑名单中</returns>
        internal static bool isBlack(SongItem i)
        {
            foreach (BlackInfoItem b in BlackList)
            {
                if (b.BLK_Enable)
                {
                    switch (b.BLK_Type)
                    {
                    case BlackInfoType.歌名:
                        if (i.SongName.Contains(b.BLK_Text))
                        {
                            return(true);
                        }
                        break;

                    case BlackInfoType.歌手:
                        if (i.SingersText.Contains(b.BLK_Text))
                        {
                            return(true);
                        }
                        break;

                    case BlackInfoType.歌曲ID:
                        if (i.SongID == b.BLK_Text)
                        {
                            return(true);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            return(false);
        }
示例#11
0
        internal static void DGJ_AdminComment(string msg)
        {
            if (string.IsNullOrWhiteSpace(msg) || !Config.DanmakuControl)
            {
                return;
            }           // 如果弹幕msg没有内容或者不允许弹幕控制

            string[] msgs = msg.Split(new string[] { " " }, System.StringSplitOptions.RemoveEmptyEntries);
            switch (msgs[0])
            {
            case "暫停":
            case "暂停":
                if (PlayControl.Pause())
                {
                    Log("歌曲已经暂停");
                }
                return;

            case "播放":
                if (PlayControl.Play())
                {
                    Log("歌曲继续播放");
                }
                return;

            case "切歌":
                if (PlayControl.Next())
                {
                    Log("已经切掉正在播放的歌曲");
                }
                return;

            case "刪歌":
            case "删歌":
                int num;
                if (msgs.Length >= 2 && int.TryParse(msgs[1], out num))
                {
                    num--;
                    if (num >= 0 && num < Center.Songs.Count)
                    {
                        SongItem item = Center.Songs[num];
                        Log($"切掉了 {item.User} 点的 {item.SongName}", true);
                        switch (item.Status)
                        {
                        case SongItem.SongStatus.WaitingDownload:
                            Center.RemoveSong(item);
                            return;

                        case SongItem.SongStatus.Downloading:
                            DownloadControl.CancelDownload();
                            return;

                        default:
                        case SongItem.SongStatus.WaitingPlay:
                            if (item.FilePath != null && item.FilePath != "")
                            {
                                new Thread((object o) =>
                                {
                                    try
                                    {
                                        File.Delete(o.ToString());
                                    }
                                    catch (Exception) { }
                                })
                                {
                                    IsBackground = true,
                                    Name         = "切歌后删除文件"
                                }
                            }
                            .Start(item.FilePath);
                            Center.RemoveSong(item);
                            return;

                        case SongItem.SongStatus.Playing:
                            PlayControl.Next();
                            return;
                        }
                    }
示例#12
0
 /// <summary>
 /// 请在不能使用普通方式下载歌曲文件的情况下重写替代下载
 /// 不重写等于返回(int)-1
 /// 重写后将由搜索模块负责歌曲的下载
 /// 下载成功请返回(int)1
 /// 下载失败请返回(int)0
 /// 如果希望由点歌姬的下载模块下载文件请返回(int)-1
 /// </summary>
 /// <param name="item">要下载的歌曲信息</param>
 /// <returns>下载是否成功</returns>
 protected internal virtual int Download(SongItem item)
 {
     return(-1);
 }