Beispiel #1
0
 def load_uri(self, uri):
     """
         Load uri
         @param uri as str
     """
     self._error = None
     self.__related_uri = uri
     parsed = urlparse(uri)
     if uri == "about:blank":
         WebKit2.WebView.load_plain_text(self, "")
     # We are not a ftp browser, fall back to env
     elif parsed.scheme == "ftp":
         argv = [get_ftp_cmd(), uri, None]
         GLib.spawn_sync(None, argv, None,
                         GLib.SpawnFlags.SEARCH_PATH, None)
     else:
         if uri.startswith("/"):
             uri = "file://" + uri
         elif parsed.scheme == "javascript":
             self.__js_load = True
             uri = GLib.uri_unescape_string(uri, None)
             self.run_javascript(uri.replace("javascript:", ""), None, None)
         elif parsed.scheme not in ["http", "https", "file",
                                    "populars", "accept"]:
             uri = "http://" + uri
         # Reset bad tls certificate
         if parsed.scheme != "accept":
             self.reset_bad_tls()
             self.__insecure_content_detected = False
         self.emit("uri-changed", uri)
         WebKit2.WebView.load_uri(self, uri)
Beispiel #2
0
def install_youtube_dl():
    try:
        path = GLib.get_user_data_dir() + "/lollypop/python"
        argv = ["pip3", "install", "-t", path, "-U", "youtube-dl"]
        GLib.spawn_sync(None, argv, [], GLib.SpawnFlags.SEARCH_PATH, None)
    except Exception as e:
        Logger.error("install_youtube_dl: %s" % e)
Beispiel #3
0
 def _save_artwork_tags(self, data, album):
     """
         Save artwork in tags
         @param data as bytes
         @param album as Album
     """
     stream = Gio.MemoryInputStream.new_from_data(data, None)
     pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(stream,
                                                        ArtSize.MONSTER,
                                                        ArtSize.MONSTER,
                                                        True,
                                                        None)
     pixbuf.savev("/tmp/lollypop_cover_tags.jpg",
                  "jpeg", ["quality"], ["90"])
     del pixbuf
     if os.path.exists("/tmp/lollypop_cover_tags.jpg"):
         argv = ["kid3-cli", "-c", "select all", "-c",
                 "set picture:'/tmp/lollypop_cover_tags.jpg' ''"]
         for path in Lp().albums.get_track_paths(album.id, [], []):
             argv.append(path)
         argv.append(None)
         GLib.spawn_sync(None, argv, None,
                         GLib.SpawnFlags.SEARCH_PATH, None)
         os.remove("/tmp/lollypop_cover_tags.jpg")
         self.clean_album_cache(album)
         GLib.idle_add(self.album_artwork_update, album.id)
Beispiel #4
0
 def load_uri(self, uri):
     """
         Load uri
         @param uri as str
     """
     self.__cancellable.cancel()
     self.__cancellable.reset()
     if uri == "about:blank":
         WebKit2.WebView.load_plain_text(self, "")
         self.__loaded_uri = uri
         return
     parsed = urlparse(uri)
     # We are not a ftp browser, fall back to env
     if parsed.scheme == "ftp":
         argv = [get_ftp_cmd(), uri, None]
         GLib.spawn_sync(None, argv, None, GLib.SpawnFlags.SEARCH_PATH,
                         None)
         return
     elif parsed.scheme == "javascript":
         uri = GLib.uri_unescape_string(uri, None)
         self.run_javascript(uri.replace("javascript:", ""), None, None)
         return
     elif parsed.scheme not in [
             "http", "https", "file", "populars", "accept"
     ]:
         uri = "http://" + uri
     # Reset bad tls certificate
     elif parsed.scheme != "accept":
         self.__bad_tls = None
         self.__insecure_content_detected = False
     self.__loaded_uri = uri
     WebKit2.WebView.load_uri(self, uri)
Beispiel #5
0
 def remove_album_artwork(self, album):
     """
         Remove album artwork
         @param album as Album
     """
     try:
         for uri in self.get_album_artworks(album):
             f = Gio.File.new_for_uri(uri)
             try:
                 f.trash()
             except:
                 f.delete(None)
         if Lp().settings.get_value('save-to-tags') and\
                 GLib.find_program_in_path("kid3-cli") is not None:
             argv = ["kid3-cli", "-c", "select all", "-c",
                     "set picture:'' ''"]
             for uri in Lp().albums.get_track_uris(album.id, [], []):
                 try:
                     path = GLib.filename_from_uri(uri)[0]
                     argv.append(path)
                 except:  # Gvfs can't find path for uri
                     pass
             argv.append(None)
             GLib.spawn_sync(None, argv, None,
                             GLib.SpawnFlags.SEARCH_PATH, None)
     except Exception as e:
         print("AlbumArt::remove_album_artwork():", e)
