Compare commits

..

No commits in common. "80a7d2bde5af7d9185483f930078eec6eff42d39" and "4d83b238e4ffacd546022a1ec839b5cc7e52d419" have entirely different histories.

3 changed files with 8 additions and 32 deletions

View file

@ -1,8 +1,7 @@
import re import re
from lxml import html, etree # type: ignore from lxml import html, etree # type: ignore
import urllib3
import shared
# Matches not only latin symbols, # Matches not only latin symbols,
@ -16,11 +15,11 @@ lyrics_xpath = etree.XPath('//div[@id="lyrics-root"][1]/div[@data-lyrics-contain
br_xpath = etree.XPath('.//br') br_xpath = etree.XPath('.//br')
def search(title: str, artist: str) -> str: def search(http: urllib3.PoolManager, title: str, artist: str) -> str:
'''Searches for Genius lyrics using SearXNG + Yahoo and returns the first URL. '''Searches for Genius lyrics using SearXNG + Yahoo and returns the first URL.
Irrelevant texts should be picked manually''' Irrelevant texts should be picked manually'''
resp = shared.get_http_pool().request( resp = http.request(
'GET', 'GET',
'https://searx.dc09.ru/search', 'https://searx.dc09.ru/search',
fields={ fields={
@ -37,11 +36,11 @@ def search(title: str, artist: str) -> str:
return result['url'] return result['url']
def parse(url: str) -> str: def parse(http: urllib3.PoolManager, url: str) -> str:
'''Requests a lyrics page and parses with libxml2, '''Requests a lyrics page and parses with libxml2,
leaving only text and line breaks''' leaving only text and line breaks'''
resp = shared.get_http_pool().request('GET', url) resp = http.request('GET', url)
tree = html.document_fromstring(resp.data) tree = html.document_fromstring(resp.data)
divs = lyrics_xpath(tree) divs = lyrics_xpath(tree)
del resp, tree del resp, tree

View file

@ -1,8 +1,6 @@
from mutagen import mp3, id3 from mutagen import mp3, id3
from yt_dlp.postprocessor import PostProcessor from yt_dlp.postprocessor import PostProcessor
import genius
ENC_UTF8 = 3 ENC_UTF8 = 3
@ -46,26 +44,15 @@ class ID3TagsPP(PostProcessor):
file = mp3.MP3(information['filepath']) file = mp3.MP3(information['filepath'])
title = information['track'] file['TIT2'] = id3.TIT2(encoding=ENC_UTF8, text=information['track'])
artist = information['artist'] file['TPE1'] = id3.TPE1(encoding=ENC_UTF8, text=information['artist'])
file['TIT2'] = id3.TIT2(encoding=ENC_UTF8, text=title)
file['TPE1'] = id3.TPE1(encoding=ENC_UTF8, text=artist)
if 'album' in information: if 'album' in information:
file['TALB'] = id3.TALB(encoding=ENC_UTF8, text=information['album']) file['TALB'] = id3.TALB(encoding=ENC_UTF8, text=information['album'])
if 'release_year' in information: if 'release_year' in information:
file['TDRC'] = id3.TDRC(encoding=ENC_UTF8, text=str(information['release_year'])) file['TDRC'] = id3.TDRC(encoding=ENC_UTF8, text=str(information['release_year']))
if 'track_number' in information: if 'track_number' in information:
file['TRCK'] = id3.TRCK(encoding=ENC_UTF8, text=str(information['track_number'])) file['TRCK'] = id3.TRCK(encoding=ENC_UTF8, text=str(information['track_number']))
if 'genre' in information:
file['TCON'] = id3.TCON(encoding=ENC_UTF8, text=information['genre'])
try: # TODO: lyrics file["USLT"]
lyr_url = genius.search(title, artist)
file['USLT'] = id3.USLT(encoding=ENC_UTF8, text=genius.parse(lyr_url))
except:
pass
file.save()
return [], information return [], information

View file

@ -1,10 +0,0 @@
from urllib3 import PoolManager
_http: PoolManager | None = None
def get_http_pool() -> PoolManager:
global _http
if _http is None:
_http = PoolManager()
return _http