from raven import Client
import os
from app.core.celery_app import celery_app
from app.core.config import settings
import requests
from pathlib import Path
from urllib.parse import urlparse, urljoin
import os
#client_sentry = Client(settings.SENTRY_DSN)

download_to_local_url = urljoin(settings.SERVER_HOST, settings.API_V1_STR+"/videos/worker")
upload_to_server_url = urljoin(settings.SERVER_HOST, settings.API_V1_STR+"/videos/worker")

ZIP_STORAGE = Path("/").joinpath(settings.LOCAL_ZIP_STORAGE) 
VIDEO_STORAGE = Path("/").joinpath(settings.CELERY_VIDEO_STORAGE)



@celery_app.task(acks_late=True)
def make_video(video_id, zip_filename, user_id) -> str:
    #video_id, zip_filename, user_id = args
    # download 
    '''
    r = requests.get(download_to_local_url, stream=True)
    with open(str(VIDEO_STORAGE/zip_filename), 'wb') as f:
        r.raise_for_status()
        for chunk in r.iter_content(chunk_size=1024):
            f.write(chunk)
    '''
    zip_filename = zip_filename + ".zip"
    print(str(ZIP_STORAGE/zip_filename))
    print((ZIP_STORAGE/zip_filename).exists())
    # make video


    
    return "complete"