Beispiel #6
0
 def __save_artwork_tags(self, data, album):
     """
         Save artwork in tags
         @param data as bytes
         @param album as Album
     """
     stream = Gio.MemoryInputStream.new_from_data(data, None)
     pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
         stream, ArtSize.MONSTER, ArtSize.MONSTER, True, None)
     pixbuf.savev("/tmp/lollypop_cover_tags.jpg", "jpeg", ["quality"],
                  ["90"])
     del pixbuf
     if os.path.exists("/tmp/lollypop_cover_tags.jpg"):
         argv = [
             "kid3-cli", "-c", "select all", "-c",
             "set picture:'/tmp/lollypop_cover_tags.jpg' ''"
         ]
         for uri in Lp().albums.get_track_uris(album.id, [], []):
             path = GLib.filename_from_uri(uri)[0]
             argv.append(path)
         argv.append(None)
         GLib.spawn_sync(None, argv, None, GLib.SpawnFlags.SEARCH_PATH,
                         None)
         os.remove("/tmp/lollypop_cover_tags.jpg")
         self.clean_album_cache(album)
         GLib.idle_add(self.album_artwork_update, album.id)
Beispiel #7
0
 def __save_artwork_tags(self, data, album):
     """
         Save artwork in tags
         @param data as bytes
         @param album as Album
     """
     if album.is_youtube:
         return
     stream = Gio.MemoryInputStream.new_from_data(data, None)
     pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(stream,
                                                        ArtSize.MONSTER,
                                                        ArtSize.MONSTER,
                                                        True,
                                                        None)
     pixbuf.savev("/tmp/lollypop_cover_tags.jpg",
                  "jpeg", ["quality"], ["90"])
     del pixbuf
     f = Gio.File.new_for_path("/tmp/lollypop_cover_tags.jpg")
     if f.query_exists():
         argv = ["kid3-cli", "-c", "select all", "-c",
                 "set picture:'/tmp/lollypop_cover_tags.jpg' ''"]
         for uri in Lp().albums.get_track_uris(album.id, [], []):
             try:
                 path = GLib.filename_from_uri(uri)[0]
                 argv.append(path)
             except:  # Gvfs can't find a path for uri
                 pass
         argv.append(None)
         GLib.spawn_sync(None, argv, None,
                         GLib.SpawnFlags.SEARCH_PATH, None)
         f = Gio.File.new_for_path("/tmp/lollypop_cover_tags.jpg")
         f.delete()
         self.clean_album_cache(album)
         GLib.idle_add(self.album_artwork_update, album.id)
Beispiel #8
0
    def __on_report_activate(self, action, param):
        """
            Launch bug report page
            @param action as Gio.SimpleAction
            @param param as GLib.Variant
        """
        argv = ["uname", "-a", None]
        (s, o, e, s) = GLib.spawn_sync(None, argv, None,
                                       GLib.SpawnFlags.SEARCH_PATH, None)
        if o:
            os = o.decode("utf-8")
        else:
            os = "Unknown"

        github = "https://github.com/gnumdk/eolie/issues/new?body="
        body = """
TRANSLATORS:
https://translate.zanata.org/project/view/eolie

### Environment
- Eolie version: %s
- GTK+ version: %s.%s
- Operating system: %s

### Bug/Feature
If your bug is a rendering bug or a WebKit crash, you should report it here:
https://bugs.webkit.org -> Section WebKit Gtk -> title starting with [GTK]

<Describe your bug here>""" % (self.__version, Gtk.get_major_version(),
                               Gtk.get_minor_version(), os)
        url = github + GLib.uri_escape_string(body, "", False)
        self.active_window.container.add_webview(url, LoadingType.FOREGROUND,
                                                 False)
