#!python

from gpymusic import common

import os
import pkgutil


# Import default config files.
gpymusic_config = str(
    pkgutil.get_data('gpymusic', os.path.join('config', 'config.json')),
    'utf-8',
)
mpv_config = str(
    pkgutil.get_data('gpymusic', os.path.join('config', 'mpv_input.conf')),
    'utf-8',
)

# Create directories if they don't exist.
if not os.path.exists(common.CONFIG_DIR):
    print('Config directory not found. Creating one...')
    os.makedirs(common.CONFIG_DIR)
else:
    print('Config directory already exists, not overwriting.')

if not os.path.exists(common.DATA_DIR):
    print('Data directory not found. Creating one...')
    os.makedirs(os.path.join(common.DATA_DIR, 'songs'))
    os.makedirs(os.path.join(common.DATA_DIR, 'playlists'))
else:
    print('Data directory already exists, not overwriting.')

# Write the config files if they don't already exist.
if not os.path.isfile(os.path.join(common.CONFIG_DIR, 'config.json')):
    print('Writing gpymusic config file...')
    with open(os.path.join(common.CONFIG_DIR, 'config.json'), 'w') as f:
        f.write(gpymusic_config)
else:
    print('gpymusic config file already exists, not overwriting.')

if not os.path.isfile(os.path.join(common.CONFIG_DIR, 'mpv_input.conf')):
    print('Writing mpv config file...')
    with open(os.path.join(common.CONFIG_DIR, 'mpv_input.conf'), 'w') as f:
        f.write(mpv_config)
else:
    print('mpv config file already exists, not overwriting.')

print('Done.')
