Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            //--------------------------------------------------------------------------------------------------------------------
            string id = context.Request.QueryString["id"].ToString();

            //--------------------------------------------------------------------------------------------------------------------



            //--------------------------------------------------------------------------------------------------------------------
            hypster_tv_DAL.songsManagement songManager = new hypster_tv_DAL.songsManagement();
            hypster_tv_DAL.Song            item        = new hypster_tv_DAL.Song();
            item = songManager.GetSongByGUID(id);
            //--------------------------------------------------------------------------------------------------------------------



            //--------------------------------------------------------------------------------------------------------------------
            XElement   xml;
            XNamespace jwNS = "http://developer.longtailvideo.com/trac/wiki/FlashFormats";

            xml = new XElement("playlist", new XAttribute(XNamespace.Xmlns + "jwplayer", jwNS.NamespaceName), new XElement("title", "Hypster Radio"),
                               new XElement("tracklist", new XElement("track",
                                                                      new XAttribute("id", item.id),
                                                                      new XElement("title", HttpUtility.HtmlEncode(item.FullTitle)),
                                                                      new XElement("location", (item.YoutubeId == "") ?
                                                                                   "http://www.hypster.com/Handlers/Stream.ashx?id=" + item.id + "&pid=0&type=.mp3"
                                                                                    :
                                                                                   "http://www.youtube.com/watch?v=" + item.YoutubeId + "&id=" + item.id + "&pid=0&type=youtube")
                                                                      )));
            //--------------------------------------------------------------------------------------------------------------------



            //--------------------------------------------------------------------------------------------------------------------
            context.Response.ContentType = "text/xml";
            context.Response.Write(xml.ToString());
            //--------------------------------------------------------------------------------------------------------------------
        }
        public ActionResult ConvertYearToPlaylist(string plst_name, int?curr_year, int?user_id)
        {
            if (Session["Roles"] != null && Session["Roles"].Equals("Admin"))
            {
                List <hypster_tv_DAL.PlaylistData_Song> new_songs = new List <hypster_tv_DAL.PlaylistData_Song>();
                short CURR_SORT_ID = 1;
                int   CURR_USER_ID = (int)user_id;
                //-------------------------------------------------------------------------------------------------------------------------------
                //-------------------------------------------------------------------------------------------------------------------------------
                hypster_tv_DAL.playlistManagement playlistManager = new hypster_tv_DAL.playlistManagement();
                hypster_tv_DAL.songsManagement    songsManager    = new hypster_tv_DAL.songsManagement();
                hypster_tv_DAL.Hypster_Entities   hypDB           = new hypster_tv_DAL.Hypster_Entities();
                hypster_tv_DAL.Playlist           new_playlist    = new hypster_tv_DAL.Playlist();
                new_playlist.create_time        = 0;
                new_playlist.is_artist_playlist = false;
                new_playlist.name        = plst_name;
                new_playlist.update_time = 0;
                new_playlist.userid      = (int)user_id;
                new_playlist.ViewsNum    = 0;
                new_playlist.Likes       = 0;
                int NEW_PLAYLIST_ID = playlistManager.AddNewPlaylist(new_playlist);
                //-------------------------------------------------------------------------------------------------------------------------------
                //-------------------------------------------------------------------------------------------------------------------------------
                string currURL    = "http://en.wikipedia.org/wiki/Billboard_Year-End_Hot_100_singles_of_" + curr_year.ToString();
                var    strContent = "";
                var    webRequest = WebRequest.Create(currURL);
                using (var response = webRequest.GetResponse())
                    using (var content = response.GetResponseStream())
                        using (var reader = new StreamReader(content))
                        {
                            strContent = reader.ReadToEnd();
                        }
                //-------------------------------------------------------------------------------------------------------------------------------
                //-------------------------------------------------------------------------------------------------------------------------------
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(strContent);
                ViewBag.Chart_Header = "Billboard Year-End Hot 100 singles of " + curr_year;
                ViewBag.curr_year    = curr_year;
                //-------------------------------------------------------------------------------------------------------------------------------
                //-------------------------------------------------------------------------------------------------------------------------------
                if (curr_year >= 1982)
                {
                    HtmlAgilityPack.HtmlNode songNode = doc.DocumentNode.SelectSingleNode("/html/body/div/div/div/table");
                    if (songNode != null)
                    {
                        HtmlAgilityPack.HtmlNodeCollection nodes_list = doc.DocumentNode.SelectNodes("/html/body/div/div/div/table/tr/td");
                        if (nodes_list != null)
                        {
                            int i_counter = 1;
                            for (var i = 0; i < nodes_list.Count; i += 2)
                            {
                                if ((i + 1) < nodes_list.Count)
                                {
                                    // get curr song guid
                                    //-----------------------------------------------------------------------------------------
                                    string artist_song = "";
                                    artist_song = nodes_list[i].InnerText + " - " + nodes_list[i + 1].InnerText;
                                    Video CURR_VIDEO = new Video();
                                    CURR_VIDEO = GetSongVideoByTitle(artist_song);
                                    //-----------------------------------------------------------------------------------------
                                    //get song by guid
                                    //-----------------------------------------------------------------------------------------
                                    hypster_tv_DAL.Song song = new hypster_tv_DAL.Song();
                                    song = songsManager.GetSongByGUID(CURR_VIDEO.VideoId);
                                    //-----------------------------------------------------------------------------------------
                                    //-----------------------------------------------------------------------------------------
                                    if (song.id == 0) //add new song
                                    {
                                        if (CURR_VIDEO.Title != null && CURR_VIDEO.VideoId != null)
                                        {
                                            //need to modify to add more song params
                                            hypster_tv_DAL.Song new_song = new hypster_tv_DAL.Song();
                                            new_song.Title            = CURR_VIDEO.Title;
                                            new_song.YoutubeId        = CURR_VIDEO.VideoId;
                                            new_song.adddate          = DateTime.Now;
                                            new_song.YoutubeProcessed = false;

                                            if (CURR_VIDEO.Author != null)
                                            {
                                                new_song.Author = CURR_VIDEO.Uploader;
                                            }
                                            //if (CURR_VIDEO.RatingAverage != null)
                                            if (CURR_VIDEO.RatingAverage != 0)
                                            {
                                                new_song.Rating = (float)CURR_VIDEO.RatingAverage;
                                            }
                                            if (CURR_VIDEO.AppControl != null)
                                            {
                                                new_song.Syndication = 1;
                                            }

                                            hypDB.Songs.AddObject(new_song);
                                            hypDB.SaveChanges();

                                            //get newely added song
                                            song = songsManager.GetSongByGUID(CURR_VIDEO.VideoId);
                                            //add to playlist data
                                            hypster_tv_DAL.PlaylistData new_playlistData = new hypster_tv_DAL.PlaylistData();
                                            new_playlistData.playlist_id = NEW_PLAYLIST_ID;
                                            new_playlistData.songid      = song.id;
                                            new_playlistData.sortid      = CURR_SORT_ID;
                                            new_playlistData.userid      = CURR_USER_ID;
                                            hypDB.PlaylistDatas.AddObject(new_playlistData);
                                            hypDB.SaveChanges();
                                        }
                                    }
                                    else //if song exist in database
                                    {
                                        //add to playlist data
                                        hypster_tv_DAL.PlaylistData new_playlistData = new hypster_tv_DAL.PlaylistData();
                                        new_playlistData.playlist_id = NEW_PLAYLIST_ID;
                                        new_playlistData.songid      = song.id;
                                        new_playlistData.sortid      = CURR_SORT_ID;
                                        new_playlistData.userid      = CURR_USER_ID;
                                        hypDB.PlaylistDatas.AddObject(new_playlistData);
                                        hypDB.SaveChanges();
                                    }
                                    //-----------------------------------------------------------------------------------------
                                    i_counter    += 1;
                                    CURR_SORT_ID += 1;
                                }
                            }
                        }
                    }
                }
                else
                {
                    HtmlAgilityPack.HtmlNode songNode = doc.DocumentNode.SelectSingleNode("/html/body/div/div/div/table");
                    if (songNode != null)
                    {
                        HtmlAgilityPack.HtmlNodeCollection nodes_list = doc.DocumentNode.SelectNodes("/html/body/div/div/div/table/tr/td");
                        if (nodes_list != null)
                        {
                            int i_counter = 1;
                            for (var i = 0; i < nodes_list.Count; i += 3)
                            {
                                if ((i + 2) < nodes_list.Count)
                                {
                                    // get curr song guid
                                    //-----------------------------------------------------------------------------------------
                                    string artist_song = "";
                                    artist_song = nodes_list[i + 1].InnerText + " - " + nodes_list[i + 2].InnerText;
                                    Video CURR_VIDEO = new Video();
                                    CURR_VIDEO = GetSongVideoByTitle(artist_song);
                                    //-----------------------------------------------------------------------------------------
                                    //get song by guid
                                    //-----------------------------------------------------------------------------------------
                                    hypster_tv_DAL.Song song = new hypster_tv_DAL.Song();
                                    song = songsManager.GetSongByGUID(CURR_VIDEO.VideoId);
                                    //-----------------------------------------------------------------------------------------
                                    //-----------------------------------------------------------------------------------------
                                    if (song.id == 0) //add new song
                                    {
                                        //need to modify to add more song params
                                        hypster_tv_DAL.Song new_song = new hypster_tv_DAL.Song();
                                        new_song.Title            = CURR_VIDEO.Title;
                                        new_song.YoutubeId        = CURR_VIDEO.VideoId;
                                        new_song.adddate          = DateTime.Now;
                                        new_song.YoutubeProcessed = false;

                                        if (CURR_VIDEO.Author != null)
                                        {
                                            new_song.Author = CURR_VIDEO.Uploader;
                                        }
                                        if (CURR_VIDEO.RatingAverage != 0)
                                        {
                                            new_song.Rating = (float)CURR_VIDEO.RatingAverage;
                                        }
                                        if (CURR_VIDEO.AppControl != null)
                                        {
                                            new_song.Syndication = 1;
                                        }
                                        hypDB.Songs.AddObject(new_song);
                                        hypDB.SaveChanges();
                                        //get newely added song
                                        song = songsManager.GetSongByGUID(CURR_VIDEO.VideoId);
                                        //add to playlist data
                                        hypster_tv_DAL.PlaylistData new_playlistData = new hypster_tv_DAL.PlaylistData();
                                        new_playlistData.playlist_id = NEW_PLAYLIST_ID;
                                        new_playlistData.songid      = song.id;
                                        new_playlistData.sortid      = CURR_SORT_ID;
                                        new_playlistData.userid      = CURR_USER_ID;

                                        hypDB.PlaylistDatas.AddObject(new_playlistData);
                                        hypDB.SaveChanges();
                                    }
                                    else //if song exist in database
                                    {
                                        //add to playlist data
                                        hypster_tv_DAL.PlaylistData new_playlistData = new hypster_tv_DAL.PlaylistData();
                                        new_playlistData.playlist_id = NEW_PLAYLIST_ID;
                                        new_playlistData.songid      = song.id;
                                        new_playlistData.sortid      = CURR_SORT_ID;
                                        new_playlistData.userid      = CURR_USER_ID;
                                        hypDB.PlaylistDatas.AddObject(new_playlistData);
                                        hypDB.SaveChanges();
                                    }
                                    //-----------------------------------------------------------------------------------------
                                    i_counter    += 1;
                                    CURR_SORT_ID += 1;
                                }
                            }
                        }
                    }
                }
                //-------------------------------------------------------------------------------------------------------------------------------
                return(RedirectPermanent("/WebsiteManagement/manageCharts"));
            }
            else
            {
                return(RedirectPermanent("/home/"));
            }
        }
        public ActionResult SubmitAddNewSongPopup(string Song_Title, string Song_Guid, int?Sel_Playlist_ID, int?StayHereCheck)
        {
            // 1.genral declarations
            //--------------------------------------------------------------------------------------------
            hypster_tv_DAL.Hypster_Entities   hypDB              = new hypster_tv_DAL.Hypster_Entities();
            hypster_tv_DAL.songsManagement    songsManager       = new hypster_tv_DAL.songsManagement();
            hypster_tv_DAL.memberManagement   userManager        = new hypster_tv_DAL.memberManagement();
            hypster_tv_DAL.playlistManagement playlistManagement = new hypster_tv_DAL.playlistManagement();
            //--------------------------------------------------------------------------------------------



            //get curr user
            //-----------------------------------------------------------------------------------------
            hypster_tv_DAL.Member curr_user = new hypster_tv_DAL.Member();
            curr_user = userManager.getMemberByUserName(User.Identity.Name);
            //-----------------------------------------------------------------------------------------



            //check if user has default playlist
            //-----------------------------------------------------------------------------------------
            if (curr_user.active_playlist == 0)
            {
                hypster_tv_DAL.Playlist create_playlist = new hypster_tv_DAL.Playlist();
                create_playlist.name   = curr_user.username + "'s playlist";
                create_playlist.userid = curr_user.id;


                if (create_playlist.name.Length > 60)
                {
                    create_playlist.name = create_playlist.name.Substring(0, 60);
                }


                hypDB.Playlists.AddObject(create_playlist);
                hypDB.SaveChanges();

                List <hypster_tv_DAL.Playlist> playlists_list = playlistManagement.GetUserPlaylists(curr_user.id);
                if (playlists_list.Count > 0)
                {
                    curr_user.active_playlist = playlists_list[0].id;
                    userManager.SetUserDefaultPlaylist(User.Identity.Name, curr_user.id, curr_user.active_playlist);
                }
                //else error - need to have dafult playlist
            }
            //-----------------------------------------------------------------------------------------



            //check if user selected playlist
            //-----------------------------------------------------------------------------------------
            if (Sel_Playlist_ID == null || Sel_Playlist_ID == 0)
            {
                Sel_Playlist_ID = curr_user.active_playlist;
            }
            //-----------------------------------------------------------------------------------------



            // get last sort_number
            //-----------------------------------------------------------------------------------------
            short Sel_Sort_Order = 0;

            //List<hypster_tv_DAL.PlaylistData_Song> songs_list = new List<hypster_tv_DAL.PlaylistData_Song>();
            //songs_list = playlistManagement.GetSongsForPlayList(curr_user.id, (int)Sel_Playlist_ID);
            //if (songs_list.Count > 0)
            //{
            //    Sel_Sort_Order = songs_list[0].sortid;
            //    for (int i = 0; i < songs_list.Count; i++)
            //    {
            //        if (songs_list[i].sortid > Sel_Sort_Order)
            //            Sel_Sort_Order = songs_list[i].sortid;
            //    }
            //}
            //Sel_Sort_Order += 1;


            playlistManagement.IncrementPlaylistSongOrder(curr_user.id, (int)Sel_Playlist_ID);
            //set sort order to first position
            Sel_Sort_Order = 1;
            //-----------------------------------------------------------------------------------------



            //get song by guid
            //-----------------------------------------------------------------------------------------
            hypster_tv_DAL.Song song = new hypster_tv_DAL.Song();
            song = songsManager.GetSongByGUID(Song_Guid);
            //-----------------------------------------------------------------------------------------



            if (Song_Title.Length > 160)
            {
                Song_Title = Song_Title.Substring(0, 160);
            }



            //-----------------------------------------------------------------------------------------
            if (song.id == 0) //add new song
            {
                string video_Author        = "";
                float  video_RatingAverage = 0;
                byte   video_AppControl    = 0;
                string video_Title         = "";

                try
                {
                    //need to get song details
                    YouTubeRequestSettings settings = new YouTubeRequestSettings("hypster", "AI39si5TNjKgF6yiHwUhKbKwIui2JRphXG4hPXUBdlrNh4XMZLXu--lf66gVSPvks9PlWonEk2Qv9fwiadpNbiuh-9TifCNsqA");
                    YouTubeRequest         request  = new YouTubeRequest(settings);
                    string feedUrl = "http://gdata.youtube.com/feeds/api/videos/" + Song_Guid;
                    Video  video   = request.Retrieve <Video>(new Uri(feedUrl));


                    if (video.Author != null)
                    {
                        video_Author = video.Uploader;
                    }
                    if (video.RatingAverage != null)
                    {
                        video_RatingAverage = (float)video.RatingAverage;
                    }
                    if (video.AppControl != null)
                    {
                        video_AppControl = 1;
                    }
                    if (video.Title != null)
                    {
                        video_Title = video.Title;
                    }
                }
                catch (Exception ex)
                {
                }


                //need to modify to add more song params
                hypster_tv_DAL.Song new_song = new hypster_tv_DAL.Song();
                new_song.Title            = video_Title;
                new_song.YoutubeId        = Song_Guid;
                new_song.adddate          = DateTime.Now;
                new_song.YoutubeProcessed = false;


                new_song.Author      = video_Author;
                new_song.Rating      = video_RatingAverage;
                new_song.Syndication = video_AppControl;

                hypDB.Songs.AddObject(new_song);
                hypDB.SaveChanges();



                //get newely added song
                song = songsManager.GetSongByGUID(Song_Guid);


                //add to playlist data
                hypster_tv_DAL.PlaylistData new_playlistData = new hypster_tv_DAL.PlaylistData();
                new_playlistData.playlist_id = Sel_Playlist_ID;
                new_playlistData.songid      = song.id;
                new_playlistData.sortid      = Sel_Sort_Order;
                new_playlistData.userid      = userManager.getMemberByUserName(User.Identity.Name).id;

                hypDB.PlaylistDatas.AddObject(new_playlistData);
                hypDB.SaveChanges();
            }
            else //if song exist in database
            {
                //add to playlist data
                hypster_tv_DAL.PlaylistData new_playlistData = new hypster_tv_DAL.PlaylistData();
                new_playlistData.playlist_id = Sel_Playlist_ID;
                new_playlistData.songid      = song.id;
                new_playlistData.sortid      = Sel_Sort_Order;
                new_playlistData.userid      = curr_user.id;


                hypDB.PlaylistDatas.AddObject(new_playlistData);
                hypDB.SaveChanges();
            }
            //-----------------------------------------------------------------------------------------



            //-----------------------------------------------------------------------------------------
            return(Content("SUCCESS", "text/html"));
            //-----------------------------------------------------------------------------------------
        }
