Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using iTunesLib;
- using System.Xml;
- using System.Xml.Linq;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using TagLib;
- using ITLRU;
- using System.Xml.Serialization;
- namespace BackupLib
- {
- class Program
- {
- static void Main(string[] args)
- {
- // iTunes classes
- iTunesAppClass itunes = new iTunesAppClass();
- IITLibraryPlaylist mainLibrary = itunes.LibraryPlaylist;
- IITTrackCollection ittracks = mainLibrary.Tracks;
- List<string> files = new List<string>();
- List<string> musicfiles = new List<string>();
- List<string> badfiles = new List<string>();
- List<string> songlist = new List<string>();
- int state = (int)itunes.PlayerState;
- //Console.Write(state); System.Threading.Thread.Sleep(5500);
- if (state == 1){ Console.Write("Itunes will be Pausing to ensure Data Integrity");System.Threading.Thread.Sleep(5500); itunes.Pause(); }
- //Console.WriteLine state;
- string[] extensions = { "*.mp3", "*.mp4", "*.m4a", "*.m4v", "*.m4p", "*.m4b", "*.flac"};
- string filepath = "G:\\iTunes Media";
- foreach (string extension in extensions)
- {
- files.AddRange(Directory.GetFiles(filepath, extension, SearchOption.AllDirectories));
- }
- foreach (string file in files)
- {
- try {string taglibfile = TagLib.File.Create(file).Tag.Title; musicfiles.Add(file); Console.WriteLine(taglibfile); }
- catch {badfiles.Add(file); }
- }
- //string pattern = "[\\~#%&*{}/:<>?|\"-]";
- //string replacement = "_";
- //Regex regEx = new Regex(pattern);
- //string sanitized = Regex.Replace(regEx.Replace(input, replacement), @"\s+", " ");
- XDocument baddoc = new XDocument
- (new XElement("Corrupt",
- badfiles.Select(badfile =>
- new XElement("File", badfile))));
- baddoc.Save("G:\\ITL\\badfiles.xml");
- // foreach(string musicfile in musicfiles)
- //{ String Title = (TagLib.File.Create(musicfile).Tag.Title); }
- XDocument doc = new XDocument();
- //foreach(string musicfile in musicfiles){
- //string Title = (TagLib.File.Create(musicfile).Tag.Title);
- //}
- XElement songsElement = new XElement("Songs");
- foreach(var musicfile in musicfiles)
- {
- XElement songElement = new XElement("Song");
- string songTitle = TagLib.File.Create(musicfile).Tag.Title;
- string songPath = musicfile;
- string songArtist = (TagLib.File.Create(musicfile).Tag.Performers);
- songlist.Add("Adding "+songTitle+", Artist "+songArtist+", at path "+songPath+" to DirLib file.");
- XElement titleElement = new XElement("Title",songTitle);
- XElement pathElement = new XElement("Path", musicfile);
- XElement artistElement = new XElement("Artist",songArtist);
- songElement.Add(titleElement);
- songElement.Add(pathElement);
- songElement.Add(artistElement);
- songsElement.Add(songElement);
- }
- System.IO.File.WriteAllLines(@"C:\Users\Public\TestFolder\WriteLines.txt", songlist);
- doc.Add(songsElement);
- doc.Save("G:\\ITL\\DirLib.xml");
- itunes.Play();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement