Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.IO;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using System.Web.Script.Serialization;
- using System.Windows.Forms;
- using HundredMilesSoftware.UltraID3Lib;
- using AudioUtils;
- using System.Net;
- namespace mp3taghandler
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string currdirectory = null;
- RootObject rootjson;
- string[] currpaths;
- int i = 0;
- int jsonindex = 0;
- private void nextbutton_Click(object sender, EventArgs e)
- {
- try
- {
- if (i < currpaths.Length)
- {
- if (currpaths[i].EndsWith(".mp3"))
- {
- UltraID3 mp3 = new UltraID3();
- if (currpaths[i] != null)
- {
- mp3.Read(currpaths[i]);
- FileInfo info = new FileInfo(currpaths[i]);
- if (neugenre.Text != string.Empty)
- mp3.ID3v23Tag.Genre = neugenre.Text;
- if(neuautor.Text != string.Empty)
- mp3.ID3v23Tag.Artist = neuautor.Text;
- if (neutitel.Text != string.Empty)
- mp3.ID3v23Tag.Title = neutitel.Text;
- else
- mp3.ID3v23Tag.Title = info.Name.Remove(info.Name.Length - 4, 4);
- mp3.ID3v23Tag.WriteFlag = true;
- mp3.Write();
- if (neutitel.Text != string.Empty && neutitel.Text.ToLower() + ".mp3" != info.Name.ToLower())
- {
- File.Copy(info.FullName,currdirectory + "\\" + neutitel.Text + ".mp3");
- File.Delete(info.FullName);
- }
- i++;
- getcurrpath();
- neuautor.Text = string.Empty;
- neugenre.Text = string.Empty;
- neutitel.Text = string.Empty;
- }
- else
- i++;
- }
- else
- i++;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- i++;
- }
- }
- private void initbutton_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog dialog = new FolderBrowserDialog();
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- currdirectory = dialog.SelectedPath;
- currpaths = Directory.GetFiles(currdirectory);
- i = 0;
- foreach (String s in currpaths)
- {
- String[] temp = s.Split('\\');
- treeView1.Nodes.Add(new TreeNode(temp[temp.Length-1]));
- }
- getcurrpath();
- }
- }
- private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
- {
- i = e.Node.Index;
- getcurrpath();
- }
- private void getcurrpath()
- {
- UltraID3 mp3 = new UltraID3();
- mp3.Read(currpaths[i]);
- FileInfo info = new FileInfo(currpaths[i]);
- alttitel.Text = info.Name;
- altautor.Text = mp3.ID3v23Tag.Artist;
- altGenre.Text = mp3.ID3v23Tag.Genre;
- textBoxquery.Text = info.Name.Substring(0,info.Name.Length-4);
- try
- {
- treeView1.SelectedNode = treeView1.Nodes[i];
- }
- catch(ArgumentOutOfRangeException e)
- {
- Debug.WriteLine(e.Message);
- }
- }
- private RootObject getroot(int page,string query)
- {
- RootObject root = null;
- query.Replace(' ', '+');
- string url = "https://api.discogs.com/database/search?q="+query+ "&type=release&per_page=3&page="+page.ToString();
- WebClient client = new WebClient();
- client.Headers.Add(HttpRequestHeader.Host, "api.discogs.com");
- client.Headers.Add(HttpRequestHeader.Authorization, "Discogs key=fvjuYhGjrQYIGmdeSVZd, secret=UyHaEdePsdCzGcINqZvEoJPBfrzcwnbn");
- client.Headers.Add(HttpRequestHeader.UserAgent, "MP3Taghandler/0.2 +phil-susen@gmx.de");
- Stream stream = client.OpenRead(url);
- StreamReader objReader = new StreamReader(stream);
- string response = objReader.ReadToEnd();
- root = new JavaScriptSerializer().Deserialize<RootObject>(response);
- return root;
- }
- private void setProposal(int index)
- {
- try
- {
- neutitel.Text = rootjson.results[index].title.Split('-')[1].Trim(' ');
- neuautor.Text = rootjson.results[index].title.Split('-')[0].Trim(' ');
- string genres = string.Empty;
- foreach (string genre in rootjson.results[index].genre)
- {
- genres += genre;
- genres += " ";
- }
- neugenre.Text = genres;
- }
- catch(ArgumentOutOfRangeException e)
- {
- MessageBox.Show("There are no more Proposals. Try changing query.");
- }
- }
- private void reloadbutton_Click(object sender, EventArgs e)
- {
- rootjson = getroot(1, textBoxquery.Text);
- jsonindex = 0;
- setProposal(0);
- }
- private void lastproposal_Click(object sender, EventArgs e)
- {
- if (jsonindex > 0)
- jsonindex--;
- else
- MessageBox.Show("You are at the Start");
- int site = jsonindex / 3 + 1;
- int index = jsonindex % 3;
- if (rootjson.pagination.page != site)
- rootjson = getroot(site, textBoxquery.Text);
- setProposal(index);
- }
- private void nextproposal_Click(object sender, EventArgs e)
- {
- if (jsonindex < rootjson.pagination.items)
- jsonindex++;
- if (jsonindex < rootjson.pagination.items)
- {
- int site = jsonindex / 3 + 1;
- int index = jsonindex % 3;
- if (rootjson.pagination.page != site)
- rootjson = getroot(site, textBoxquery.Text);
- setProposal(index);
- }
- else
- {
- MessageBox.Show("You are through all Proposals");
- }
- }
- private void skipbutton_Click(object sender, EventArgs e)
- {
- i++;
- getcurrpath();
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- waveControl1.Filename = "C:\\Users\\phil-\\Downloads\\Best_Of_You.wav";
- waveControl1.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement