o
    {g"*                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 de
fdd	Zd
e
fddZde
defddZd
e
defddZdededefddZdd Zedkr^e  dS dS )    N)datetime)Path)time)Dict)ImageGlitcherreturnc                  C   s@   t td} |  }W d    | S 1 sw   Y  | S )Nr)openversion_filepathreadstrip)version_filecontent r   t/var/www/bot.gig.net.ua/public_html/telegram/P1/HellBot/venv/lib/python3.10/site-packages/glitch_this/commandline.pyread_version   s   

r   versionc                 C   s>   t td}|| d  W d    d S 1 sw   Y  d S )Nw
)r	   r
   write)r   r   r   r   r   write_version   s   "r   filepathc                 C   s(   t t| j}t  }|| jdkS )N   )r   fromtimestamposstatst_mtimenowdays)r   file_creationr   r   r   r   
is_expired   s   r    c                 C   s   ddl m} dd l}tjtrttst }nz	|	d
 }W n   Y dS ||}|d d }t| td|  d|  | |kS )	Nr   )requestz&https://pypi.org/pypi/glitch-this/jsonTinfor   zCurrent version: z | Latest version: )urllibr!   jsonr   pathisfiler
   r    r   urlopenr   loadsr   print)r   r!   r$   latest_versioncontentsdatar   r   r   	is_latest   s"   
r-   
glitch_min
glitch_maxc                 C   s   t  }d|d< d|  d| d|d< d|d< d	|d
< d|d< d|d< d|d< d|d< d|d< d|  d| d|d< d|d< d|d< d|d< d|d < d!|d"< d#|d$< |S )%Nz0Relative or Absolute string path to source imager%   zNumber between z and z/, inclusive, representing amount of glitchinesslevelz'Include if you want to add color offsetcolorz>Include if you want to add scan lines effect
Defaults to Falsescanz;Set a random seed for generating similar images across runsseedz&Include if you want output to be a GIFgifz7Number of frames to include in output GIF, default - 23frameszCGlitch every step'th frame of output GIF, default - 1 (every frame)stepzPIncrement glitch_amount by given value after glitching every frame of output GIF	incrementz2Include if glitch_amount should be cycled back to z or z if it over/underflowscyclez?How long to display each frame (in centiseconds), default - 200durationzNMultiply given value to input GIF's original duration and use that as durationrelative_durationzHHow many times the glitched GIF should loop, default - 0 (infinite loop)loopzInclude if input image is GIFinputgifz Forcefully overwrite output fileforcez2Explcitly supply full/relative path to output fileout)dict)r.   r/   	help_textr   r   r   get_help6   s$   rA   c                  C   s  d\} }t j}t| |}tjd| dtjd}|jddd| d |jd	d
t|d d |jddt|d d |jdddd|d d |jdddd|d d |jdddd|d d |jdddd|d d |jd d!d"d|d" d |jd#d$d%d&td |d% d' |jd(d)d*d+t	d,|d* d' |jd-d.d/d0t	d1|d/ d' |jd2d3d4d5td6|d4 d' |jd7d8d9d|d9 d |jd:d;d<d=t	d>|d< d' |jd?d@dAdBt|dC dD |jdEdFdGdHt	dI|dG d' |jdJdKdLdMt|dN dD |
 }|jdIkstdO|jdIkstdP|jdIkstdQtj|jstdRtjt|j\}}|dSd1\}}	dT| }|jr9dn|	}	|jrftjt|j\}}|dUkr^tj|s^tdV| dW |dSd1dI }tj|| dS|	 }
tj|
r|jst|
dX t  }tj|jdYat }|j s|j!|j|j"|j#|j$|j%|j&|j'|j|j|j(dZ
}n+|j)|j|j"|j#|j$|j%|j&|j'|j(d[\}}|_d\|_|j*s|jnt	|j*| |_t }t }|js|j+|
d]d^ t }t,d_-|
 n*|dI j+|
d`|d1d  d\|j|jd]da t }t,db|
 dc|j dd|j de|j  t,df||   t,dg||   t,dh||   t.|sFt,di d S d S )jN)g?g      $@zglitch_this: Glitchify images and GIFs, with highly customizable options!

* Website: https://github.com/TotallyNotChase/glitch-this 
* Version: zU
* Changelog: https://github.com/TotallyNotChase/glitch-this/blob/master/CHANGELOG.md)descriptionformatter_classz	--versionr   zglitch_this )actionr   src_img_path
Image_Pathr%   )metavartypehelpglitch_levelGlitch_Levelr0   z-cz--colorr1   
store_true)destrD   rI   z-sz--scan
scan_linesr2   z-gz--gifr4   z-igz
--inputgif	input_gifr<   z-fz--forcer=   z-sdz--seedr3   Seed)rM   rG   rH   defaultrI   z-frz--framesr5   Frames   z-stz--stepr6   Step   z-iz--incrementr7   	Incrementg        z-cyz--cycler8   z-dz
--durationr9   Duration   z-rdz--relative_durationrel_durationRelative_Durationr:   )rM   rG   rH   rI   z-lz--loopr;   
Loop_Countr   z-oz	--outfileoutfileOutfile_pathr>   zDuration must be greater than 0z'Loop must be greater than or equal to 0zFrames must be greater than 0zNo image found at given path.	glitched_ zGiven outfile path, z, does not existz_ already exists
Cannot overwrite existing file unless -f or --force is included
Program Abortedzversion.info)glitch_changer8   rN   color_offsetr3   r4   r5   r6   )ra   r8   rN   rb   r3   r6   T   )compress_levelzGlitched Image saved in "{}"GIF)formatappend_imagessave_allr9   r;   rd   zGlitched GIF saved in "z"
Frames = z, Duration = z	, Loop = zTime taken to glitch: zTime taken to save: zTotal Time taken: zoA new version of "glitch-this" is available. Please consider upgrading via `pip3 install --upgrade glitch-this`)/r   __version__rA   argparseArgumentParserRawTextHelpFormatteradd_argumentstrfloatint
parse_argsr9   
ValueErrorr;   r5   r   r%   r&   rE   FileNotFoundErrorsplitr   rsplitr4   r\   exists	Exceptionjoinr=   lib_pathr
   r   rO   glitch_imagerJ   r7   r8   rN   r1   r3   r6   
glitch_gifrY   saver)   rf   r-   )r.   r/   current_versionr@   	argparserargsout_pathout_fileout_filename
out_fileex	full_pathglitchert0
glitch_imgsrc_durationt1t2t3r   r   r   mainK   s  





 
r   __main__)rj   r   r   pathlibr   r   typingr   glitch_thisr   rn   r   r   boolr    r-   ro   rA   r   __name__r   r   r   r   <module>   s"    
