Skip to content

Commit

Permalink
fix user agent for google lyrics parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jugran committed Mar 3, 2024
1 parent 1661dac commit 5497733
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lyrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

CONFIG_PATH = Path.home().joinpath('.config', 'lyrics-in-terminal','lyrics.cfg')

__version__ = '1.5.0'
__version__ = '1.5.1-dev'

if not CONFIG_PATH.exists():
from shutil import copy
Expand Down
12 changes: 7 additions & 5 deletions lyrics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


url = 'https://www.google.com/search?q='
HEADER = {'User-Agent': 'Mozilla/5.0'}
HEADER = {
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch'
}

CLASS_NAME = r'\w{5,7} \w{4,5} \w{5,7}' # dependent on User-Agent
EDITOR = os.environ.get('EDITOR', 'nano')
Expand All @@ -24,7 +26,7 @@ def query(track_name):
'''encodes search query
'''
track_name = re.sub(r'(\[.*\].*)|(\(.*\).*)', '', track_name).strip()
return quote( track_name + ' lyrics')
return quote(track_name + ' lyrics')


def get_html(url, header=HEADER):
Expand Down Expand Up @@ -97,7 +99,7 @@ def get_azlyrics(url):
def fetch_lyrics(url):
''' fetches sources from google, then azlyrics
checks if lyrics are valid
returns list of strings
if lyrics not found in both google & azlyrics
Expand Down Expand Up @@ -135,7 +137,8 @@ def fetch_lyrics(url):
def get_filename(track_name):
'''returns name of cache file name from track name with correct format
'''
filename = re.sub(r'(\[.*\].*)|(\(.*\).*)', '', track_name).strip() # removing text in brackets [] ()
# removing text in brackets [] ()
filename = re.sub(r'(\[.*\].*)|(\(.*\).*)', '', track_name).strip()
filename = re.sub(r'\s|\/|\\|\.', '', filename)
return os.path.join(CACHE_PATH, filename)

Expand Down Expand Up @@ -200,7 +203,6 @@ def edit_lyrics(track_name):
file.writelines(edited_lyrics)



def delete_lyrics(track_name):
''' deletes local lyrics cache file
returns -> bool | whether the delete operation occured or not
Expand Down

0 comments on commit 5497733

Please sign in to comment.