Exemplo n.º 1
0
        public List <ArtistItem> GetSimilarArtistsSite(string site)
        {
            List <ArtistItem> res = new List <ArtistItem>();

            try
            {
                Regex regexObj =
                    new Regex("<h3 class=\"channel-summary-title\">.*?<a href=\"/artist/(?<id>.*?)\" class=\"yt-uix-tile-link\">YouTube - (?<name>.*?)</a>",
                              RegexOptions.Singleline);
                Match matchResult = regexObj.Match(site);
                while (matchResult.Success)
                {
                    ArtistItem item = new ArtistItem()
                    {
                        Id = matchResult.Groups["id"].Value, Name = HttpUtility.HtmlDecode(matchResult.Groups["name"].Value)
                    };
                    ArtistManager.Instance.AddArtist(item);
                    res.Add(item);
                    matchResult = matchResult.NextMatch();
                }
            }
            catch (ArgumentException ex)
            {
                // Syntax error in the regular expression
            }
            return(res);
        }
Exemplo n.º 2
0
        public ArtistItem GetArtistsByName(string name)
        {
            ArtistItem res = new ArtistItem();

            res = DatabaseProvider.InstanInstance.GetArtistsByName(name);
            if (res != null)
            {
                return(res);
            }
            res = new ArtistItem();
            string lsSQL = string.Format("select * from ARTISTS WHERE ARTIST_NAME like '{0}' order by ARTIST_NAME",
                                         DatabaseUtility.RemoveInvalidChars(name));
            SQLiteResultSet loResultSet = m_db.Execute(lsSQL);

            for (int iRow = 0; iRow < loResultSet.Rows.Count; iRow++)
            {
                res.Id      = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_ID");
                res.Name    = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_NAME");
                res.Img_url = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_IMG");
                res.User    = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_USER");
                res.Tags    = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_TAG");
                break;
            }
            return(res);
        }
