- def get_player_params(self, doc):
- for script in doc.xpath("//script"):
- if not script.text:
- continue
- for line in script.text.split("\n"):
- s = "var playerParams = {"
- if s in line:
- p1 = line.find(s) + len(s) - 1
- p2 = line.find("};", p1) + 1
- if p1 >= 0 and p2 > 0:
- return json.loads(line[p1:p2])
- raise Exception("Unable to find player params for %s: %s" % (self.video_id, self.title))
-