Exemple #4
0
        public string SubmitAddNewSong(string Song_Title, string Song_Guid, string Sel_Playlist_ID)
        {
            hypster_tv_DAL.Hypster_Entities   hypDB              = new hypster_tv_DAL.Hypster_Entities();
            hypster_tv_DAL.songsManagement    songsManager       = new hypster_tv_DAL.songsManagement();
            hypster_tv_DAL.memberManagement   userManager        = new hypster_tv_DAL.memberManagement();
            hypster_tv_DAL.playlistManagement playlistManagement = new hypster_tv_DAL.playlistManagement();
            hypster_tv_DAL.Member             curr_user          = new hypster_tv_DAL.Member();
            curr_user = userManager.getMemberByUserName(User.Identity.Name);

            if (curr_user.active_playlist == 0)
            {
                hypster_tv_DAL.Playlist create_playlist = new hypster_tv_DAL.Playlist();
                create_playlist.name   = curr_user.username + "'s playlist";
                create_playlist.userid = curr_user.id;


                string crtd   = DateTime.Now.ToString("yyyyMMdd");
                int    crtd_i = 0;
                Int32.TryParse(crtd, out crtd_i);
                create_playlist.create_time = crtd_i;


                if (create_playlist.name.Length > 60)
                {
                    create_playlist.name = create_playlist.name.Substring(0, 60);
                }


                hypDB.Playlists.AddObject(create_playlist);
                hypDB.SaveChanges();

                List <hypster_tv_DAL.Playlist> playlists_list = playlistManagement.GetUserPlaylists(curr_user.id);
                if (playlists_list.Count > 0)
                {
                    curr_user.active_playlist = playlists_list[0].id;
                    userManager.SetUserDefaultPlaylist(User.Identity.Name, curr_user.id, curr_user.active_playlist);
                }
                //else error - need to have dafult playlist
            }
            //-----------------------------------------------------------------------------------------

            //check if user selected playlist
            //-----------------------------------------------------------------------------------------
            if (Sel_Playlist_ID == null)
            {
                Sel_Playlist_ID = curr_user.active_playlist.ToString();
            }
            //-----------------------------------------------------------------------------------------

            // get last sort_number
            //-----------------------------------------------------------------------------------------
            short Sel_Sort_Order = 0;

            playlistManagement.IncrementPlaylistSongOrder(curr_user.id, Convert.ToInt32(Sel_Playlist_ID));
            //set sort order to first position
            Sel_Sort_Order = 1;
            //-----------------------------------------------------------------------------------------

            //get song by guid
            //-----------------------------------------------------------------------------------------
            hypster_tv_DAL.Song song = new hypster_tv_DAL.Song();
            song = songsManager.GetSongByGUID(Song_Guid);
            //-----------------------------------------------------------------------------------------
            if (Song_Title.Length > 75)
            {
                Song_Title = Song_Title.Substring(0, 75);
            }

            //-----------------------------------------------------------------------------------------
            if (song.id == 0) //add new song
            {
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey          = System.Configuration.ConfigurationManager.AppSettings["YouTubeAPIKEY"],
                    ApplicationName = System.Configuration.ConfigurationManager.AppSettings["YouTubeAPIKEYName"]
                });

                var searchListRequest = youtubeService.Search.List("id,snippet");
                searchListRequest.Q          = Song_Guid; // Replace with your search term.
                searchListRequest.MaxResults = 1;

                var          searchListResponse = searchListRequest.Execute();
                SearchResult video = new SearchResult();
                foreach (var searchResult in searchListResponse.Items)
                {
                    switch (searchResult.Id.Kind)
                    {
                    case "youtube#video":
                        video = searchResult;
                        break;
                    }
                }

                //need to modify to add more song params
                hypster_tv_DAL.Song new_song = new hypster_tv_DAL.Song();
                new_song.Title            = Song_Title;
                new_song.YoutubeId        = Song_Guid;
                new_song.adddate          = DateTime.Now;
                new_song.YoutubeProcessed = false;

                new_song.Author      = "";
                new_song.Rating      = 1;
                new_song.Syndication = 1;

                hypDB.Songs.AddObject(new_song);
                hypDB.SaveChanges();

                //get newely added song
                song = songsManager.GetSongByGUID(Song_Guid);

                //add to playlist data
                hypster_tv_DAL.PlaylistData new_playlistData = new hypster_tv_DAL.PlaylistData();
                new_playlistData.playlist_id = Convert.ToInt32(Sel_Playlist_ID);
                new_playlistData.songid      = song.id;
                new_playlistData.sortid      = Sel_Sort_Order;
                new_playlistData.userid      = userManager.getMemberByUserName(User.Identity.Name).id;
                hypDB.PlaylistDatas.AddObject(new_playlistData);
                hypDB.SaveChanges();
            }
            else //if song exist in database
            {
                //add to playlist data
                hypster_tv_DAL.PlaylistData new_playlistData = new hypster_tv_DAL.PlaylistData();
                new_playlistData.playlist_id = Convert.ToInt32(Sel_Playlist_ID);
                new_playlistData.songid      = song.id;
                new_playlistData.sortid      = Sel_Sort_Order;
                new_playlistData.userid      = curr_user.id;
                hypDB.PlaylistDatas.AddObject(new_playlistData);
                hypDB.SaveChanges();
            }
            return("A New Song, " + Song_Title + " (ID: " + Song_Guid + ") has been added to the Playlist, " + playlistManagement.GetPlaylistById(Convert.ToInt32(Sel_Playlist_ID))[0].name);
            //return RedirectPermanent("/Editors/managePlaylist/?playlist_id=" + Sel_Playlist_ID);
        }