예제 #1
0
        public static MediaItem PopulateMetaData(MediaResource R, FileInfo F)
        {
            MediaItem RetVal;
            MediaBuilder.item Item = null;
            DText parser = new DText();
            parser.ATTRMARK = "-";
            parser.MULTMARK = ".";

            switch(F.Extension.ToUpper())
            {
                case ".MP3":
                    Item = ParseMP3_V1(F);
                    if(Item==null)
                    {
                        parser[0] = F.Name;
                        if(parser.DCOUNT()==2)
                        {
                            Item = new MediaBuilder.musicTrack(parser[2,1].Trim());
                            Item.creator = parser[1].Trim();
                            ((MediaBuilder.musicTrack)Item).artist = new PersonWithRole[1]{new PersonWithRole()};
                            ((MediaBuilder.musicTrack)Item).artist[0].Name = Item.creator;
                            ((MediaBuilder.musicTrack)Item).artist[0].Role = null;
                        }
                    }
                    break;
            }

            if(Item!=null)
            {
                RetVal = MediaBuilder.CreateItem(Item);
                RetVal.AddResource(R);
                return(RetVal);
            }
            else
            {
                // Create a Generic Item
                string fname = F.Name;
                int fnameidx = fname.IndexOf(".");
                if(fnameidx!=-1) fname=fname.Substring(0,fnameidx);
                MediaBuilder.item genericItem = new MediaBuilder.item(fname);
                RetVal = MediaBuilder.CreateItem(genericItem);
                RetVal.AddResource(R);
                return(RetVal);
            }
        }
        private DvMediaItem CreateItemFromGenericFile(FileInfo file)
        {
            string mime, mediaClass;
            MimeTypes.ExtensionToMimeType(file.Extension, out mime, out mediaClass);

            string protInfo = new System.Text.StringBuilder().AppendFormat("http-get:*:{0}:*", mime).ToString();
            string title = Path.GetFileNameWithoutExtension(file.Name);
            string creator = file.Directory.Name;

            MediaBuilder.item info = new MediaBuilder.item(title);
            info.creator = creator;
            DvMediaItem newMedia = DvMediaBuilder.CreateItem(info);

            ResourceBuilder.VideoItem resInfo = new ResourceBuilder.VideoItem();
            resInfo.contentUri = DvMediaResource.AUTOMAPFILE + file.FullName;
            resInfo.protocolInfo = new ProtocolInfoString(protInfo);
            resInfo.size = new _ULong((ulong)file.Length);
            DvMediaResource res = DvResourceBuilder.CreateResource(resInfo, true);
            res.Tag = file;
            newMedia.AddResource(res);

            return newMedia;
        }
        // For files with filenames that have the format: "creator - title"
        private DvMediaItem CreateItemFromFormatedNameFile(FileInfo file)
        {
            string mime, mediaClass;
            MimeTypes.ExtensionToMimeType(file.Extension, out mime, out mediaClass);

            string protInfo = new System.Text.StringBuilder().AppendFormat("http-get:*:{0}:*", mime).ToString();
            string ct = Path.GetFileNameWithoutExtension(file.Name);

            DText DT = new DText();
            DT.ATTRMARK = "-";
            string title;
            string creator;

            DT[0] = ct;
            if (DT.DCOUNT() == 1)
            {
                creator = "";
                title = DT[1].Trim();
            }
            else
            {
                creator = DT[1].Trim();
                title = DT[2].Trim();
            }

            MediaBuilder.item info = new MediaBuilder.item(title);
            info.creator = creator;
            DvMediaItem newMedia = DvMediaBuilder.CreateItem(info);

            //DvMediaResource res = DvResourceBuilder.CreateResource_HttpGet(file,false);
            ResourceBuilder.VideoItem resInfo = new ResourceBuilder.VideoItem();
            resInfo.contentUri = DvMediaResource.AUTOMAPFILE + file.FullName;
            resInfo.protocolInfo = new ProtocolInfoString(protInfo);
            resInfo.size = new _ULong((ulong)file.Length);
            DvMediaResource res = DvResourceBuilder.CreateResource(resInfo, true);
            res.Tag = file;
            newMedia.AddResource(res);

            return newMedia;
        }