
    g                     8   d dl Z d dlmZ d dlZd dlZddZd Zedk    r e j        d          Z	e	
                    d	ed
           e	
                    ddedd           e	
                    ddd           e	                                Z eej        ej                  Zera ed ee           dej         d           ej        rd eD             ZeD ]Z ee           n ee            ej        d            dS  ej        d           dS dS )    N)
ColorThief   c                    t           j                            |           s!t          d|  dt          j                   dS t           j                            |           s!t          d|  dt          j                   dS 	 t          |           }|                    |          }|S # t          $ r,}t          d|  d	| t          j                   Y d}~dS d}~ww xY w)
al  
    Extracts a specified number of colors from an image using ColorThief.

    Args:
        image_path (str): The path to the image file.
        num_colors (int): The number of colors to extract in the palette.

    Returns:
        list: A list of RGB tuples representing the color palette,
              or None if the file is invalid or an error occurs.
    z Error: Image file not found at '')fileNzError: Path 'z' is not a file.)color_countzError processing image 'z': )
ospathexistsprintsysstderrisfiler   get_palette	Exception)
image_path
num_colorscolor_thiefpalettees        3/Users/srajan/code/music-website/extract_palette.pyextract_colorsr      s     7>>*%% >>>>SZPPPPt7>>*%% 	;z;;;#*	M	M	M	M ,,))j)AA   ;;;;;#*MMMMttttts   &B) )
C3!CCc                 T    d                     | d         | d         | d                   S )z,Converts an RGB tuple to a hex color string.z#{:02x}{:02x}{:02x}r         )format)rgbs    r   
rgb_to_hexr   "   s&     ''AAA???    __main__z0Extract a color palette from an album art image.)description
image_filez!Path to the album art image file.)typehelpz-nz--num_colors   z(Number of colors to extract (default: 6))r#   defaultr$   z--hex
store_truez2Output colors in hex format instead of RGB tuples.)actionr$   z
Extracted z colors from 'z':c                 ,    g | ]}t          |          S  )r   ).0colors     r   
<listcomp>r-   5   s     BBB:e,,BBBr   r   )r   )argparse
colorthiefr   r   r	   r   r   __name__ArgumentParserparseradd_argumentstrint
parse_argsargsr"   r   r   r   lenhexhex_paletter,   exitr*   r   r   <module>r<      s    ! ! ! ! ! ! 



 				   8@ @ @ z$X$1cdddF
35XYYY
n3G  I I I
Q  S S S DnT_do>>G 
J33w<<JJtJJJKKK8 	BB'BBBK$  e E'NNN- r   