Beispiel #1
0
        public static async Task <RomanizedSong> RomanizeSong(Song song, bool useHtml)
        {
            //TODO: Add furigana/okurigana support across app
            Task <string> awaitLyrics = GetTransliteration(song.Lyrics, useHtml);
            Task <string> awaitTitle  = song.Title.StripJapanese();
            Task <string> awaitArtist = song.Artist.StripJapanese();
            Task <string> awaitFeat   = song.FeaturedArtist.StripJapanese();
            Task <string> awaitAlbum  = song.Album.StripJapanese();

            await Task.WhenAll(awaitLyrics, awaitTitle, awaitArtist, awaitFeat, awaitAlbum);

            RomanizedSong romanized = new RomanizedSong
            {
                Title  = await awaitTitle,
                Artist = await awaitArtist,
                Album  = await awaitAlbum,
                Lyrics = await awaitLyrics,
                Id     = song.Id
            };

            // Log(Type.Event, "Romanized song with ID " + song.Id);
            // Analytics.TrackEvent("Romanized song info", new Dictionary<string, string> {
            //     { "SongID", song.Id.ToString() }
            // });
            return(romanized);
        }
Beispiel #2
0
        public static async Task <RomanizedSong> GetRomanizedSongFromTable(int id)
        {
            Logging.Log(Logging.Type.Processing, $"Attempting to find romanized song with ID {id} on table...");

            DataRow[] _;
            try
            {
                _ = rdb.Select("id = " + id);

                if (_.Length != 0)
                {
                    DataRow       dr   = _[0];
                    RomanizedSong song = DataRowToRomanizedSong(dr);

                    return(song);
                }
                else
                {
                    Logging.Log(Logging.Type.Processing, "Did not find song, returning null...");
                    return(null);
                }
            }
            catch (EvaluateException)
            {
                //TODO: Add error hadnling
                return(null);
            }
        }
