about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2011-11-21 20:07:24 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2011-11-21 20:07:24 +0100
commite33e3045c6d3a4e6a8489074548e392e4f748615 (patch)
tree73dba07e1dec8d4d20966f19a73bdaa48c959817
parentcb6568bf21e891143dab378d4a40988fc52b9f1d (diff)
downloadyoutube-dl-e33e3045c6d3a4e6a8489074548e392e4f748615.tar.gz
youtube-dl-e33e3045c6d3a4e6a8489074548e392e4f748615.tar.xz
youtube-dl-e33e3045c6d3a4e6a8489074548e392e4f748615.zip
First tests
-rw-r--r--test/test_div.py21
-rwxr-xr-xyoutube-dl2
-rwxr-xr-xyoutube_dl/__init__.py2
3 files changed, 25 insertions, 0 deletions
diff --git a/test/test_div.py b/test/test_div.py
new file mode 100644
index 000000000..367780ed3
--- /dev/null
+++ b/test/test_div.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+
+# Various small unit tests
+
+import os,sys
+sys.path.append(os.path.dirname(os.path.dirname(__file__)))
+
+import youtube_dl
+
+def test_simplify_title():
+	assert youtube_dl._simplify_title('abc') == 'abc'
+	assert youtube_dl._simplify_title('abc_d-e') == 'abc_d-e'
+
+	assert '/' not in youtube_dl._simplify_title('abc/de')
+	assert 'abc' in youtube_dl._simplify_title('abc/de')
+	assert 'de' in youtube_dl._simplify_title('abc/de')
+
+	assert '\\' not in youtube_dl._simplify_title('abc\\de')
+	assert 'abc' in youtube_dl._simplify_title('abc\\de')
+	assert 'de' in youtube_dl._simplify_title('abc\\de')
+
diff --git a/youtube-dl b/youtube-dl
index a5af555ff..8fc320cbf 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -279,6 +279,8 @@ def timeconvert(timestr):
 		timestamp = email.utils.mktime_tz(timetuple)
 	return timestamp
 
+def _simplify_title(title):
+	return re.sub(ur'[^\w\d_\-]+', u'_', title)
 
 class DownloadError(Exception):
 	"""Download Error exception.
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
index a5af555ff..8fc320cbf 100755
--- a/youtube_dl/__init__.py
+++ b/youtube_dl/__init__.py
@@ -279,6 +279,8 @@ def timeconvert(timestr):
 		timestamp = email.utils.mktime_tz(timetuple)
 	return timestamp
 
+def _simplify_title(title):
+	return re.sub(ur'[^\w\d_\-]+', u'_', title)
 
 class DownloadError(Exception):
 	"""Download Error exception.