<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using ManagedBass;
using osu.Framework.Audio.Callbacks;
using osu.Game.Rulesets.Edit.Checks.Components;

namespace osu.Game.Rulesets.Edit.Checks
{
    public class CheckTooShortAudioFiles : ICheck
    {
        private const int ms_threshold = 25;
        private const int min_bytes_threshold = 100;

        private readonly string[] audioExtensions = { "mp3", "ogg", "wav" };

        public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Audio, "Too short audio files");

        public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
        {
            new IssueTemplateTooShort(this),
            new IssueTemplateBadFormat(this)
        };

        public IEnumerable<Issue> Run(BeatmapVerifierContext context)
        {
            var beatmapSet = context.Beatmap.BeatmapInfo.BeatmapSet;

            foreach (var file in beatmapSet.Files)
            {
                Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath);
                if (data == null)
                    continue;

                var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
                int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode, fileCallbacks.Callbacks, fileCallbacks.Handle);

                if (decodeStream == 0)
                {
                    // If the file is not likely to be properly parsed by Bass, we don't produce Error issues about it.
                    // Image files and audio files devoid of audio data both fail, for example, but neither would be issues in this check.
                    if (hasAudioExtension(file.Filename) && probablyHasAudioData(data))<commit_msg>Use `Prescan` flag for audio length check<commit_after>// Copyright (c) p<NAME> <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using ManagedBass;
using osu.Framework.Audio.Callbacks;
using osu.Game.Rulesets.Edit.Checks.Components;

namespace osu.Game.Rulesets.Edit.Checks
{
    public class CheckTooShortAudioFiles : ICheck
    {
        private const int ms_threshold = 25;
        private const int min_bytes_threshold = 100;

        private readonly string[] audioExtensions = { "mp3", "ogg", "wav" };

        public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Audio, "Too short audio files");

        public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
        {
            new IssueTemplateTooShort(this),
            new IssueTemplateBadFormat(this)
        };

        public IEnumerable<Issue> Run(BeatmapVerifierContext context)
        {
            var beatmapSet = context.Beatmap.BeatmapInfo.BeatmapSet;

            foreach (var file in beatmapSet.Files)
            {
                Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath);
                if (data == null)
                    continue;

                var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
                int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode | BassFlags.Prescan, fileCallbacks.Callbacks, fileCallbacks.Handle);

                if (decodeStream == 0)
                {
                    // If the file is not likely to be properly parsed by Bass, we don't produce Error issues about it.
                    // Image files and audio files devoid of audio data both fail, for example, but neither would be issues in this check.
                    if (hasAudioExtension(file.Filename) && probablyHasAudioData(data))
{'fraction_non_alphanumeric': 0.07889344262295082, 'fraction_numerical': 0.003586065573770492, 'mean_word_length': 2.55, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4820370', 'n_tokens_mistral': 1043, 'n_tokens_neox': 974, 'n_words': 310}