Beispiel #3
0
        public static async Task <List <SongBundle> > GetSongList()
        {
            if (File.Exists(DbPath))
            {
                InitializeTables();
                db = await ReadDatabaseFile(DbPath);

                rdb = await ReadRomanizedDatabaseFile(RomanizedDbPath);

                List <SongBundle> songs = new List <SongBundle>();

                foreach (DataRow dr in db.Rows)
                {
                    Song          song  = DataRowToSong(dr);
                    RomanizedSong rSong = null;

                    if (song.Romanized)
                    {
                        rSong = await GetRomanizedSongFromTable(song.Id);
                    }

                    songs.Add(new SongBundle(song, rSong));
                }

                return(songs);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        internal static RomanizedSong DataRowToRomanizedSong(DataRow dr)
        {
            RomanizedSong song = new RomanizedSong
            {
                Id             = (int)dr["id"],
                Title          = (string)dr["title"],
                Artist         = (string)dr["artist"],
                Album          = (string)dr["album"],
                FeaturedArtist = (string)dr["featuredArtist"]
            };

            return(song);
        }
Beispiel #5
0
        public static async Task <SongBundle> GetSongFromTable(int id)
        {
            InitializeTables();
            db = await ReadDatabaseFile(DbPath);

            rdb = await ReadRomanizedDatabaseFile(RomanizedDbPath);

            //Genius does not have a song with ID 0, if we recieve a request with
            //ID 0, immediately return null
            if (id == 0)
            {
                return(null);
            }
            else
            {
                Logging.Log(Logging.Type.Info, $"Attempting to find song with ID {id} on table...");

                DataRow[] _;
                try
                {
                    _ = db.Select("id = " + id);

                    if (_.Length != 0)
                    {
                        DataRow       dr        = _[0];
                        Song          song      = DataRowToSong(dr);
                        RomanizedSong romanized = null;

                        if (song.Romanized)
                        {
                            romanized = await GetRomanizedSongFromTable(id);
                        }

                        return(new SongBundle(song, romanized));
                    }
                    else
                    {
                        Logging.Log(Logging.Type.Info, "Did not find song, returning null...");
                        return(null);
                    }
                }
                catch (EvaluateException)
                {
                    //TODO: Add error hadnling
                    return(null);
                }
            }
        }
Beispiel #6
0
        public static async Task <List <SongBundle> > GetSearchResults(string query)
        {
            string results = await HttpRequests.GetRequest(GeniusSearchUrl + Uri.EscapeUriString(query), GeniusAuthHeader);

            JObject parsed = JObject.Parse(results);

            IList <JToken> parsedList = parsed["response"]?["hits"]?.Children().ToList();

            List <SongBundle> resultsList = new List <SongBundle>();

            if (parsedList != null && parsedList.Count != 0)
            {
                foreach (JToken result in parsedList)
                {
                    Song song = new Song
                    {
                        Id      = (int)result["result"]?["id"],
                        Title   = (string)result["result"]?["title"],
                        Artist  = (string)result["result"]?["primary_artist"]?["name"],
                        Cover   = (string)result["result"]?["song_art_image_thumbnail_url"],
                        Header  = (string)result["result"]?["header_image_url"],
                        ApiPath = (string)result["result"]?["api_path"],
                        Path    = (string)result["result"]?["path"]
                    };

                    RomanizedSong rSong = new RomanizedSong();
                    if (Prefs.GetBoolean("romanize_search", false))
                    {
                        rSong = await JapaneseTools.RomanizeSong(song, false);
                    }

                    resultsList.Add(new SongBundle(song, rSong));
                }

                return(resultsList);
            }

            resultsList = new List <SongBundle>();
            return(resultsList);
        }
Beispiel #7
0
        public static async Task <SongBundle> GetSongDetails(SongBundle song)
        {
            Log(Logging.Type.Info, "Starting GetSongDetails operation");
            string results = await HttpRequests.GetRequest(GeniusApiUrl + song.Normal.ApiPath, GeniusAuthHeader);

            JObject parsed = JObject.Parse(results);

            parsed = (JObject)parsed["response"]?["song"]; //Change root to song

            Song fromJson = new Song
            {
                Title   = (string)parsed?.SelectToken("title") ?? "",
                Artist  = (string)parsed?.SelectToken("primary_artist.name") ?? "",
                Album   = (string)parsed?.SelectToken("album.name") ?? "",
                Header  = (string)parsed?.SelectToken("header_image_url") ?? "",
                Cover   = (string)parsed?.SelectToken("song_art_image_url") ?? "",
                ApiPath = (string)parsed?.SelectToken("api_path") ?? "",
                Path    = (string)parsed?.SelectToken("path") ?? ""
            };

            song.Normal = fromJson;

            if (parsed != null && parsed["featured_artists"].HasValues)
            {
                IList <JToken> parsedList = parsed["featured_artists"].Children().ToList();

                song.Normal.FeaturedArtist = "feat. ";
                foreach (JToken artist in parsedList)
                {
                    if (song.Normal.FeaturedArtist == "feat. ")
                    {
                        song.Normal.FeaturedArtist += artist["name"]?.ToString();
                    }
                    else
                    {
                        song.Normal.FeaturedArtist += ", " + artist["name"];
                    }
                }

                Log(Logging.Type.Processing, "Added featured artists to song");
            }
            else
            {
                song.Normal.FeaturedArtist = "";
            }

            //Execute all Japanese transliteration tasks at once
            if (Prefs.GetBoolean("auto_romanize_details", true) && song.Normal.Title.ContainsJapanese() || song.Normal.Artist.ContainsJapanese() || song.Normal.Album.ContainsJapanese())
            {
                Task <string> awaitTitle  = song.Normal.Title.StripJapanese();
                Task <string> awaitArtist = song.Normal.Artist.StripJapanese();
                Task <string> awaitAlbum  = song.Normal.Album.StripJapanese();

                await Task.WhenAll(awaitTitle, awaitArtist, awaitAlbum);

                RomanizedSong romanized = new RomanizedSong();
                // This snippet is the same in GetAndShowLyrics
                song.Romanized ??= romanized;

                romanized.Title  = await awaitTitle;
                romanized.Artist = await awaitArtist;
                romanized.Album  = await awaitAlbum;

                romanized.Id          = song.Normal.Id;
                song.Romanized        = romanized;
                song.Normal.Romanized = true;

                Log(Logging.Type.Event, "Romanized song info with ID " + song.Normal.Id);
                Analytics.TrackEvent("Romanized song info", new Dictionary <string, string> {
                    { "SongID", song.Normal.Id.ToString() }
                });
            }
            else
            {
                song.Romanized = null;
            }

            return(song);
        }
Beispiel #8
0
        private async Task ShowLyrics()
        {
            Log(Type.Info, "Started ShowLyrics method");

            #region UI Variables
            TextView           infoTxt            = FindViewById <TextView>(Resource.Id.infoTxt);
            ProgressBar        lyricsLoadingWheel = FindViewById <ProgressBar>(Resource.Id.lyricsLoadingWheel);
            SwipeRefreshLayout refreshLayout      = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);
            ImageView          savedView          = FindViewById <ImageView>(Resource.Id.savedView);
            ImageButton        fabMore            = FindViewById <ImageButton>(Resource.Id.fabMore);
            #endregion

            string lyrics = await Genius.GetSongLyrics(songInfo);

            songInfo.Normal.Lyrics = lyrics;

            //TODO: Make auto-romanization happen after loading normal version of song
            //Auto-romanize based on preferences
            if (songInfo.Normal.Lyrics.ContainsJapanese() && Prefs.GetBoolean("auto_romanize", false))
            {
                RomanizedSong romanized = await JapaneseTools.RomanizeSong(songInfo.Normal, true);

                //Fill empty info for songs with romanized lyrics and non-romanized details
                if (string.IsNullOrEmpty(romanized.Title) &&
                    !string.IsNullOrEmpty(songInfo.Normal.Title))
                {
                    romanized.Title = songInfo.Normal.Title;
                }
                if (string.IsNullOrEmpty(romanized.Artist) &&
                    !string.IsNullOrEmpty(songInfo.Normal.Artist))
                {
                    romanized.Artist = songInfo.Normal.Artist;
                }
                if (string.IsNullOrEmpty(romanized.Album) &&
                    !string.IsNullOrEmpty(songInfo.Normal.Album))
                {
                    romanized.Album = songInfo.Normal.Album;
                }
                if (string.IsNullOrEmpty(romanized.FeaturedArtist) &&
                    !string.IsNullOrEmpty(songInfo.Normal.FeaturedArtist))
                {
                    romanized.FeaturedArtist = songInfo.Normal.FeaturedArtist;
                }

                songInfo.Romanized        = romanized;
                songInfo.Normal.Romanized = true;
            }
            else
            {
                if (songInfo.Romanized != null)
                {
                    songInfo.Romanized.Lyrics = "";
                }
            }

            UpdateSong(songInfo, false, false);
            RunOnUiThread(() =>
            {
                fabMore.Visibility   = ViewStates.Visible;
                savedView.Visibility = ViewStates.Gone;
                infoTxt.Visibility   = ViewStates.Visible;

                lyricsLoadingWheel.Visibility = ViewStates.Gone;
                refreshLayout.Refreshing      = false;
            });

            shouldCheck = true;

            Log(Type.Info, "Finished getting lyrics from Genius");
            Analytics.TrackEvent("Finished getting lyrics from Genius", new Dictionary <string, string> {
                { "SongID", songInfo.Normal.Id.ToString() }
            });
        }