"""
Django settings for crawler project.

Generated by 'django-admin startproject' using Django 3.0.5.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'oko5$gr_j5c$%%n(!&kwl#)=h=#%@lvag+#$szgc-3yj)lk1!x'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["*"]

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'apps.video_search'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'crawler.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'frontend')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'crawler.wsgi.application'

# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "frontend"),
]

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

VIMEO_ACCESS_TOKEN = '16d8f42440b981adaa5e58bae264643c'
VIMEO_CLIENT_ID = 'd46d2ffd7e4af7e4bfcee87bf4e1e999559f9221'
VIMEO_CLIENT_SECRET = '89imGWDO2fZ1KqZuJ54oQVNrIb5NH0SGLL4ii8mg4gMTgScphArtTaKA97NoQFvfU80lZlvk4nxWCgE1Kn/K+QzwfDpgKDbdz2xJhCmDamFL+acIJNlqdvnhbBpmib54'

YOUTUBE_API_DEVELOPER_KEY = 'AIzaSyA-yUD5PSS0UPopKSIGMa-CyR9YA8imQoo'
YOUTUBE_API_SERVICE_NAME = 'youtube'
YOUTUBE_API_VERSION = 'v3'

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

AWS_ACCESS_KEY_ID = 'AKIARRD6RJOYFJDDNEGK'
AWS_SECRET_ACCESS_KEY = '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'
AWS_STORAGE_BUCKET_NAME = 'recon-crawler-files'
AWS_DEFAULT_ACL = 'public-read'
AWS_QUERYSTRING_AUTH = False
AWS_REGION_NAME = 'us-east-2'

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10
}

# ---------------------AWS SQS------------------------
SQS_CRAWLER_DOWNLOAD_VIDEO_FILE_QUEUE = ''

from kombu.utils.url import safequote
safe_aws_access_key = safequote(AWS_ACCESS_KEY_ID)
safe_aws_secret_key = safequote(AWS_SECRET_ACCESS_KEY)

CELERY_BROKER_URL = f"sqs://{safe_aws_access_key}:{safe_aws_secret_key}@"
CELERY_BROKER_TRANSPORT_OPTIONS = {
    'region': AWS_REGION_NAME,
    'visibility_timeout': 3600,  # 1 hour
    'polling_interval': 10,  # 10 seconds
}

CELERY_TASK_DEFAULT_QUEUE = '' # override this

PROXIES = [
  #'http://192.168.88.245:30128',
]
SEARCH_VIMEO_AMOUNT = 50
SEARCH_YOUTUBE_AMOUNT = 50