Example #1
0
    def resolve(self):
        """ Resolve the video """
        if "resolve" in self.done:
            return True
        # load the page
        if not self.load():
            return False

        # same as WebBackend
        page = self.document.getroot()
        div = page.get_element_by_id("player")
        # See if youtube shows an error message
        try:
            error_ = div.get_element_by_id("unavailable-message")
        except:
            error_ = None

        def error(e):
            if error_ is not None:
                self.error.emit(error_.text.strip() + "\n\n(" + e + ")")
            else:
                self.error.emit(e)
            return False

        # get the player config
        for script in div.iterfind(".//script"):
            if script.text is not None and "ytplayer.config" in script.text:
                fvars = script.text[script.text.index("ytplayer.config = {") + 18:script.text.rindex("}") + 1]
                break
        else:
            return error("Could not get flashvars")
        try:
            data = json.loads(fvars, strict=False)
        except:
            with tempfile.NamedTemporaryFile("w", suffix=".json", prefix="vlyc", delete=False) as fp:
                fp.write(fvars)
            return error("Could not parse flashvars. See %s" % fp.name)

        args = data["args"]
        # extract info
        self.urlmap = dict(
            [
                (
                    int(i["itag"]),
                    "&signature=".join((i["url"], i["sig"]))
                )
                for i in [sdict_parser(i, unq=2) for i in args["url_encoded_fmt_stream_map"].split(",")]
            ]
        )
        self.title = args["title"]

        # Done
        self.done.add("resolve")
        return True
Example #2
0
 def load_callback(ok_):
     if not ok_:
         return
     if web.title().startswith("Success"):
         window.close()
         _, dct = web.title().rsplit(" ", 1)
         data = sdict_parser(dct)
         if "code" in data:
             yauth.finishAuth(data["code"])
             global ok
             ok = True
         window.destroy()
         cb()
Example #3
0
 def on_videoFeedButton_clicked(self):
     self.videoFeedResults.clear()
     parameters = list()
     feed = self.videoFeedInput.text()
     if "?" in feed:
         feed, s = feed.split("?", 1)
         d = sdict_parser(s)
         parameters.extend(d.items())
     try:
         lst = self.makeListWidgetItemListFromGDATA(gdata(feed, parameters))
     except auth.yauth.request.HTTPError as e:
         QtGui.QMessageBox.critical(self, "API Error", e.fp.read().decode("utf8"))
     for i in lst:
         self.videoFeedResults.addItem(i)
Example #4
0
 def youtube_init_video(self,video_url):
     # Get VideoId
     self.logger_youtube.debug("New Video: "+video_url)
     match = self.youtube_regexp.match(video_url)
     if not match:
         return self.youtube_message.format(video_url)
     self.logger_youtube.debug("Search String: %s"%match.group(1))
     params = sdict_parser(match.group(1))
     self.logger_youtube.debug("Parameters: %s"%str(params))
     if "v" not in params:
         return self.youtube_message.format(video_url)
     vid = params["v"]
     # Resolve Video
     self.logger_youtube.debug("Resolving Video: "+vid)
     video_info = resolve.resolve3(vid,self.resolver)
     if not video_info:
         return self.resolve_message.format(vid)
     self.video_info = video_info
     # Create Quality List
     self.logger_youtube.debug("Assembling Format List")
     self.qa_map = OrderedDict()
     for f in self.main_q_lookup:
         if f in video_info.urlmap:
             self.qa_map[profiles.descriptions[f]]=f
     # Determine Initial Quality
     self.logger_youtube.debug("Determining fitting Quality Level")
     for f in self.pref_q_lookup:
         if f in video_info.urlmap:
             fmt = f
             break;
     else:
         fmt = self.qa_map.values()[0]
     # Update UI
     self.logger_player.debug("Setting up UI for Video: "+video_info.title)
     self.uilock=True
     self.main_window.setWindowTitle(self.window_title_2.format(video_info.title))
     # Populate Quality ComboBox
     self.main_window.ui.combo_quality.clear()
     self.main_window.ui.combo_quality.addItems(list(self.qa_map.keys()))
     self.main_window.ui.combo_quality.setCurrentIndex(
         self.main_window.ui.combo_quality.findText(profiles.descriptions[fmt], flags=QtCore.Qt.MatchExactly))
     self.uilock=False
     # Set Quality Level
     self.youtube_set_fmt(fmt)