Ejemplo n.º 1
0
        /// <summary>
        /// Loads playlist generators from xml
        /// </summary>
        public void Load(string xmlFile)
        {
            if (File.Exists(xmlFile))
            {
                // create doc and load
                XmlDocument playlistsXmlDoc = new XmlDocument();
                playlistsXmlDoc.Load(xmlFile);

                // get the parent node
                XmlNode parentNode = playlistsXmlDoc.ChildNodes.Cast <XmlNode>().FirstOrDefault();
                if (parentNode != null)
                {
                    // loop through playlist nodes in xml
                    foreach (XmlNode playlistNode in parentNode.ChildNodes)
                    {
                        // create playlist generator from node
                        PlaylistGenerator playlistGenerator =
                            PlaylistGenerator.CreateFromXml((XmlElement)playlistNode);

                        // add to list
                        PlaylistGenerators.Add(playlistGenerator.Name, playlistGenerator);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void RaiseGeneratorAdded(PlaylistGenerator generator)
 {
     if (GeneratorAdded != null)
     {
         GeneratorAdded(generator);
     }
 }
Ejemplo n.º 3
0
        private IActionResult GetPlaylistActionResult(
            string chanel,
            DateTime time,
            int hlsListSize)
        {
            var content = "";

            try
            {
                content = PlaylistGenerator.GeneratePlaylist(
                    chanel,
                    time,
                    _ffmpegConfig,
                    _streamsConfig,
                    hlsListSize
                    );
            }
            catch (Exception e)
            {
                return(new JsonResult(e.Message));
            }

            var bytes  = Encoding.UTF8.GetBytes(content);
            var result = new FileContentResult(bytes, "text/utf8")
            {
                FileDownloadName = "index.m3u8"
            };

            Console.WriteLine("Requested .m3u8 {0}", DateTime.Now);

            return(result);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Callback(string code, string state, string error)
        {
            Authentication.RedirectUri = RedirectUri;

            var token = await Authentication.GetAccessToken(code);

            if (token == null || token.HasExpired)
            {
                throw new Exception("Sys!");
            }

            Session["SpotifyToken"] = token;

            new TaskFactory().StartNew(() => PlaylistGenerator.GenerateAndStorePlaylistTracks(token));

            Thread.Sleep(TimeSpan.FromSeconds(10));

            var redirect = Session["LoginRedirectUrl"] as string;

            if (redirect != null)
            {
                return(Redirect(redirect));
            }

            return(Redirect(Url.RouteUrl("default", new { controller = "Cause", action = "Create" })));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Join(int id)
        {
            var token = Session["SpotifyToken"] as AuthenticationToken;

            if (token == null)
            {
                throw new Exception("Not logged in against Spotify");
            }
            using (var db = new SoundFundingDbContext())
            {
                var cause = db.Causes.Find(id);

                if (cause.SpotifyPlaylistId != null)
                {
                    var user = await PlaylistGenerator.AddToPlaylist(token, cause);

                    var image = user.Images.FirstOrDefault();
                    if (image != null)
                    {
                        cause.Contributors = cause.Contributors ?? new List <Contributor>();
                        cause.Contributors.Add(new Contributor
                        {
                            ImageUrl = image.Url
                        });
                    }
                }

                db.SaveChanges();
            }
            return(RedirectToAction("Cause", new { id = id }));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Stops the generator and updates its status
        /// </summary>
        public void StopGenerator()
        {
            if (PlaylistGenerator != null)
            {
                PlaylistGenerator.Stop();

                RaiseStatusChanged();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Runs the generator and updates its status
        /// </summary>
        public void StartGenerator()
        {
            if (PlaylistGenerator != null)
            {
                // start the playlist generator
                PlaylistGenerator.Start();

                RaiseStatusChanged();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Instantiates the view model with an existing playlist generator
        /// </summary>
        /// <param name="container"></param>
        /// <param name="playlistGenerator"></param>
        public PlaylistGeneratorViewModel(IUnityContainer container, PlaylistGenerator playlistGenerator)
            : base(container)
        {
            PlaylistGenerator = playlistGenerator;

            if (PlaylistGenerator != null)
            {
                SetValuesFromGenerator();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds a new playlist creator to the list
        /// </summary>
        /// <param name="mediaFolder">The folder to watch for media files</param>
        /// <param name="outputFolder">The output folder for playlist files</param>
        /// <param name="scanInterval">The interval at which to scan the media folder</param>
        /// <param name="playlistCreationInterval">The interval at which to create new playlists</param>
        public PlaylistGenerator AddPlaylistGenerator(string name,
                                                      string mediaFolder,
                                                      string outputFolder,
                                                      TimeSpan scanInterval,
                                                      TimeSpan playlistCreationInterval)
        {
            // create the playlist generator
            PlaylistGenerator playlistGenerator = PlaylistGenerator.Create(name, mediaFolder, outputFolder, scanInterval, playlistCreationInterval);

            // add it to the list
            PlaylistGenerators.Add(name, playlistGenerator);

            // indicate that it's been added
            RaiseGeneratorAdded(playlistGenerator);

            return(playlistGenerator);
        }
Ejemplo n.º 10
0
        private static void GeneratePlaylist()
        {
            Console.WriteLine("Playlist generation started.");

            try
            {
                using (var playlistGenerator = new PlaylistGenerator())
                {
                    playlistGenerator.GeneratePlaylist().Wait();
                }
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine(exception.Message);
            }

            Console.WriteLine("Playlist generation finished.");
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> Create(Cause cause)
        {
            var token = Session["SpotifyToken"] as AuthenticationToken;

            if (token == null)
            {
                throw new Exception("Not logged in against Spotify");
            }

            if (ModelState.IsValid)
            {
                if (cause.PostedPicture != null)
                {
                    var bh = new BlobHandler("soundfunding");
                    bh.Upload(new List <HttpPostedFileBase> {
                        cause.PostedPicture
                    });
                    var blobUri = bh.GetBlobs().FirstOrDefault(b => b.Contains(cause.PostedPicture.FileName));
                    cause.Picture = blobUri;
                }

                var playlist = await PlaylistGenerator.GeneratePlaylist(token, cause);

                cause.SpotifyPlaylistId  = playlist.Id;
                cause.SpotifyPlaylistUri = playlist.Uri;
                cause.SpotifyUserId      = playlist.Owner.Id;

                var image = playlist.Owner.Images.FirstOrDefault();
                if (image != null)
                {
                    cause.SpotifyUserAvatarUrl = image.Url;
                }

                using (var db = new SoundFundingDbContext())
                {
                    db.Causes.Add(cause);
                    db.SaveChanges();
                }

                return(RedirectToAction("Cause", "Cause", new { id = cause.Id }));
            }
            return(View("Create"));
        }
Ejemplo n.º 12
0
 protected override void When()
 {
     PlaylistGenerator.GeneratePlaylist(ControlFile, ControlFile.GetSourceRoot(), true, null);
 }
 /// <summary>
 /// Instantiates the view model with an existing playlist generator
 /// </summary>
 /// <param name="container"></param>
 /// <param name="playlistGenerator"></param>
 public EditPlaylistGeneratorViewModel(IUnityContainer container, PlaylistGenerator playlistGenerator)
     : base(container, playlistGenerator)
 {
     // set values on generator
     SetValuesFromGenerator();
 }
 /// <summary>
 /// Adds a generator to the list
 /// </summary>
 /// <param name="playlistGenerator"></param>
 public void AddGenerator(PlaylistGenerator playlistGenerator)
 {
     PlaylistGeneratorVMs.Add(new PlaylistGeneratorViewModel(Container, playlistGenerator));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Handles adding of a generator to the playlist manager
 /// </summary>
 /// <param name="playlistGenerator"></param>
 public void OnGeneratorAdded(PlaylistGenerator playlistGenerator)
 {
     PlaylistGeneratorsListVM.AddGenerator(playlistGenerator);
 }
 protected override void When()
 {
     PlaylistGenerator.GeneratePlaylist(ControlFile, false);
 }
Ejemplo n.º 17
0
 private void RaiseGeneratorAdded(PlaylistGenerator generator)
 {
     if (GeneratorAdded != null)
         GeneratorAdded(generator);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Handles adding of a generator to the playlist manager
 /// </summary>
 /// <param name="playlistGenerator"></param>
 public void OnGeneratorAdded(PlaylistGenerator playlistGenerator)
 {
     PlaylistGeneratorsListVM.AddGenerator(playlistGenerator);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Instantiates the view model with an existing playlist generator
        /// </summary>
        /// <param name="container"></param>
        /// <param name="playlistGenerator"></param>
        public PlaylistGeneratorViewModel(IUnityContainer container, PlaylistGenerator playlistGenerator)
            : base(container)
        {
            PlaylistGenerator = playlistGenerator;

            if (PlaylistGenerator != null)
                SetValuesFromGenerator();
        }
 /// <summary>
 /// Instantiates the view model with an existing playlist generator
 /// </summary>
 /// <param name="container"></param>
 /// <param name="playlistGenerator"></param>
 public EditPlaylistGeneratorViewModel(IUnityContainer container, PlaylistGenerator playlistGenerator)
     : base(container, playlistGenerator)
 {
     // set values on generator
     SetValuesFromGenerator();
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Adds a generator to the list
 /// </summary>
 /// <param name="playlistGenerator"></param>
 public void AddGenerator(PlaylistGenerator playlistGenerator)
 {
     PlaylistGeneratorVMs.Add(new PlaylistGeneratorViewModel(Container, playlistGenerator));
 }