示例#1
0
    def on_url_changed(self, entry):
        url_str = entry.get_text()
        url = urlparse(url_str)
        e_types = (StreamType.E_SERVICE_URI.value,
                   StreamType.E_SERVICE_HLS.value)
        cond = all([url.scheme, url.netloc, url.path
                    ]) or self.get_type() in e_types
        entry.set_name("GtkEntry" if cond else _DIGIT_ENTRY_NAME)

        yt_id = YouTube.get_yt_id(url_str)
        if yt_id:
            entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY,
                                       get_yt_icon("youtube", 32))
            text = "Found a link to the YouTube resource!\nTry to get a direct link to the video?"
            if show_dialog(DialogType.QUESTION, self._dialog,
                           text=text) == Gtk.ResponseType.OK:
                entry.set_sensitive(False)
                gen = self.set_yt_url(entry, yt_id)
                GLib.idle_add(lambda: next(gen, False),
                              priority=GLib.PRIORITY_LOW)
        elif YouTube.is_yt_video_link(url_str):
            entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY,
                                       get_yt_icon("youtube", 32))
        else:
            entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, None)
            self._yt_quality_box.set_visible(False)
示例#2
0
    def activate_url(self, url):
        self._url_entry.set_name("GtkEntry")
        self._url_entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY,
                                            None)

        if self.is_url(url):
            self._tool_bar.set_sensitive(False)
            yt_id = YouTube.get_yt_id(url)
            yield True

            if yt_id:
                self._url_entry.set_icon_from_pixbuf(
                    Gtk.EntryIconPosition.SECONDARY,
                    get_yt_icon("youtube", 32))
                links, title = self._yt.get_yt_link(yt_id, url)
                yield True
                if links:
                    url = links[sorted(links,
                                       key=lambda x: int(x.rstrip("p")),
                                       reverse=True)[0]]
                else:
                    self.on_done(links)
                    return
            else:
                self._url_entry.set_icon_from_stock(
                    Gtk.EntryIconPosition.SECONDARY, None)

            self._http_api.send(HttpAPI.Request.PLAY, url, self.on_done,
                                self.__STREAM_PREFIX)
            yield True
示例#3
0
    def __init__(self, http_api, app_window, settings):
        handlers = {
            "on_popup_menu": self.on_popup_menu,
            "on_status_icon_activate": self.on_status_icon_activate,
            "on_url_changed": self.on_url_changed,
            "on_url_activate": self.on_url_activate,
            "on_drag_data_received": self.on_drag_data_received,
            "on_previous": self.on_previous,
            "on_next": self.on_next,
            "on_stop": self.on_stop,
            "on_clear": self.on_clear,
            "on_play": self.on_play
        }

        self._http_api = http_api
        self._app_window = app_window
        self._is_status_icon = True

        builder = Gtk.Builder()
        builder.add_from_file(UI_RESOURCES_PATH + "transmitter.glade")
        builder.connect_signals(handlers)

        self._main_window = builder.get_object("main_window")
        self._url_entry = builder.get_object("url_entry")
        self._tool_bar = builder.get_object("tool_bar")
        self._popup_menu = builder.get_object("staus_popup_menu")
        self._restore_menu_item = builder.get_object("restore_menu_item")
        self._status_active = None
        self._status_passive = None
        self._yt = YouTube.get_instance(settings)

        try:
            gi.require_version("AppIndicator3", "0.1")
            from gi.repository import AppIndicator3
        except (ImportError, ValueError) as e:
            log("{}: Load library error: {}".format(__class__.__name__, e))
            self._tray = builder.get_object("status_icon")
        else:
            self._is_status_icon = False
            self._status_active = AppIndicator3.IndicatorStatus.ACTIVE
            self._status_passive = AppIndicator3.IndicatorStatus.PASSIVE

            category = AppIndicator3.IndicatorCategory.APPLICATION_STATUS
            path = Path(UI_RESOURCES_PATH +
                        "/icons/hicolor/scalable/apps/demon-editor.svg")
            path = str(path.resolve()) if path.is_file() else "demon-editor"
            self._tray = AppIndicator3.Indicator.new("DemonEditor", path,
                                                     category)
            self._tray.set_status(self._status_active)
            self._tray.set_secondary_activate_target(
                builder.get_object("show_menu_item"))
            self._tray.set_menu(self._popup_menu)

        style_provider = Gtk.CssProvider()
        style_provider.load_from_path(UI_RESOURCES_PATH + "style.css")
        self._url_entry.get_style_context().add_provider_for_screen(
            Gdk.Screen.get_default(), style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_USER)
示例#4
0
    def on_url_entry_changed(self, entry):
        url_str = entry.get_text()
        yt_id = YouTube.get_yt_list_id(url_str)
        entry.set_name("GtkEntry" if yt_id else _DIGIT_ENTRY_NAME)
        self._receive_button.set_sensitive(bool(yt_id))
        self._import_button.set_sensitive(bool(yt_id))
        self._yt_list_id = yt_id

        if yt_id:
            entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY,
                                       get_yt_icon("youtube", 32))
        else:
            entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, None)
示例#5
0
 def update_refs_list(self):
     if self._yt_list_id:
         try:
             if not self._yt:
                 self._yt = YouTube.get_instance(self._settings)
             self._yt_list_title, links = self._yt.get_yt_playlist(
                 self._yt_list_id, self._url_entry.get_text())
         except Exception as e:
             self.show_info_message(str(e), Gtk.MessageType.ERROR)
             return
         else:
             gen = self.update_links(links)
             GLib.idle_add(lambda: next(gen, False),
                           priority=GLib.PRIORITY_LOW)
         finally:
             self.update_active_elements(True)
示例#6
0
    def on_import(self, item):
        self.on_info_bar_close()
        self.update_active_elements(False)
        self._download_task = True

        try:
            with concurrent.futures.ThreadPoolExecutor(
                    max_workers=4) as executor:
                done_links = {}
                rows = list(filter(lambda r: r[2], self._model))
                if not self._yt:
                    self._yt = YouTube.get_instance(self._settings)

                futures = {
                    executor.submit(self._yt.get_yt_link, r[1],
                                    YouTube.VIDEO_LINK.format(r[1]), True): r
                    for r in rows
                }
                size = len(futures)
                counter = 0

                for future in concurrent.futures.as_completed(futures):
                    if not self._download_task:
                        executor.shutdown()
                        return

                    done_links[futures[future]] = future.result()
                    counter += 1
                    self.update_progress_bar(counter / size)
        except YouTubeException as e:
            self.show_info_message(str(e), Gtk.MessageType.ERROR)
        except Exception as e:
            self.show_info_message(str(e), Gtk.MessageType.ERROR)
        else:
            if self._download_task:
                self.show_info_message(get_message("Done!"),
                                       Gtk.MessageType.INFO)
                self.append_services([done_links[r] for r in rows])
        finally:
            self._download_task = False
            self.update_active_elements(True)
示例#7
0
    def set_yt_url(self, entry, video_id):
        try:
            if not self._yt_dl:

                def callback(message, error=True):
                    msg_type = Gtk.MessageType.ERROR if error else Gtk.MessageType.INFO
                    self.show_info_message(message, msg_type)

                self._yt_dl = YouTube.get_instance(self._settings,
                                                   callback=callback)
                yield True
            links, title = self._yt_dl.get_yt_link(video_id, entry.get_text())
            yield True
        except urllib.error.URLError as e:
            self.show_info_message(
                get_message("Getting link error:") + (str(e)),
                Gtk.MessageType.ERROR)
            return
        except YouTubeException as e:
            self.show_info_message((str(e)), Gtk.MessageType.ERROR)
            return
        else:
            if self._action is Action.ADD:
                self._name_entry.set_text(title)

            if links:
                if len(links) > 1:
                    self._yt_quality_box.set_visible(True)
                entry.set_text(links[sorted(links,
                                            key=lambda x: int(x.rstrip("p")),
                                            reverse=True)[0]])
                self._yt_links = links
            else:
                msg = get_message("Getting link error:"
                                  ) + " No link received for id: {}".format(
                                      video_id)
                self.show_info_message(msg, Gtk.MessageType.ERROR)
        finally:
            entry.set_sensitive(True)
        yield True