Exemplo n.º 3
0
        public void AddArtist(ArtistItem artistItem)
        {
            try
            {
                if (string.IsNullOrEmpty(artistItem.Id))
                {
                    return;
                }

                string          lsSQL       = string.Format("select distinct ARTIST_ID,ARTIST_IMG from ARTISTS WHERE ARTIST_ID=\"{0}\"", artistItem.Id);
                SQLiteResultSet loResultSet = m_db.Execute(lsSQL);
                if (loResultSet.Rows.Count > 0)
                {
                    for (int iRow = 0; iRow < loResultSet.Rows.Count; iRow++)
                    {
                        artistItem.Img_url = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_IMG");
                        artistItem.Tags    = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_TAG");
                    }
                    return;
                }
                lsSQL =
                    string.Format(
                        "insert into ARTISTS (ARTIST_ID,ARTIST_NAME,ARTIST_IMG, ARTIST_USER, ARTIST_TAG) VALUES ('{0}','{1}','{2}','{3}','{4}')",
                        artistItem.Id,
                        DatabaseUtility.RemoveInvalidChars(artistItem.Name), artistItem.Img_url, artistItem.User,
                        DatabaseUtility.RemoveInvalidChars(artistItem.Tags));
                m_db.Execute(lsSQL);
                artistItem.Db_id = m_db.LastInsertID();
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 4
0
 public void SetSkinProperties(ArtistItem artistItem, string prefix)
 {
     GUIPropertyManager.SetProperty("#Youtube.fm." + prefix + ".Artist.Image", " ");
     GUIPropertyManager.SetProperty("#Youtube.fm." + prefix + ".Artist.Name", Property(artistItem.Name));
     GUIPropertyManager.SetProperty("#Youtube.fm." + prefix + ".Artist.Bio", Property(artistItem.Bio));
     GUIPropertyManager.SetProperty("#Youtube.fm." + prefix + ".Artist.Tags", Property(artistItem.Tags));
     GUIPropertyManager.SetProperty("#Youtube.fm." + prefix + ".Artist.Image",
                                    Property(artistItem.LocalImage));
 }
Exemplo n.º 5
0
 public string GetArtistUser(string artist_id)
 {
     try
     {
         string     site       = DownloadArtistInfo(artist_id);
         Regex      regexObj   = new Regex("class=\"channel-details\">.*?<a href=\"/user/.*?\">(?<user>.*?)</a>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
         string     user       = regexObj.Match(site).Groups["user"].Value;
         ArtistItem artistItem = ArtistManager.Instance.GetArtistsById(artist_id);
         artistItem.User = user;
         ArtistManager.Instance.Save(artistItem);
         return(user);
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
Exemplo n.º 6
0
 public void SaveTag(ArtistItem artistItem, string tag)
 {
     try
     {
         if (string.IsNullOrEmpty(artistItem.Id) || string.IsNullOrEmpty(tag))
         {
             return;
         }
         string lsSQL =
             string.Format(
                 "insert into TAGS (ARTIST_ID, ARTIST_TAG) VALUES ('{0}','{1}')",
                 artistItem.Id, DatabaseUtility.RemoveInvalidChars(tag));
         m_db.Execute(lsSQL);
     }
     catch (Exception exception)
     {
     }
 }
Exemplo n.º 7
0
        public ArtistItem GetArtistsById(string id)
        {
            ArtistItem      res         = new ArtistItem();
            string          lsSQL       = string.Format("select * from ARTISTS WHERE ARTIST_ID = '{0}' order by ARTIST_NAME", id);
            SQLiteResultSet loResultSet = m_db.Execute(lsSQL);

            for (int iRow = 0; iRow < loResultSet.Rows.Count; iRow++)
            {
                res.Id      = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_ID");
                res.Name    = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_NAME");
                res.Img_url = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_IMG");
                res.User    = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_USER");
                res.Tags    = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_TAG");
            }
            ;

            return(res);
        }
Exemplo n.º 8
0
        public void Save(ArtistItem artistItem)
        {
            if (string.IsNullOrEmpty(artistItem.Id))
            {
                return;
            }
            //if (Youtube2MP.LastFmProfile.Session != null)
            //{
            //  Lastfm.Services.Artist artist = new Lastfm.Services.Artist(artistItem.Name, Youtube2MP.LastFmProfile.Session);
            //  artistItem.Img_url = artist.GetImageURL(ImageSize.Large);
            //}
            string lsSQL =
                string.Format(
                    "UPDATE ARTISTS SET ARTIST_NAME ='{1}' ,ARTIST_IMG='{2}', ARTIST_USER='******', ARTIST_TAG='{4}', ARTIST_BIO='{5}'  WHERE ARTIST_ID='{0}' ",
                    artistItem.Id, DatabaseUtility.RemoveInvalidChars(artistItem.Name),
                    artistItem.Img_url, artistItem.User, DatabaseUtility.RemoveInvalidChars(artistItem.Tags),
                    DatabaseUtility.RemoveInvalidChars(artistItem.Bio));

            m_db.Execute(lsSQL);
        }
Exemplo n.º 9
0
        public ArtistItem GetFromVideoSite(string site)
        {
            ArtistItem res = new ArtistItem();

            try
            {
                Regex regexObj    = new Regex(@"<a href=""/artist/(?<id>.*?)\?.*?Artist: <span class=.link-like.>(?<name>.*?)</span>", RegexOptions.Singleline);
                Match matchResult = regexObj.Match(site);
                while (matchResult.Success)
                {
                    res.Id   = matchResult.Groups["id"].Value;
                    res.Name = HttpUtility.HtmlDecode(matchResult.Groups["name"].Value);
                    //res.Img_url = HttpUtility.HtmlDecode(matchResult.Groups["img_url"].Value);
                    matchResult = matchResult.NextMatch();
                }
                GetArtistUser(res.Id);
            }
            catch (ArgumentException ex)
            {
                // Syntax error in the regular expression
            }
            return(res);
        }
Exemplo n.º 10
0
        public bool SetSkinProperties(YouTubeEntry youTubeEntry, string prefix, bool grab, bool download)
        {
            if (youTubeEntry == null)
            {
                return(true);
            }
            ArtistItem artistItem = DatabaseProvider.InstanInstance.GetArtist(youTubeEntry);

            if (artistItem == null && grab)
            {
                string vidId = Youtube2MP.GetVideoId(youTubeEntry);
                artistItem = SitesCache.GetByVideoId(vidId) != null
                       ? Grabber.GetFromVideoSite(SitesCache.GetByVideoId(vidId).SIte)
                       : Grabber.GetFromVideoId(vidId);
            }
            if (artistItem == null)
            {
                string art = GetArtistName(youTubeEntry.Title.Text);
                artistItem = GetArtistsByName(art);
            }
            if ((artistItem == null || string.IsNullOrEmpty(artistItem.Bio) || string.IsNullOrEmpty(artistItem.Img_url)) && grab)
            {
                if (artistItem == null || string.IsNullOrEmpty((artistItem.Name)))
                {
                    artistItem = new ArtistItem()
                    {
                        Name = GetArtistName(youTubeEntry.Title.Text)
                    }
                }
                ;

                try
                {
                    Lastfm.Services.Artist artist = new Lastfm.Services.Artist(artistItem.Name, Youtube2MP.LastFmProfile.Session);
                    if (string.IsNullOrEmpty(artistItem.Img_url))
                    {
                        artistItem.Img_url = artist.GetImageURL(ImageSize.Huge);
                    }
                    if (string.IsNullOrEmpty(artistItem.Bio))
                    {
                        ArtistBio artistBio = artist.Bio;
                        artistBio.Lang = GUILocalizeStrings.GetCultureName(GUILocalizeStrings.CurrentLanguage());
                        string contents = Regex.Replace(HttpUtility.HtmlDecode(artistBio.getContent()), "<.*?>",
                                                        string.Empty);
                        if (string.IsNullOrEmpty(contents))
                        {
                            artistBio.Lang = string.Empty;
                            contents       = Regex.Replace(HttpUtility.HtmlDecode(artistBio.getContent()), "<.*?>",
                                                           string.Empty);
                        }
                        artistItem.Bio = contents;
                    }
                    if (string.IsNullOrEmpty(artistItem.Tags))
                    {
                        int      i       = 0;
                        string   tags    = "";
                        TopTag[] topTags = artist.GetTopTags();
                        foreach (TopTag tag in topTags)
                        {
                            tags += tag.Item.Name + "|";
                            if (i < 5)
                            {
                                if (!string.IsNullOrEmpty(artistItem.Id))
                                {
                                    SaveTag(artistItem, tag.Item.Name);
                                }
                            }
                            i++;
                        }
                        artistItem.Tags = tags;
                    }
                    DatabaseProvider.InstanInstance.AddArtist(artistItem);
                }
                catch (Exception exception)
                {
                    Log.Debug(exception.Message);
                }
            }
            if (artistItem != null)
            {
                if (download && !File.Exists(artistItem.LocalImage))
                {
                    Youtube2MP.DownloadFile(artistItem.Img_url, artistItem.LocalImage);
                }
                SetSkinProperties(artistItem, prefix);
            }
            return(false);
        }