U
    dR                     @   s   d dl mZmZ d dlmZ d dlmZ ddlT d dlmZ d dl	m	Z	 d dl
mZ d d	lZdd
lmZ d d	lZd d	lZd d	lZd dlmZ ddlmZ dd Zdd Zdd Zdd Zdd Zdd Zd	S )    )renderredirectHttpResponse)models   )*)messages)datetime)VideoFileClipN)	FilesForm)Key)check_for_SRT_filec                 C   s   t dS )Nz	home.htmlr   request r   3/var/www/html/subscibe_interface/interface/views.pyhome   s    r   c                 C   s
   t | dS )Nregistration/login.html)r   r   r   r   r   login   s    r   c                 C   s   t  }| jd}| jd}td| td| ztjj|dj|d}W n, tjk
rz   t	
| d t| d Y S X |rd	| jd
< t|j| jd< t|dd |_|  t| dS t	
| d d S )Nusernamepasswordzthe username is :zthe password is :)r   )r   zSometing Wrong.r   yesZisloggedid_user.r   zregistration/upload.htmlzError detected.)r
   nowPOSTgetprintUsersobjectsfilterDoesNotExistr	   errorr   sessionstrr   split	last_timesave)r   r   r   r   datar   r   r   dologin   s"    



r*   c           	      C   sV   |}t |}|j}|dd }t }t|dd }t||||d}|  d S )Nr   r   )
video_pathduration	extensionwhen_uploaded)r   r-   r&   r
   r   r%   Filesr(   )	contentfilenamer,   Zclipr-   r.   r   r/   new_filer   r   r   	save_file.   s    r4   c              	   C   sN   t |d:}t| tkr(||   n|  D ]}|| q0W 5 Q R X d S )Nzwb+)opentyper%   writeencodechunks)filepathr2   destinationchunkr   r   r   handle_uploaded_fileB   s
    r>   c                 C   s   | j dkr| jd j}| jd }td| d}tj|sDt| t||| t	|| t
jjdddt
jj d}|d	}|}d}tj||}||}|| d
}	|dd }
tj|	 d|
 dgd}t| t| dS )Nr   r2   zthe file name is :/z	us-east-2ZAKIAT6THLFM7NTAL4XWXz(iGzTVrIAOLQNRes8HvUwZSq/8LBqaH3aanR+sxNS)Zaws_access_key_idZaws_secret_access_keyZcalling_formatzinput-transcribe-bucketesr   r   _z.srt)argszregistration/about.html)methodFILESnamer   osr;   existsmakedirsr>   r4   botos3Zconnect_to_region
connectionZOrdinaryCallingFormatZ
get_bucketjoinZnew_keyZset_contents_from_filenamer&   r   apply_asyncr   )r   r2   r1   r;   connbucketkey_nameZfull_key_nameklangZ	fileshortresultr   r   r   uploadO   s2    








rT   )Zdjango.shortcutsr   r   django.httpr   	django.dbr   django.contribr	   r
   Zmoviepy.editorr   rF   formsr   rI   Zboto.s3.connectionZboto.s3.keyr   tasksr   r   r   r*   r4   r>   rT   r   r   r   r   <module>   s&   