Beispiel #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");
         }
     }
 }
Beispiel #2
0
        private void SaveLoc_TextChanged(object sender, EventArgs e)
        {
            if (!(SaveLoc.Text.EndsWith("/") || SaveLoc.Text.EndsWith(@"\")))
            {
                SaveLoc.Text += @"\";
            }
            Program.savedir = SaveLoc.Text;
            IniFiles ini = new IniFiles(Program.tloc + @"\settings.ini");

            ini.IniWriteValue("163AlbumGet", "FileSaveDir", Program.savedir);
        }
Beispiel #3
0
 private void Confirm_Click(object sender, EventArgs e)
 {
     FileSaveDirI.Text           = PathFilter(FileSaveDirI.Text);
     AlbumFolderNameI.Text       = FileNameFilter(AlbumFolderNameI.Text);
     SingleSongFilenameI.Text    = FileNameFilter(SingleSongFilenameI.Text);
     MultipleSongsFilenameI.Text = FileNameFilter(MultipleSongsFilenameI.Text);
     if (!(FileSaveDirI.Text.EndsWith("/") || FileSaveDirI.Text.EndsWith(@"\")))
     {
         FileSaveDirI.Text += @"\";
     }
     if (FileSaveDirI.Text != string.Empty ||
         AlbumFolderNameI.Text != string.Empty ||
         SingleSongFilenameI.Text != string.Empty ||
         MultipleSongsFilenameI.Text != string.Empty)
     {
         if (ReplaceCHK(FileSaveDirI.Text, "文件保存地址 文本框") &&
             ReplaceCHK(AlbumFolderNameI.Text, "专辑文件夹名称 文本框") &&
             ReplaceCHK(SingleSongFilenameI.Text, "歌曲文件名称(单个下载) 文本框") &&
             ReplaceCHK(MultipleSongsFilenameI.Text, "歌曲文件名称(批量下载) 文本框"))
         {
             Program.afn = AlbumFolderNameI.Text;
             Program.ssf = SingleSongFilenameI.Text;
             Program.msf = MultipleSongsFilenameI.Text;
             IniFiles ini = new IniFiles(Program.tloc + @"\settings.ini");
             ini.IniWriteValue("163AlbumGet", "AlbumFolderName", Program.afn);
             ini.IniWriteValue("163AlbumGet", "SingleSongFilename", Program.ssf);
             ini.IniWriteValue("163AlbumGet", "MultipleSongsFilename", Program.msf);
             if (!Directory.Exists(FileSaveDirI.Text))//如果不存在就创建 dir 文件夹
             {
                 DialogResult dr = MessageBox.Show("路径不存在!是否创建路径?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                 if (dr == DialogResult.OK)
                 {
                     Directory.CreateDirectory(FileSaveDirI.Text);
                     Program.savedir = FileSaveDirI.Text;
                     ini.IniWriteValue("163AlbumGet", "FileSaveDir", Program.savedir);
                     Close();
                 }
                 else
                 {
                     Program.savedir = FileSaveDirI.Text;
                     ini.IniWriteValue("163AlbumGet", "FileSaveDir", Program.savedir);
                     Close();
                 }
             }
             else
             {
                 Program.savedir = FileSaveDirI.Text;
                 ini.IniWriteValue("163AlbumGet", "FileSaveDir", Program.savedir);
                 Close();
             }
         }
     }
     else
     {
         Error("文件名不能为空!", string.Empty);
     }
 }
Beispiel #4
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";
         }
     }
 }