Beispiel #9
0
 def load_uri(self, uri):
     """
         Load uri
         @param uri as str
     """
     if App().phishing.is_phishing(uri):
         self._show_phishing_error(uri)
         return
     self.discard_error()
     # If not an URI, start a search
     parsed = urlparse(uri)
     is_uri = parsed.scheme in [
         "about", "http", "https", "file", "populars"
     ]
     if not is_uri and\
             not uri.startswith("/") and\
             App().search.is_search(uri):
         uri = App().search.get_search_uri(uri)
     parsed = urlparse(uri)
     if uri == "about:blank":
         WebKit2.WebView.load_plain_text(self, "")
     # We are not a ftp browser, fall back to env
     elif parsed.scheme == "ftp":
         argv = [get_ftp_cmd(), uri, None]
         GLib.spawn_sync(None, argv, None, GLib.SpawnFlags.SEARCH_PATH,
                         None)
     else:
         if uri.startswith("/"):
             uri = "file://" + uri
         elif parsed.scheme == "javascript":
             # To bypass popup blocker
             self._last_click_time = time()
             uri = GLib.uri_unescape_string(uri, None)
             self.run_javascript(uri.replace("javascript:", ""), None, None)
         elif parsed.scheme not in [
                 "http", "https", "file", "populars", "accept"
         ]:
             uri = "http://" + uri
         # Reset bad tls certificate
         if parsed.scheme != "accept":
             self.reset_bad_tls()
             self.__insecure_content_detected = False
         self.stop_loading()
         self.update_settings_for_uri(uri)
         GLib.idle_add(WebKit2.WebView.load_uri, self, uri)
Beispiel #10
0
 def remove_album_artwork(self, album):
     """
         Remove album artwork
         @param album as Album
     """
     try:
         for artwork in self.get_album_artworks(album):
             os.remove(os.path.join(album.path, artwork))
         if Lp().settings.get_value('artwork-tags') and\
                 which("kid3-cli") is not None:
             argv = ["kid3-cli", "-c", "select all", "-c",
                     "set picture:'' ''"]
             for path in Lp().albums.get_track_paths(album.id, [], []):
                 argv.append(path)
             argv.append(None)
             GLib.spawn_sync(None, argv, None,
                             GLib.SpawnFlags.SEARCH_PATH, None)
     except Exception as e:
         print("AlbumArt::remove_album_artwork():", e)
Beispiel #11
0
 def remove_album_artwork(self, album):
     """
         Remove album artwork
         @param album as Album
     """
     try:
         for artwork in self.get_album_artworks(album):
             os.remove(os.path.join(album.path, artwork))
         if Lp().settings.get_value('artwork-tags') and\
                 which("kid3-cli") is not None:
             argv = [
                 "kid3-cli", "-c", "select all", "-c", "set picture:'' ''"
             ]
             for uri in Lp().albums.get_track_uris(album.id, [], []):
                 path = GLib.filename_from_uri(uri)[0]
                 argv.append(path)
             argv.append(None)
             GLib.spawn_sync(None, argv, None, GLib.SpawnFlags.SEARCH_PATH,
                             None)
     except Exception as e:
         print("AlbumArt::remove_album_artwork():", e)
Beispiel #12
0
 def _on_button_press(self, widget, event):
     """
         On button press, set album popularity
         @param widget as Gtk.EventBox
         @param event as Gdk.Event
     """
     if Lp().scanner.is_locked():
         return
     event_star = widget.get_children()[0]
     if event_star in self._stars:
         position = self._stars.index(event_star)
     else:
         position = -1
     pop = position + 1
     self._object.set_popularity(pop)
     # Save to tags if needed
     if Lp().settings.get_value('save-to-tags') and\
             GLib.find_program_in_path("kid3-cli") is not None and\
             isinstance(self._object, Track) and\
             not self._object.is_web:
         if pop == 0:
             value = 0
         elif pop == 1:
             value = 1
         elif pop == 2:
             value = 64
         elif pop == 3:
             value = 128
         elif pop == 4:
             value = 196
         else:
             value = 255
         path = GLib.filename_from_uri(self._object.uri)[0]
         argv = [
             "kid3-cli", "-c", "select all", "-c",
             "set pop: %s" % value, path, None
         ]
         GLib.spawn_sync(None, argv, None, GLib.SpawnFlags.SEARCH_PATH,
                         None)
     return True
Beispiel #13
0
 def get_uri_content(uri):
     """
         Get content uri
         @param uri as str
         @return content uri as str/None
     """
     # Remove playlist args
     uri = sub("list=.*", "", uri)
     argv = ["youtube-dl", "-g", "-f", "bestaudio", uri, None]
     (s, o, e, s) = GLib.spawn_sync(None, argv, None,
                                    GLib.SpawnFlags.SEARCH_PATH, None)
     if o:
         return o.decode("utf-8")
     else:
         if Lp().notify:
             Lp().notify.send(e.decode("utf-8"))
         print("WebYouTube::get_uri_content:", e.decode("utf-8"))
         return None
