コード例 #1
0
 private void SaveDataAsINI_Click(object sender, EventArgs e)
 {
     if (rb != null)
     {
         string ls4 = Conv(
             FileSavingSettings.FileNameFilter(Program.afn, "_"),
             string.Empty,
             string.Empty,
             FileSavingSettings.FileNameFilter(rb.rb[0].album.name, "_"),
             FileSavingSettings.FileNameFilter(rb.rb[0].album.id.ToString(), "_"),
             string.Empty,
             string.Empty);
         Directory.CreateDirectory(SaveLoc.Text + ls4);
         IniFiles ini = new IniFiles(SaveLoc.Text + ls4 + @"\专辑信息.ini");
         ini.IniWriteValue("AlbumInfo", "id", rb.rb[0].album.id.ToString());
         ini.IniWriteValue("AlbumInfo", "name", rb.rb[0].album.name);
         ini.IniWriteValue("AlbumInfo", "picUrl", rb.rb[0].album.picUrl);
         ini.IniWriteValue("AlbumInfo", "count", rb.rb.Count.ToString());
         for (int i = 0; i < rb.rb.Count; i++)
         {
             ini.IniWriteValue("Song" + i.ToString(), "id", rb.rb[i].id.ToString());
             ini.IniWriteValue("Song" + i.ToString(), "name", rb.rb[i].name);
             ini.IniWriteValue("Song" + i.ToString(), "duration", rb.rb[i].duration.ToString());
             ls2 = string.Empty;
             for (int i2 = 0; i2 < rb.rb[i].artists.Count; i2++)
             {
                 if (i2 != 0)
                 {
                     ls2 += "/";
                 }
                 ls2 += rb.rb[i].artists[i2].name;
             }
             ls3 = string.Empty;
             for (int i2 = 0; i2 < rb.rb[i].artists.Count; i2++)
             {
                 if (i2 != 0)
                 {
                     ls3 += "/";
                 }
                 ls3 += rb.rb[i].artists[i2].id.ToString();
             }
             ini.IniWriteValue("Song" + i.ToString(), "artistsName", ls2);
             ini.IniWriteValue("Song" + i.ToString(), "artistsID", ls3);
             Success("保存成功!位置:" + SaveLoc.Text + ls4 + @"\专辑信息.ini");
         }
     }
 }
コード例 #2
0
        private void DLSong_Click(object sender, EventArgs e)
        {
            if (SongListBox.SelectedItem != null)
            {
                string ls4 = string.Empty;
                for (int i2 = 0; i2 < rb.rb[SongListBox.SelectedIndex].artists.Count; i2++)
                {
                    if (i2 != 0)
                    {
                        ls4 += ";";
                    }

                    ls4 += rb.rb[SongListBox.SelectedIndex].artists[i2].name;
                }
                string locx = Conv(
                    FileSavingSettings.FileNameFilter(Program.ssf, "_"),
                    string.Empty,
                    FileSavingSettings.FileNameFilter(ls4, "_"),
                    FileSavingSettings.FileNameFilter(rb.rb[0].album.name, "_"),
                    FileSavingSettings.FileNameFilter(rb.rb[0].album.id.ToString(), "_"),
                    FileSavingSettings.FileNameFilter(rb.rb[SongListBox.SelectedIndex].name, "_"),
                    FileSavingSettings.FileNameFilter(rb.rb[SongListBox.SelectedIndex].id.ToString(), "_"));
                locx = FileSavingSettings.PathFilter(SaveLoc.Text + locx + Program.fmt, "_");
                Directory.CreateDirectory(SaveLoc.Text + @"\");
                if (DownloadFile("http://music.163.com/song/media/outer/url?id=" + rb.rb[SongListBox.SelectedIndex].id.ToString(), locx))
                {
                    Success("下载成功!位置:" + locx);
                }
                else
                {
                    Error("下载失败 " + dlerr);
                    dlerr = string.Empty;
                }
                using (FileStream fs = File.OpenRead(locx))
                {
                    if (fs.ReadByte() == '<')
                    {
                        fs.Close();
                        fs.Dispose();
                        File.Delete(locx);
                        Error("下载失败,可能原因:版权限制或地区限制");
                    }
                }
            }
        }
コード例 #3
0
 private void DLAllSong_Click(object sender, EventArgs e)
 {
     if (rb != null)
     {
         string ls5 = Conv(
             FileSavingSettings.FileNameFilter(Program.afn, "_"),
             string.Empty,
             string.Empty,
             FileSavingSettings.FileNameFilter(rb.rb[0].album.name, "_"),
             FileSavingSettings.FileNameFilter(rb.rb[0].album.id.ToString(), "_"),
             string.Empty,
             string.Empty);
         Directory.CreateDirectory(SaveLoc.Text + ls5);
         ProcessB.Maximum = rb.rb.Count;
         ProcessL.Text    = rb.rb.Count.ToString();
         string   locx;
         int      DLfailedcount = 0;
         IniFiles ini           = new IniFiles(SaveLoc.Text + ls5 + @"\下载失败的文件.ini");
         for (int i = 0; i < rb.rb.Count; i++)
         {
             string ls4 = string.Empty;
             for (int i2 = 0; i2 < rb.rb[i].artists.Count; i2++)
             {
                 if (i2 != 0)
                 {
                     ls4 += ";";
                 }
                 ls4 += rb.rb[i].artists[i2].name;
             }
             string ls6 = Conv(
                 FileSavingSettings.FileNameFilter(Program.msf, "_"),
                 FileSavingSettings.FileNameFilter(i.ToString().PadLeft((rb.rb.Count - 1).ToString().Length, '0'), "_"),
                 FileSavingSettings.FileNameFilter(ls4, "_"),
                 FileSavingSettings.FileNameFilter(rb.rb[0].album.name, "_"),
                 FileSavingSettings.FileNameFilter(rb.rb[0].album.id.ToString(), "_"),
                 FileSavingSettings.FileNameFilter(rb.rb[i].name, "_"),
                 FileSavingSettings.FileNameFilter(rb.rb[i].id.ToString(), "_"));
             locx = FileSavingSettings.PathFilter(SaveLoc.Text + ls5 + @"\" + ls6 + Program.fmt, "_");
             if (!DownloadFile("http://music.163.com/song/media/outer/url?id=" + rb.rb[i].id.ToString() + Program.fmt, locx))
             {
                 int iii = i + 1;
                 Error("下载失败 (" + iii + ")");
                 ini.IniWriteValue("DownloadFailed", "count", (DLfailedcount + 1).ToString());
                 ini.IniWriteValue("Error" + DLfailedcount.ToString(), "歌曲编号", iii.ToString());
                 ini.IniWriteValue("Error" + DLfailedcount.ToString(), "歌曲名称", rb.rb[i].name);
                 ini.IniWriteValue("Error" + DLfailedcount.ToString(), "歌曲ID", rb.rb[i].id.ToString());
                 ini.IniWriteValue("Error" + DLfailedcount.ToString(), "源地址", "http://music.163.com/song/media/outer/url?id=" + rb.rb[i].id.ToString());
                 ini.IniWriteValue("Error" + DLfailedcount.ToString(), "保存路径", locx);
                 ini.IniWriteValue("Error" + DLfailedcount.ToString(), "错误提示", dlerr);
                 ini.IniWriteValue("Error" + DLfailedcount.ToString(), "可能原因", "网络问题");
                 DLfailedcount++;
                 dlerr = string.Empty;
             }
             using (FileStream fs = File.OpenRead(locx))
             {
                 if (fs.ReadByte() == '<')
                 {
                     fs.Close();
                     fs.Dispose();
                     File.Delete(locx);
                     int iii = i + 1;
                     Error("下载失败,可能原因:版权限制或地区限制 (" + iii + ")");
                     ini.IniWriteValue("DownloadFailed", "count", DLfailedcount.ToString());
                     ini.IniWriteValue("Error" + DLfailedcount.ToString(), "歌曲编号", iii.ToString());
                     ini.IniWriteValue("Error" + DLfailedcount.ToString(), "歌曲名称", rb.rb[i].name);
                     ini.IniWriteValue("Error" + DLfailedcount.ToString(), "歌曲ID", rb.rb[i].id.ToString());
                     ini.IniWriteValue("Error" + DLfailedcount.ToString(), "源地址", "http://music.163.com/song/media/outer/url?id=" + rb.rb[i].id.ToString());
                     ini.IniWriteValue("Error" + DLfailedcount.ToString(), "保存路径", locx);
                     ini.IniWriteValue("Error" + DLfailedcount.ToString(), "可能原因", "版权限制或地区限制");
                     DLfailedcount++;
                 }
             }
             ProcessB.Value = i + 1;
         }
         if (DLfailedcount != 0)
         {
             ini.IniWriteValue("DownloadFailed", "count", DLfailedcount.ToString());
         }
         else
         {
             Success("下载成功!位置:" + SaveLoc.Text + ls5 + @"\");
             ProcessB.Value = 0;
             ProcessL.Text  = "0";
         }
     }
 }