Exemplo n.º 1
0
        public static ICollection <BeatmapCharacteristic> ConvertFrom(JToken jChars, string _songId)
        {
            var bcList = new List <BeatmapCharacteristic>();

            foreach (var jChar in jChars.Children())
            {
                //var newChar = Characteristic.GetOrAddCharacteristic(jChar["name"]?.Value<string>());
                var charName  = jChar["name"]?.Value <string>();
                var charDiffs = new List <CharacteristicDifficulty>();
                var newBChar  = new BeatmapCharacteristic()
                {
                    SongId = _songId, CharacteristicName = charName
                };
                foreach (JProperty diff in jChar["difficulties"].Children())
                {
                    if (string.IsNullOrEmpty(diff.First.ToString()))
                    {
                        continue;
                    }
                    var newCharDiff = CharacteristicDifficulty.ConvertFromJson(diff);
                    //newCharDiff.BeatmapCharacteristicId = newBChar.BeatmapCharacteristicId;
                    newCharDiff.BeatmapCharacteristic = newBChar;
                    charDiffs.Add(newCharDiff);
                }
                newBChar.CharacteristicDifficulties = charDiffs;
                bcList.Add(newBChar);
            }

            return(bcList);
        }
Exemplo n.º 2
0
        public CharacteristicDifficulty(DifficultyCharacteristic diff, string diffName, BeatmapCharacteristic bmChar)
        {
            Difficulty          = diffName;
            Duration            = diff.duration;
            Length              = diff.length;
            Bombs               = diff.bombs;
            Notes               = diff.notes;
            Obstacles           = diff.obstacles;
            NoteJumpSpeed       = diff.njs;
            NoteJumpSpeedOffset = diff.njsOffset;

            BeatmapCharacteristic = bmChar;
        }
Exemplo n.º 3
0
        public Song(BeatSaverSong s, IEnumerable <ScoreSaberDifficulty> scoreSaberDifficulties = null)
            : this()
        {
            SongId      = s._id;
            Key         = s.key.ToLower();
            Name        = s.name;
            Description = s.description;
            DeletedAt   = s.deletedAt;
            Hash        = s.hash.ToUpper();
            Uploaded    = s.uploaded;
            Converted   = s.converted;
            DownloadUrl = s.downloadURL;
            CoverUrl    = s.coverURL;

            SongName        = s.metadata.songName;
            SongSubName     = s.metadata.songSubName;
            SongAuthorName  = s.metadata.songAuthorName;
            LevelAuthorName = s.metadata.levelAuthorName;
            BeatsPerMinute  = s.metadata.bpm;

            Downloads = s.stats.downloads;
            Plays     = s.stats.plays;
            DownVotes = s.stats.downVotes;
            UpVotes   = s.stats.upVotes;
            Heat      = s.stats.heat;
            Rating    = s.stats.rating;

            ScrapedAt = s.ScrapedAt;

            //SongDifficulties = Difficulty.DictionaryToDifficulties(s.metadata.difficulties).
            //    Select(d => new SongDifficulty() { Difficulty = d, Song = this, SongId = s._id }).ToList();
            BeatmapCharacteristics = BeatmapCharacteristic.ConvertFrom(s.metadata.characteristics, this);
            UploaderRefId          = s.uploader.id;
            Uploader = new Uploader()
            {
                UploaderId = UploaderRefId, UploaderName = s.uploader.username
            };
            if (scoreSaberDifficulties != null)
            {
                ScoreSaberDifficulties = scoreSaberDifficulties.ToList();
            }
            else
            {
                ScoreSaberDifficulties = null; // new List<ScoreSaberDifficulty>();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new Song from a Beat Saver song JSON token.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown when the passed JToken doesn't contain the nested metadata, stats, or uploader objects.</exception>
        /// <param name="jSong"></param>
        public Song(JToken jSong)
        {
            JToken jMetadata        = jSong["metadata"];
            JToken jCharacteristics = jMetadata["characteristics"];
            JToken jStats           = jSong["stats"];
            JToken jUploader        = jSong["uploader"];

            if (jMetadata == null || jStats == null || jUploader == null)
            {
                var nullTokens = new string[] {
                    jMetadata == null ? "metadata" : string.Empty,
                    jStats == null ? "stats" : string.Empty,
                    jUploader == null ? "uploader" : string.Empty
                };
                throw new ArgumentException($"Unable to parse Song from jSong: {(string.Join(", ", nullTokens.Where(s => !string.IsNullOrEmpty(s))))} cannot be null.");
            }


            // Root
            SongId      = jSong["_id"]?.Value <string>();
            Key         = jSong["key"]?.Value <string>();
            Name        = jSong["name"]?.Value <string>();
            Description = jSong["description"]?.Value <string>();
            DeletedAt   = jSong["deletedAt"]?.Value <DateTime?>();
            Hash        = jSong["hash"]?.Value <string>().ToUpper();
            Uploaded    = jSong["uploaded"]?.Value <DateTime?>() ?? DateTime.MinValue;
            Converted   = jSong["converted"]?.Value <string>();
            DownloadUrl = jSong["downloadURL"]?.Value <string>();
            CoverUrl    = jSong["coverURL"]?.Value <string>();

            // Metadata
            //var characteristics = JsonConvert.DeserializeObject<List<string>>(jMetadata["characteristics"]?.ToString());// Change
            var diffs = JsonConvert.DeserializeObject <Dictionary <string, bool> >(jMetadata["difficulties"]?.ToString());

            //SongDifficulties = Difficulty.DictionaryToDifficulties(diffs)
            //        .Select(d => new SongDifficulty() { Difficulty = d, Song = this, SongId = SongId }).ToList();

            BeatmapCharacteristics = BeatmapCharacteristic.ConvertFrom(jCharacteristics, SongId);

            SongName        = jMetadata["songName"]?.Value <string>();
            SongSubName     = jMetadata["songSubName"]?.Value <string>();
            SongAuthorName  = jMetadata["songAuthorName"]?.Value <string>();
            LevelAuthorName = jMetadata["levelAuthorName"]?.Value <string>();
            BeatsPerMinute  = jMetadata["bpm"]?.Value <float>() ?? default(float);
            //Stats
            Downloads = jStats["downloads"]?.Value <int>() ?? 0;
            Plays     = jStats["plays"]?.Value <int>() ?? 0;
            DownVotes = jStats["downVotes"]?.Value <int>() ?? 0;
            UpVotes   = jStats["upVotes"]?.Value <int>() ?? 0;
            Heat      = jStats["heat"]?.Value <double>() ?? 0;
            Rating    = jStats["rating"]?.Value <double>() ?? 0;
            // Uploader
            UploaderRefId = jUploader["_id"]?.Value <string>().ToLower();
            Uploader      = new Uploader()
            {
                UploaderId = UploaderRefId, UploaderName = jUploader["username"]?.Value <string>()
            };

            ScrapedAt = jSong["ScrapedAt"]?.Value <DateTime>() ?? DateTime.MinValue;

            //ScoreSaberDifficulties = s.ScoreSaberInfo.Values.Select(d => new ScoreSaberDifficulty(d)).ToList(),
        }