Config setup - xIceArcher/lyricsheets GitHub Wiki
config.json
Setting up The config.json
file is crucial for lyricsheets
as it tells the script how to authenticate with Google Sheets and where to find your song databases. By default, populate_songs.py
looks for this file in the same directory (./config.json
), but you can specify a different path using the --config
command-line argument.
The file has the following main sections:
{
"google_credentials": { ... },
"spreadsheets": { ... },
"default": "..."
}
Let's break down each section:
google_credentials
1. This section contains the authentication details needed to access your Google Sheets via the Google API. You need to use a Google Cloud Service Account for this.
How to get Google Credentials:
- Google Cloud Console: Go to the Google Cloud Console.
- Project: Create a new project or select an existing one.
- Enable APIs: Navigate to "APIs & Services" > "Library". Search for "Google Sheets API" and enable it for your project.
- Create Service Account: Go to "APIs & Services" > "Credentials".
- Click "Create Credentials" > "Service account".
- Give your service account a name (e.g., "lyricsheets-reader").
- Grant necessary roles (optional, but "Viewer" might be sufficient if the script only reads). Click "Continue" and "Done".
- Generate Key: Find the service account you just created in the list.
- Click on its email address.
- Go to the "KEYS" tab.
- Click "ADD KEY" > "Create new key".
- Select "JSON" as the key type and click "CREATE".
- A JSON file containing your credentials will be downloaded. Keep this file secure!
- Share Google Sheets: Open the Google Sheet(s) you want the script to access.
- Click the "Share" button.
- Copy the
client_email
address from the downloaded JSON file (it looks likeyour-service-account-name@your-project-id.iam.gserviceaccount.com
). - Paste this email address into the "Share" dialog and grant it Editor access (required for reading and writing/updating data). Click "Send" or "Share".
config.json
:
Using the Credentials in - Open the downloaded JSON key file.
- Copy its entire content.
- Paste this content as the value for the
"google_credentials"
key in yourconfig.json
.
Example Structure (Values will differ):
"google_credentials": {
"type": "service_account",
"project_id": "your-gcp-project-id",
"private_key_id": "your_private_key_id",
"private_key": "-----BEGIN PRIVATE KEY-----\nYOUR_VERY_LONG_PRIVATE_KEY\n-----END PRIVATE KEY-----\n",
"client_email": "your-service-account-name@your-project-id.iam.gserviceaccount.com",
"client_id": "your_client_id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/your-service-account-email"
},
spreadsheets
2. This section maps friendly group names (like different idol groups or categories) to their specific Google Sheet IDs. The script uses this mapping to find the correct spreadsheet when looking up a song.
Structure:
- It's a JSON object (key-value pairs).
- Keys: User-defined strings representing the group or category (e.g.,
"niji"
,"aqours"
,"my_songs"
). These names are used internally by the script (e.g., for caching, potentially for future group-specific logic). - Values: The Spreadsheet ID for the corresponding Google Sheet.
How to find the Spreadsheet ID:
- Open your Google Sheet in the browser.
- Look at the URL in the address bar. It will look like:
https://docs.google.com/spreadsheets/d/THIS_IS_THE_SPREADSHEET_ID/edit
- Copy the long alphanumeric string between
/d/
and/edit
.
"spreadsheets": {
"liella": "12345678901093012803124139827498340180901981",
"niji": "104972107301270910jd0912jd90fusdagasfasdsajf",
"muse": "iageiuahr9e8wafhjeaw9fuejwaufjagdw8iayfhdas8",
"aqours": "hifasohfdiasfh01fioh10fi309-fudasufj9asdaffda"
},
default
This specifies the default group to use. The script (SongServiceByDB
in lyricsheets/service/db.py
) uses this:
- When initially building its internal map of all songs across all sheets.
- When fetching format tags if no specific group is provided (
get_format_tags
). - As a fallback spreadsheet ID if needed.
Value:
- A string that must exactly match one of the keys you defined in the spreadsheets section. Example:
"default": "niji"
In this case, if the script needs a default, it will use the spreadsheet ID associated with the "niji"
key in the spreadsheets object (104972107301270910jd0912jd90fusdagasfasdsajf
).
config.json
Complete Example {
"google_credentials": {
"type": "service_account",
"project_id": "your-gcp-project-id",
"private_key_id": "your_private_key_id",
"private_key": "-----BEGIN PRIVATE KEY-----\nYOUR_VERY_LONG_PRIVATE_KEY\n-----END PRIVATE KEY-----\n",
"client_email": "your-service-account-name@your-project-id.iam.gserviceaccount.com",
"client_id": "your_client_id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/your-service-account-email"
},
"spreadsheets": {
"liella": "12345678901093012803124139827498340180901981",
"niji": "104972107301270910jd0912jd90fusdagasfasdsajf",
"muse": "iageiuahr9e8wafhjeaw9fuejwaufjagdw8iayfhdas8",
"aqours": "hifasohfdiasfh01fioh10fi309-fudasufj9asdaffda"
},
"default": "niji"
}