Skip to content

Commit

Permalink
Allow non-ASCII characters in simplified titles(Closes #220)
Browse files Browse the repository at this point in the history
  • Loading branch information
phihag committed Nov 21, 2011
1 parent e092418 commit af8e8d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions test/test_div.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ def test_simplify_title():
assert u'/' not in youtube_dl._simplify_title(u'abc/de')
assert u'abc' in youtube_dl._simplify_title(u'abc/de')
assert u'de' in youtube_dl._simplify_title(u'abc/de')
assert u'/' not in youtube_dl._simplify_title(u'abc/de///')

assert u'\\' not in youtube_dl._simplify_title(u'abc\\de')
assert u'abc' in youtube_dl._simplify_title(u'abc\\de')
assert u'de' in youtube_dl._simplify_title(u'abc\\de')

# TODO: Fix #220
#assert youtube_dl._simplify_title(u'ä') == u'ä'
assert youtube_dl._simplify_title(u'ä') == u'ä'
assert youtube_dl._simplify_title(u'кириллица') == u'кириллица'

# Strip underlines
assert youtube_dl._simplify_title(u'\'a_') == u'a'
10 changes: 6 additions & 4 deletions youtube_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ def timeconvert(timestr):
return timestamp

def _simplify_title(title):
return re.sub(ur'[^\w\d_\-]+', u'_', title).strip(u'_')
expr = re.compile(ur'[^\w\d_\-]+', flags=re.UNICODE)
return expr.sub(u'_', title).strip(u'_')

class DownloadError(Exception):
"""Download Error exception.
Expand Down Expand Up @@ -2937,6 +2938,7 @@ def _real_extract(self, url):
if urlh.headers.get('Content-Type', '').startswith('video/'): # Direct download
basename = url.split('/')[-1]
title,ext = os.path.splitext(basename)
title = title.decode('UTF-8')
ext = ext.replace('.', '')
self.report_direct_download(title)
info = {
Expand Down Expand Up @@ -3089,9 +3091,9 @@ def _real_extract(self, url):

if mobj.group('shortname'):
if mobj.group('shortname') in ('tds', 'thedailyshow'):
url = 'http://www.thedailyshow.com/full-episodes/'
url = u'http://www.thedailyshow.com/full-episodes/'
else:
url = 'http://www.colbertnation.com/full-episodes/'
url = u'http://www.colbertnation.com/full-episodes/'
mobj = re.match(self._VALID_URL, url)
assert mobj is not None

Expand Down Expand Up @@ -3177,7 +3179,7 @@ def _real_extract(self, url):

self._downloader.increment_downloads()

effTitle = showId + '-' + epTitle
effTitle = showId + u'-' + epTitle
info = {
'id': shortMediaId,
'url': video_url,
Expand Down

0 comments on commit af8e8d6

Please sign in to comment.