コード例 #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Directory.CreateDirectory(loc);
            IniFiles ini = new IniFiles(Program.tloc + @"\settings.ini");

            if (ini.IniReadValue("163AlbumGet", "FileSaveDir").Trim() != string.Empty)
            {
                Program.savedir = ini.IniReadValue("163AlbumGet", "FileSaveDir");
            }
            if (ini.IniReadValue("163AlbumGet", "AlbumFolderName").Trim() != string.Empty)
            {
                Program.afn = ini.IniReadValue("163AlbumGet", "AlbumFolderName");
            }
            if (ini.IniReadValue("163AlbumGet", "SingleSongFilename").Trim() != string.Empty)
            {
                Program.ssf = ini.IniReadValue("163AlbumGet", "SingleSongFilename");
            }
            if (ini.IniReadValue("163AlbumGet", "MultipleSongsFilename").Trim() != string.Empty)
            {
                Program.msf = ini.IniReadValue("163AlbumGet", "MultipleSongsFilename");
            }
            SaveLoc.Text = Program.savedir;
        }
コード例 #2
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";
         }
     }
 }