예제 #1
0
파일: Program.cs 프로젝트: saveenr/saveenr
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                System.Console.WriteLine("Syntax: ExportWMPMetadataToCSV.exe <outfile> [<top>]");
                return;
            }

            int? top = null;

            if (args.Length >= 2)
            {
                top = int.Parse(args[1]);
            }

            string output_filename = args[0];
            var normalized_names = new Dictionary<string, string>();
            foreach (var attr in all_attributes)
            {
                string name = attr.Replace("/", "_");
                normalized_names[attr] = name;
            }

            var wmp = new WMPLib.WindowsMediaPlayerClass();
            var item_collection = wmp.getAll();

            using (var writer = File.CreateText(output_filename))
            using (var csv = new CsvWriter(writer))
            {
                // Write CSV Header
                for (int i = 0; i < all_attributes.Length; i++)
                {
                    string h = normalized_names[all_attributes[i]];
                    csv.WriteField(h);
                }
                csv.NextRecord();

                for (int i = 0; i < item_collection.count; i++)
                {
                    if (top.HasValue && i>= top.Value)
                    {
                        break;
                    }

                    System.Console.WriteLine("WMP Item #: {0}", i + 1);
                    // write a csv line for each item in the collection
                    var item = item_collection.get_Item(i);

                    for (int j = 0; j < all_attributes.Length; j++)
                    {
                        var attr_value = item.getItemInfo(all_attributes[j]) ?? "";
                        csv.WriteField(attr_value);
                    }
                    csv.NextRecord();
                }
            }

            System.Console.WriteLine("DONE");

        }
예제 #2
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                System.Console.WriteLine("Syntax: ExportWMPMetadataToCSV.exe <outfile> [<top>]");
                return;
            }

            int?top = null;

            if (args.Length >= 2)
            {
                top = int.Parse(args[1]);
            }

            string output_filename  = args[0];
            var    normalized_names = new Dictionary <string, string>();

            foreach (var attr in all_attributes)
            {
                string name = attr.Replace("/", "_");
                normalized_names[attr] = name;
            }

            var wmp             = new WMPLib.WindowsMediaPlayerClass();
            var item_collection = wmp.getAll();

            using (var writer = File.CreateText(output_filename))
                using (var csv = new CsvWriter(writer))
                {
                    // Write CSV Header
                    for (int i = 0; i < all_attributes.Length; i++)
                    {
                        string h = normalized_names[all_attributes[i]];
                        csv.WriteField(h);
                    }
                    csv.NextRecord();

                    for (int i = 0; i < item_collection.count; i++)
                    {
                        if (top.HasValue && i >= top.Value)
                        {
                            break;
                        }

                        System.Console.WriteLine("WMP Item #: {0}", i + 1);
                        // write a csv line for each item in the collection
                        var item = item_collection.get_Item(i);

                        for (int j = 0; j < all_attributes.Length; j++)
                        {
                            var attr_value = item.getItemInfo(all_attributes[j]) ?? "";
                            csv.WriteField(attr_value);
                        }
                        csv.NextRecord();
                    }
                }

            System.Console.WriteLine("DONE");
        }