Simplify url_basename
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Tue, 17 Dec 2013 13:56:29 +0000 (14:56 +0100)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Tue, 17 Dec 2013 13:56:29 +0000 (14:56 +0100)
Use urlparse from the standard library.

youtube_dl/utils.py

index d5069dcca98dea4e6071d3d7d35a42576dcd4604..4c7ad89c0b39602bf50de3b5ea2a6289c2215cfe 100644 (file)
@@ -1092,7 +1092,5 @@ def remove_start(s, start):
 
 
 def url_basename(url):
-    m = re.match(r'(?:https?:|)//[^/]+/(?:[^?#]+/)?([^/?#]+)/?(?:[?#]|$)', url)
-    if not m:
-        return u''
-    return m.group(1)
+    path = compat_urlparse.urlparse(url).path
+    return path.strip(u'/').split(u'/')[-1]