[common] fix google_search (close #2924)

This commit is contained in:
Mort Yao 2022-04-22 23:38:38 +02:00
parent 0d5562497f
commit 62013d034f
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -1807,20 +1807,10 @@ def google_search(url):
url = 'https://www.google.com/search?tbm=vid&q=%s' % parse.quote(keywords) url = 'https://www.google.com/search?tbm=vid&q=%s' % parse.quote(keywords)
page = get_content(url, headers=fake_headers) page = get_content(url, headers=fake_headers)
videos = re.findall( videos = re.findall(
r'<a href="(https?://[^"]+)" onmousedown="[^"]+"><h3 class="[^"]*">([^<]+)<', page r'(https://www\.youtube\.com/watch\?v=[\w-]+)', page
) )
vdurs = re.findall(r'<span class="vdur[^"]*">([^<]+)<', page)
durs = [r1(r'(\d+:\d+)', unescape_html(dur)) for dur in vdurs]
print('Google Videos search:')
for v in zip(videos, durs):
print('- video: {} [{}]'.format(
unescape_html(v[0][1]),
v[1] if v[1] else '?'
))
print('# you-get %s' % log.sprint(v[0][0], log.UNDERLINE))
print()
print('Best matched result:') print('Best matched result:')
return(videos[0][0]) return(videos[0])
def url_to_module(url): def url_to_module(url):