
    @};d/                     B    d dl Z d dlZd dlZd dlZdZdZ G d de      Zy)    Ng      ?c                   D    e Zd ZdZd Zd Zd Z G d de      Zd Z	d Z
y	)
DarkLyricsParserz)Parser for Lyrics from www.darklyrics.comc                 <    || _         || _        d| _        d| _        y )N )artisttitleartist_asciititlenumber)selfr   r   s      F/usr/lib/x86_64-linux-gnu/rhythmbox/plugins/lyrics/DarkLyricsParser.py__init__zDarkLyricsParser.__init__'   s     $+$*$$    c                 6   dj                  d | j                  j                         D              | _        | j                  j                         | _        d| j                  d   z  }t	        j
                         } |j                  || j                  |g|  y)zCDo a request of a specific url based on artist's first letter name.r   c              3   D   K   | ]  }|t         j                  v r|  y wN)stringascii_letters).0cs     r   	<genexpr>z*DarkLyricsParser.search.<locals>.<genexpr>0   s%      (A&&&&   (s    z!http://www.darklyrics.com/%s.htmlr   N)joinr   lowerr	   rbLoaderget_urlsearch_artist)r   callbackdatafirstcharurlloaders        r   searchzDarkLyricsParser.search-   s     gg ():):)< ( ($''--/$48I8I!8LM,99;&&.., 2 2HDtDr   c                    |
 |dg|  y|j                  d      }t        j                  d|d      d   }d}d}t        j                  ||j                               }|j	                  d       d}d}	|D ]  }
t        j
                  ||
      }t        |      dk(  r(|d   \  }}d	|z  }|dd
 dk(  r>|j                         }t        j                  || j                        }|t        kD  sx||	kD  s~|||f}|}	 |s
 |dg|  yt        j                         }|d   | _         |j                  |d   | j                   |g|  y)z<Search for the link to the page of artist in artists_page
		N
iso-8859-1ztban.js   z	<a href="z([^"]*)">*([^<]*)<r    zhttp://www.darklyrics.com/%s   zhttp:   )decoderesplitr   popfindalllenstripstringmatchstring_matchr	   min_artist_matchr   r   r   r   search_song)r   artist_pager   r   link_sectionpattern_linkpattern_artistlinks
best_matchsmvalue_bestmatchliner   artist_linkartist_name
artist_urlsmvaluer    s                    r   r   zDarkLyricsParser.search_artist7   sf    TD	""<0+9k15a8,,'.
((L,"4"4"6
7%))A,*  dJJ~t,6	&kQ$Qi;.+>:"1o ""$;%%{D4E4EF7  W/@%@:{3J  
TD	99<&A$+&..*Q-!1!18CdCr   c                       e Zd Zd Zd Zy)DarkLyricsParser.SongFoundc                 J    || _         || _        || _        || _        || _        y r   )r>   r   numberalbumr   )r   r>   r   rB   rC   r   s         r   r   z#DarkLyricsParser.SongFound.__init__\   s%    4<4:4;4:4;r   c                     dt        | j                        z   dz   | j                  z   dz   | j                  z   dz   | j                  z   dz   S )N(. ))strr>   r   rC   r   )r   s    r   __str__z"DarkLyricsParser.SongFound.__str__c   sI    
DLL!
!D
(4::
5
<tzz
ID
PSWS^S^
^ad
ddr   N)__name__
__module____qualname__r   rI   r%   r   r   	SongFoundr@   [   s    er   rM   c                    |
 |dg|  y|j                  d      }t        j                  d|      d   }|j                         }d}t        j                  |j                         |      }d}|D ]  }|\  }	}
}}t        j                  |j                         j                  dd      | j                  j                         j                  dd            }|t        kD  sp| j                  ||||
|	      } n |s
 |dg|  yt        j                         }d|j                  d	|j                  d
}|j                  | _        |j                  | _         |j"                  || j$                  |g|  y)zIf artist's page is found, search_song looks for the song.

		The artist page contains a list of all the albums and
		links to the songs lyrics from this.
		Nr#   zLYRICS</h1>r$   z3<a href="../lyrics/(.*)/(.*).html#([^"]+)">(.*)</a>r    z!http://www.darklyrics.com/lyrics//z.html)r(   r)   r*   r   r,   r/   r0   replacer   min_song_matchrM   r   r   r   rC   rB   r
   r   parse_lyrics)r   songlistr   r   r4   pattern_songmatchesr8   r:   r   rC   rB   r   r>   r    urls                   r   r2   zDarkLyricsParser.search_songf   sf    TD	__\*( -215,##%,F,JJ**,l;'* 

d"&65&%%%u{{}'<'<S"'F

""3+-7..	J
 


 
TD	99<&9C9J9JJL\L\]#$*&&$&..#t(((:T:r   c           	      ~   |
 |dg|  y|j                  d      }d| j                  d| j                  dt        j                  | j                  j	                               d}t        j
                  ||      }t        |      dkD  r|d   }|j                  d      d	   }|j                  d
d      }t        j                  dd|      }|j                  d      }| j                  j	                         d| j                  j	                         d}|t        |      z   }|dz  } ||g|  y |dg|  y)zIn the album's page parse_lyrics get the lyrics of the song.

		This page contains all the lyrics for self.album, but
		this method get rides of everything that isn't the
		lyrics of self.titleNr#   z	<a name="z">rF   z	(.*?)</a>r'   z<h3>r   r   z<.*?>
z - z

z 

Lyrics provided by Dark Lyrics)r(   r
   r)   escaper   r*   r-   rQ   subr.   r   rH   )r   rC   r   r   	titleline
lyricmatchlyricsr   s           r   rS   zDarkLyricsParser.parse_lyrics   s    ]TD	
,,|
$%))299TZZ5E5E5G+HJ)xxE***qM6LL #6NND"%6FFHb&)6LL$6 KK--/1A1A1CD5CL 6	116VdTD	r   N)rJ   rK   rL   __doc__r   r!   r   objectrM   r2   rS   r%   r   r   r   r   #   s0    0E"DH	e& 	e&;P
r   r   )r)   r   r   r/   r1   rR   ra   r   r%   r   r   <module>rb      s,   6 
  	  E
 E
r   