Fixed for Google changes
authorJames Bunton <jamesbunton@delx.net.au>
Thu, 13 Jun 2019 10:25:39 +0000 (20:25 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Thu, 13 Jun 2019 10:25:39 +0000 (20:25 +1000)
youtube.cgi

index d1cb666..9e14fd1 100755 (executable)
@@ -15,8 +15,7 @@ import urllib.parse
 import urllib.request
 
 
-MAX_MEMORY_BYTES = 128 * 1024*1024
-USER_AGENT = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
+USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0"
 
 MIMETYPES = {
     "video/mp4": "mp4",
@@ -227,6 +226,7 @@ def decode_signature(js_url, signature):
     p.stdin.close()
 
     transformed_signature = p.stdout.read().decode("utf-8").strip()
+    transformed_signature = urllib.parse.unquote(transformed_signature)
     if p.wait() != 0:
         raise Exception("js failed to execute: %d" % p.returncode)
 
@@ -266,7 +266,8 @@ def get_best_video(player_config):
             signature = None
 
         if signature:
-            video_url = append_to_qs(video_url, {"signature": signature})
+            sp = url_data.get("sp", ["signature"])[0]
+            video_url = append_to_qs(video_url, {sp: signature})
 
         best_url = video_url
         best_quality = quality
@@ -291,7 +292,7 @@ def get_video_url(page):
     if not video_url:
         return None, None
 
-    filename = sanitize_filename(page.title)
+    filename = sanitize_filename(player_config["args"]["title"])
     filename += "." + extension
 
     return video_url, filename
@@ -299,13 +300,11 @@ def get_video_url(page):
 class YouTubeVideoPageParser(html.parser.HTMLParser):
     def __init__(self):
         super().__init__()
-        self.title = None
         self.unavailable_message = None
         self.scripts = []
 
     def handle_starttag(self, tag, attrs):
         attrs = dict(attrs)
-        self._handle_title(tag, attrs)
         self._handle_unavailable_message(tag, attrs)
         self._handle_script(tag, attrs)
 
@@ -315,13 +314,6 @@ class YouTubeVideoPageParser(html.parser.HTMLParser):
     def _ignore_data(self, _):
         pass
 
-    def _handle_title(self, tag, attrs):
-        if tag == "title":
-            self.handle_data = self._handle_title_data
-
-    def _handle_title_data(self, data):
-        self.title = data.strip()
-
     def _handle_unavailable_message(self, tag, attrs):
         if attrs.get("id", None) == "unavailable-message":
             self.handle_data = self._handle_unavailable_message_data