Esempio n. 1
0
        /// <summary>
        ///     Stores this instance to the specified url.
        /// </summary>
        public override void Store(String url)
        {
            Url = url; //use this from now on.
            List <Quirli.Api.Track> quirliPlaylist = new List <Quirli.Api.Track>();
            string targetDirectory = Path.GetDirectoryName(url) + @"\";
            Uri    urlRoot         = new Uri(targetDirectory);

            //create a deployment information with all relevant stuff per track
            int index           = 0;
            var mediaDeployment = (from track in Tracks
                                   let trackSource = Find(track)
                                                     let i = ++index
                                                                                                                                                                                       //let targetFileName = Path.GetFileName(trackSource)
                                                             let targetFileName = Path.GetFileNameWithoutExtension(url) + String.Format("-{0:00}", i) + Path.GetExtension(trackSource) //alternative with prefix number instead of just name
                                                                                  select new {
                Track = track,
                TrackSource = trackSource,
                TargetFileName = targetFileName,
                TrackTarget = targetDirectory + targetFileName
            }
                                   ).ToList(); //track media files

            //store the files along the url
            foreach (var mediaFile in mediaDeployment)
            {
                File.Copy(mediaFile.TrackSource, mediaFile.TrackTarget, true);
                Uri relativeMediaUrl = urlRoot.MakeRelativeUri(new Uri(mediaFile.TrackTarget));

                //Quirli.Api.Track quirliTrack = QuirliAdapter.CreateFrom(track, this.MediaPath + track.Url);
                Quirli.Api.Track quirliTrack = QuirliAdapter.CreateFrom(mediaFile.Track, relativeMediaUrl);
                quirliPlaylist.Add(quirliTrack);
            }

            //store the playlist into a template HTML file
            Uri relativePlayerUrl = urlRoot.MakeRelativeUri(new Uri(targetDirectory + "player.html"));

            Player.Url = relativePlayerUrl;
            string templateContent = GetPlaylistTemplate();

            Template.RegisterSafeType(typeof(Quirli.Api.Track), new[] { "Title", "Album", "Artist", "TrackUrl" });
            Template.NamingConvention = new CSharpNamingConvention();
            Template template     = Template.Parse(templateContent); // Parses and compiles the template
            string   htmlPlaylist = template.Render(Hash.FromAnonymousObject(new {
                CompilationTitle = Title,
                Tracks           = quirliPlaylist
            }));

            using (TextWriter writeFileStream = new StreamWriter(Url)) {
                writeFileStream.Write(htmlPlaylist);
            }
            DeployPlayer();
            IsDirty = false;
        }
Esempio n. 2
0
        /// <summary>
        ///     Stores this instance to the specified url.
        /// </summary>
        public override void Store(String url)
        {
            Url = url; //use this from now on.
            //store back to file
            var CompilationSerializer = new XmlSerializer(typeof(XmlCompilation));

            using (TextWriter writeFileStream = new StreamWriter(Url))
            {
                CompilationSerializer.Serialize(writeFileStream, this);
            }

            //TODO experimental: Write quirli player too

            //Deploy to certain local path
            Quirli.Api.Player.Url = new Uri(String.Format("file:///C:/Users/marcel/Music/{0}/player.html", Path.GetFileNameWithoutExtension(Url)));
            String playerBasePath         = Path.GetDirectoryName(Quirli.Api.Player.Url.LocalPath);
            String mediafilesSubdirectory = @"\media\";

            Directory.CreateDirectory(playerBasePath + mediafilesSubdirectory);
            Quirli.Api.Player.Deploy();

            var playlist = new Playlist();

            playlist.Title = this.Title;
            foreach (Track track in Tracks)
            {
                Quirli.Api.Track quirliTrack = QuirliAdapter.CreateFrom(track, Find(track));

                //copy and adapt media file
                String mediaFileName        = Path.GetFileName(track.Url);
                String mediaFileDestination = playerBasePath + mediafilesSubdirectory + mediaFileName;
                FileSystem.FileCopy(track.Url, mediaFileDestination);
                //quirliTrack.MediaUrl = (new Uri(mediaFileDestination)).MakeRelativeUri(new Uri(playerBasePath));
                quirliTrack.MediaUrl = (new Uri(playerBasePath + @"\")).MakeRelativeUri(new Uri(mediaFileDestination));

                //w.WriteLine(String.Format("<a href={0}>{1}</a><br>", quirliTrack.TrackUrl, quirliTrack.Title));
                playlist.Tracks.Add(quirliTrack);
            }

            //Deploy to certain local path
            playlist.Store();

            IsDirty = false;
        }