Beispiel #14
0
 def _get_pa_outputs(self):
     """
         Get PulseAudio outputs
         @return name/device as [(str, str)]
     """
     ret = []
     argv = ["pacmd", "list-sinks", None]
     try:
         (s, out, err, e) = GLib.spawn_sync(None, argv, None,
                                            GLib.SpawnFlags.SEARCH_PATH,
                                            None)
         string = out.decode('utf-8')
         devices = findall('name: <([^>]*)>', string, DOTALL)
         names = findall('device.description = "([^"]*)"', string, DOTALL)
         for name in names:
             ret.append((name, devices.pop(0)))
     except Exception as e:
         print("SettingsDialog::_get_pa_outputse()", e)
     return ret
Beispiel #15
0
 def __get_pa_outputs(self):
     """
         Get PulseAudio outputs
         @return name/device as [(str, str)]
     """
     ret = []
     argv = ["pacmd", "list-sinks", None]
     try:
         (s, out, err, e) = GLib.spawn_sync(None, argv, None,
                                            GLib.SpawnFlags.SEARCH_PATH,
                                            None)
         string = out.decode('utf-8')
         devices = findall('name: <([^>]*)>', string, DOTALL)
         names = findall('device.description = "([^"]*)"', string, DOTALL)
         for name in names:
             ret.append((name, devices.pop(0)))
     except Exception as e:
         print("SettingsDialog::_get_pa_outputse()", e)
     return ret
Beispiel #16
0
 def get_uri_content(self, track):
     """
         Get content uri
         @param track as Track
         @return content uri as str/None
     """
     # Remove playlist args
     uri = sub("list=.*", "", track.uri)
     argv_list = [["youtube-dl", "-g", "-f", "bestaudio", uri, None],
                  ["youtube-dl", "-g", uri, None]]
     for argv in argv_list:
         (s, o, e, s) = GLib.spawn_sync(None, argv, None,
                                        GLib.SpawnFlags.SEARCH_PATH, None)
         if o:
             return o.decode("utf-8")
     error = e.decode("utf-8")
     if App().notify is not None:
         App().notify.send(error)
     Logger.warning("YouTubeHelper::get_uri_content(): %s", error)
     return None
 def get_uri_content(uri):
     """
         Get content uri
         @param uri as str
         @return content uri as str/None
     """
     # Remove playlist args
     uri = sub("list=.*", "", uri)
     argv = ["youtube-dl", "-g", "-f", "bestaudio", uri, None]
     (s, o, e, s) = GLib.spawn_sync(None,
                                    argv,
                                    None,
                                    GLib.SpawnFlags.SEARCH_PATH,
                                    None)
     if o:
         return o.decode("utf-8")
     else:
         if Lp().notify:
             Lp().notify.send(e.decode("utf-8"))
         print("WebYouTube::get_uri_content:", e.decode("utf-8"))
         return None
Beispiel #18
0
 def __youtube_dl_lookup(self, track, play):
     """
         Launch youtube-dl to get video url
         @param track as Track
         @param play as bool
     """
     # Remove playlist args
     uri = sub("list=.*", "", track.uri)
     argv = ["youtube-dl", "-g", "-f", "bestaudio", uri, None]
     (s, o, e, s) = GLib.spawn_sync(None,
                                    argv,
                                    None,
                                    GLib.SpawnFlags.SEARCH_PATH,
                                    None)
     if o:
         GLib.idle_add(self.__set_gv_uri, o.decode("utf-8"), track, play)
     else:
         if Lp().notify:
             Lp().notify.send(e.decode("utf-8"))
         print("BinPlayer::__youtube_dl_lookup:", e.decode("utf-8"))
         if play:
             GLib.idle_add(self.emit, 'loading-changed', False)
