コード例 #1
0
    def _search(self, search_string, sort_by, **search_args):

        search_result = self.youtube.search(search_string, sort_by, **search_args)

        for video in search_result:
            self.videos.setdefault(video.video_id, video)

            title = cleanup_markup(video.title)
            description = "" if video.description is None else cleanup_markup(video.description)

            info = "<b>{title}</b>\n{description}\n{duration}".format(
                title=title,
                description=cream.util.string.crop_string(description, 100),
                duration=convert_ns(int(video.duration) * 1000000000),
            )

            with gtk.gdk.lock:
                video._tree_iter = self.ui.search_results_liststore.append((video.video_id, info, None, True))

        for row in self.ui.search_results_liststore:
            try:
                video = self.videos[row[0]]
            except TypeError:
                print "row[0]:", row[0]
            if self._request_video_info(video):
                thumbnail = gtk.gdk.pixbuf_new_from_file(video.download_thumbnail()).scale_simple(
                    ICON_SIZE, ICON_SIZE, gtk.gdk.INTERP_HYPER
                )
            else:
                thumbnail = DEFAULT_THUMBNAIL
            row[2] = thumbnail
コード例 #2
0
 def _request_video_info(self, video):
     try:
         video.request_video_info()
         return True
     except youtube.YouTubeError, exc:
         self.ui.search_results_liststore.set_value(video._tree_iter, 1, cleanup_markup(exc.reason))
         self.ui.search_results_liststore.set_value(video._tree_iter, 3, False)
         return False