Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

change the way to parse title #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions youku.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,13 @@ def trim_title(title):
return title

def parse_video_title(url, page):
if re.search(r'v_playlist', url):
# if we are playing a viedo from play list, the meta title might be incorrect
title = r1_of([r'<div class="show_title" title="([^"]+)">[^<]', r'<title>([^<>]*)</title>'], page).decode('utf-8')
else:
title = r1_of([r'<div class="show_title" title="([^"]+)">[^<]', r'<meta name="title" content="([^"]*)"'], page).decode('utf-8')
assert title
title = trim_title(title)
if re.search(r'v_playlist', url) and re.search(r'-.*\S+', title):
title = re.sub(r'^[^-]+-\s*', '', title) # remove the special name from title for playlist video
title = re.sub(ur'—专辑:.*', u'', title) # remove the special name from title for playlist video
title = unescape_html(title)
media_start = page.find('<!--视频基本信息-->')
media_end = page.find('<script', media_start)
media_info = page[media_start:media_end]

result = re.search(r'<h1 class="title"><a[^<>]*>([^<>]*)</a>[^<>]*<span[^>]*>([^<>]*)</span></h1>', media_info)
title = result.group(1).decode('utf-8') + ':' + result.group(2).decode('utf-8')

subtitle = re.search(r'<span class="subtitle" id="subtitle">([^<>]*)</span>', page)
if subtitle:
subtitle = subtitle.group(1).decode('utf-8').strip()
if subtitle == title:
subtitle = None
if subtitle:
title += '-' + subtitle
return title

def parse_playlist_title(url, page):
Expand Down