浏览代码

[extractor/common] add update_url_params helper method to add or update query string params

remitamine 9 年之前
父节点
当前提交
f3bdae76de
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      youtube_dl/extractor/common.py

+ 7 - 0
youtube_dl/extractor/common.py

@@ -517,6 +517,13 @@ class InfoExtractor(object):
             else:
                 self.report_warning(errmsg + str(ve))
 
+    def update_url_params(self, url, params):
+        parsed_url = compat_urlparse.urlparse(url)
+        qs = compat_urlparse.parse_qs(parsed_url.query)
+        qs.update(params)
+        return compat_urlparse.urlunparse(
+            parsed_url._replace(query=compat_urllib_parse.urlencode(qs, True)))
+
     def report_warning(self, msg, video_id=None):
         idstr = '' if video_id is None else '%s: ' % video_id
         self._downloader.report_warning(