> For the complete documentation index, see [llms.txt](https://codingmace.gitbook.io/masterward/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codingmace.gitbook.io/masterward/software/work-in-progress/bsaber-ai.md).

# Bsaber AI

## Origin

So I know the community has made a lot of songs that go here, but I couldn't find NF and the only one on it was so hard. I was like maybe more people would play it if they could just put in any song and it would generate the songs. Also there was missing on Easy and some were only expert and by my opinion, not expert at all. I believe VR has capability as it is escaping reality, but we can only do that if there is a lot or appeals to more categories.

## Overview

The objective is to have a model that takes the input of a audio file and output a full map.&#x20;

## Step 1 - Downloading Data

We need to first grab all the data from the api

<pre class="language-python"><code class="lang-python">import requests
import json

before = "2024-01-28T00%3A00%3A01%2B00%3A00"
continuing = True
while continuing:
    url = "https://api.beatsaver.com/maps/latest?automapper=false&#x26;before=" + before + "&#x26;pageSize=100"
    headers = {
        'Accept': 'application/json',
        'Accept-Charset': 'utf-8'
        }
    response = requests.get(url, headers)
    obj = response.content

    obj1 = json.loads(obj)
    maps = obj1['docs']
    for i in range(0, len(maps)):
        curMap = maps[i]
        map_id = curMap['id']
        metadata = curMap['metadata'] # Derminating
        stats = curMap['stats'] # Determine based on that
        uploadTime = curMap['uploaded'] # Used for next Setting it
        versions = curMap['versions'] # Data needed to keep
        if stats['upvotes'] > 10 and metadata['duration'] > 80:
            print(map_id, stats['upvotes'], stats['downvotes'], metadata['duration'])
            # Extract relevant fields
            map_data = {
                "id": curMap["id"],
                "metadata": curMap["metadata"],
                "stats": curMap["stats"],
                "uploaded": curMap["uploaded"],
                "versions": curMap["versions"]
            }

            # Write the extracted data to a JSON file
            output_file_name = map_id + ".json"
            with open(output_file_name, 'w') as json_file:
                json.dump(map_data, json_file, indent=4)

            print("Data written to", output_file_name)
<strong>#                        con += 1
</strong>
    continuing = len(maps) > 2
    before = uploadTime
print("Finished on " , before)
</code></pre>

So once this downloads all the json files it came up to around 50k json files. I then had to narrow it down and download what is necessary inforamtion. I choose parameters that left it to be around 10k for my dataset.

```python
import json
import os
import requests

def downloadZip(url,id):
    output = "./downloads/" + str(id) + ".zip"
    r = requests.get(url)
    with open(output, 'wb') as f:
        f.write(r.content)

def compare_ignore_case(str1, str2):
    return str1.casefold() == str2.casefold()

def loads(filename):
    with open(filename) as file:
        data = json.load(file)
        # Print the data
        upvotes = data['stats']['upvotes']
        downvotes = data['stats']['downvotes']
        duration = data['metadata']['duration']
        per = (upvotes / (downvotes + upvotes)) * 100
        evenbpm = int(data['metadata']['bpm']) == data['metadata']['bpm']
        difficulties = [False,False,False,False,False]
        difficult = [False,False,False,False,True]
        sets = data['versions'][0]['diffs']
        for s in sets:
            if compare_ignore_case(s['difficulty'], 'easy'):
                difficulties[0] = True
            if compare_ignore_case(s['difficulty'], 'normal'):
                difficulties[1] = True
            if compare_ignore_case(s['difficulty'], 'hard'):
                difficulties[2] = True
            if compare_ignore_case(s['difficulty'], 'expert'):
                difficulties[3] = True
            if compare_ignore_case(s['difficulty'], 'expertplus'):
                difficulties[4] = True
        onlyExpertPlus = difficulties == difficult
        if upvotes > 100 and per > 80 and evenbpm and not onlyExpertPlus and duration < 250:
            dURL = data['versions'][0]['downloadURL']
            downloadZip(dURL, data['id'])
            return "True"
        return "False"

path = "."
file_list = os.listdir(path)
f = open('out.txt', 'w')
con = 0
for l in file_list:
    try:
        ans = loads(l)
        if ans == "True":
            con += 1
    except:
        print("Ran into issue on file" + l)
print('Downloaded ' + str(con) + ' Songs')

```

## Step 2 - Cleaning Data

I then created a short script to remove files that weren't going to be useful.

```python
import os

# Function to delete image and video files
def delete_media_files(folder):
    for root, dirs, files in os.walk(folder):
        for file in files:
            file_path = os.path.join(root, file)
            # Check if the file is an image or video file
            if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp',
                                       '.tiff', '.svg', '.webp', '.ico',
                                       '.mp4', '.avi', '.mkv', '.mov', '.wmv', '.flv')):
                try:
                    os.remove(file_path)
                    print(f"Deleted: {file_path}")
                except Exception as e:
                    print(f"Error deleting {file_path}: {e}")

# Specify the directory to start traversing from
folder_to_search = input("Enter the directory path to start traversing from: ")

# Check if the specified directory exists
if os.path.exists(folder_to_search):
    # Confirm with the user before proceeding
    confirmation = input(f"Are you sure you want to delete all image and video files in {folder_to_search}? (yes/no): ")
    if confirmation.lower() == "yes":
        delete_media_files(folder_to_search)
        print("Operation completed.")
    else:
        print("Operation aborted by user.")
else:
    print("Directory not found.")
```

### Notable Links

Created by [nick sypteras](https://www.nicksypteras.com/blog/aisu.html?msclkid=526f29b3b04311ecbf6ceb8434261934) in October 2017 was an OSU generator which is close to beatsaber in a way. It has clicking in a 2d field based on music so that could really help along the process.

Another [OSU mapper](https://github.com/kotritrona/osumapper?msclkid=526f9d92b04311ec8068537a2023196e) that is on github written by kotritrona using tensorflow and deep learning hasn't been updated for 2 years so I assume it is the final product on version 7.0\
Another one is the actual project after dance dance revolution game called [Dance Dance Convolution](https://arxiv.org/pdf/1703.06891.pdf). The idea has been proven to work and it has the same principle as 2 entities only issue is deciding in a 9 grid instead of 4 expanding the amount of combinations and patterns exponentially.

Useful website for verification of this [wiki webpage](https://bsmg.wiki/mapping/map-format.html) that is highly liked in the community.

Two music analysis websites, [beat tracking](https://www.analyticsvidhya.com/blog/2018/02/audio-beat-tracking-for-music-information-retrieval/) and 2016 writting [for music analysis](https://cilvr.cs.nyu.edu/lib/exe/fetch.php?media=deeplearning:2016:mcfee_dl-for-music.pdf).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://codingmace.gitbook.io/masterward/software/work-in-progress/bsaber-ai.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