Beispiel #19
0
    def __get_xkb_layout(self):
        # Until Gdk.property_get is fixed
        '''
        # Move importing Gdk into ThumbShiftKeyboard from the header
        # because ibus-engine-anthy --xml does not requre to open X.
        try:
            from gi.repository import Gdk
            get_default_root_window = Gdk.get_default_root_window
            property_get = Gdk.property_get
            intern = Gdk.Atom.intern
        except ImportError:
            get_default_root_window = lambda : None
            property_get = lambda : None
            intern = lambda : None
        except RuntimeError:
            # Do we support the engine without display?
            print >> sys.stderr, "Gdk couldn't be initialized"
            print >> sys.stderr, 'Could not open display'
            get_default_root_window = lambda : None
            property_get = lambda : None
            intern = lambda : None

        root_window = get_default_root_window()
        if not root_window:
            return 0
        xkb_rules_names = intern('_XKB_RULES_NAMES', False)
        xa_string = intern('STRING', False)
        try:
            prop = property_get(root_window,
                                xkb_rules_names, xa_string,
                                0, 1024, 0)[3]
            layout_list = prop.split('\0')
        except TypeError:
            print >> sys.stderr, \
              'This problem is fixed in the latest gobject-introspection'
            print >> sys.stderr, \
              'https://bugzilla.gnome.org/show_bug.cgi?id=670509'
            return 0
        layout = 0
        for data in layout_list:
            if data == 'jp':
                layout = 0
            elif data == 'us':
                layout = 1
            elif data.find('japan:nicola_f_bs') >= 0:
                layout = 2
            elif data.find('japan:') >= 0:
                layout = 0
        return layout
        '''

        layout = 0
        argv = ['setxkbmap', '-query']
        (ret, std_out, std_error, exit_status) = \
                GLib.spawn_sync(None, argv, None,
                                GLib.SpawnFlags.SEARCH_PATH_FROM_ENVP,
                                None, None)
        if not ret:
            print >> sys.stderr, std_error
            return layout
        for line in std_out.split('\n'):
            if line.startswith('layout:'):
                data = line.split()[1]
                if data == 'jp':
                    layout = 0
                elif data == 'us':
                    layout = 1
            elif line.startswith('options:'):
                data = line.split()[1]
                if data.find('japan:nicola_f_bs') >= 0:
                    layout = 2
                elif data.find('japan:') >= 0:
                    layout = 0
        return layout
Beispiel #20
0
    def __get_xkb_layout(self):
        # Until Gdk.property_get is fixed
        '''
        # Move importing Gdk into ThumbShiftKeyboard from the header
        # because ibus-engine-anthy --xml does not requre to open X.
        try:
            from gi.repository import Gdk
            get_default_root_window = Gdk.get_default_root_window
            property_get = Gdk.property_get
            intern = Gdk.Atom.intern
        except ImportError:
            get_default_root_window = lambda : None
            property_get = lambda : None
            intern = lambda : None
        except RuntimeError:
            # Do we support the engine without display?
            print >> sys.stderr, "Gdk couldn't be initialized"
            print >> sys.stderr, 'Could not open display'
            get_default_root_window = lambda : None
            property_get = lambda : None
            intern = lambda : None

        root_window = get_default_root_window()
        if not root_window:
            return 0
        xkb_rules_names = intern('_XKB_RULES_NAMES', False)
        xa_string = intern('STRING', False)
        try:
            prop = property_get(root_window,
                                xkb_rules_names, xa_string,
                                0, 1024, 0)[3]
            layout_list = prop.split('\0')
        except TypeError:
            print >> sys.stderr, \
              'This problem is fixed in the latest gobject-introspection'
            print >> sys.stderr, \
              'https://bugzilla.gnome.org/show_bug.cgi?id=670509'
            return 0
        layout = 0
        for data in layout_list:
            if data == 'jp':
                layout = 0
            elif data == 'us':
                layout = 1
            elif data.find('japan:nicola_f_bs') >= 0:
                layout = 2
            elif data.find('japan:') >= 0:
                layout = 0
        return layout
        '''

        layout = 0
        argv = ['setxkbmap', '-query']
        (ret, std_out, std_error, exit_status) = \
                GLib.spawn_sync(None, argv, None,
                                GLib.SpawnFlags.SEARCH_PATH_FROM_ENVP,
                                None, None)
        if not ret:
            print >> sys.stderr, std_error
            return layout
        for line in std_out.split('\n'):
            if line.startswith('layout:'):
                data = line.split()[1]
                if data == 'jp':
                    layout = 0
                elif data == 'us':
                    layout = 1
            elif line.startswith('options:'):
                data = line.split()[1]
                if data.find('japan:nicola_f_bs') >= 0:
                    layout = 2
                elif data.find('japan:') >= 0:
                    layout = 0
        return layout