Ejemplo n.º 1
0
 def __download_wikia_lyrics(self):
     """
         Downloas lyrics from wikia
     """
     self.__downloads_running += 1
     # Update lyrics
     if self.__current_track.id == Type.RADIOS:
         split = self.__current_track.name.split(" - ")
         if len(split) < 2:
             return
         artist = GLib.uri_escape_string(split[0], None, False)
         title = GLib.uri_escape_string(split[1], None, False)
     else:
         if self.__current_track.artists:
             artist = GLib.uri_escape_string(
                 self.__current_track.artists[0], None, False)
         elif self.__current_track.album_artists:
             artist = self.__current_track.album_artists[0]
         else:
             artist = ""
         title = GLib.uri_escape_string(self.__current_track.name, None,
                                        False)
     uri = "https://lyrics.wikia.com/wiki/%s:%s" % (artist, title)
     helper = TaskHelper()
     helper.load_uri_content(uri, self.__cancellable,
                             self.__on_lyrics_downloaded, "lyricbox", "\n")
Ejemplo n.º 2
0
 def __populate(self, uris):
     """
         Add uris to view
         @param uris as [str]
     """
     if self.__cancellable.is_cancelled():
         return
     helper = TaskHelper()
     # Fallback to link extraction
     if uris is None and WEBKIT2:
         if self.__web_search is None:
             self.__back_button.show()
             self.__web_search = ArtworkSearchWebView(self.__spinner)
             self.__web_search.connect("populated",
                                       self.__on_web_search_populated)
             self.__web_search.show()
             self.__entry.hide()
             self.__stack.add_named(self.__web_search, "web")
             self.__stack.set_visible_child_name("web")
             self.__web_search.search(self.__get_current_search())
     # Populate the view
     elif uris:
         uri = uris.pop(0)
         helper.load_uri_content(uri, self.__cancellable, self.__add_pixbuf,
                                 self.__populate, uris)
     # Nothing to load, stop
     else:
         self.__spinner.stop()
Ejemplo n.º 3
0
    def populate(self):
        """
            Populate view
        """
        image = Gtk.Image()
        surface = Lp().art.get_default_icon("edit-clear-all-symbolic",
                                            ArtSize.BIG,
                                            self.get_scale_factor())
        image.set_from_surface(surface)
        image.set_property("valign", Gtk.Align.CENTER)
        image.set_property("halign", Gtk.Align.CENTER)
        image.get_style_context().add_class("cover-frame")
        image.show()
        self._view.add(image)

        # First load local files
        if self.__album is not None:
            uris = Lp().art.get_album_artworks(self.__album)
            for uri in uris:
                try:
                    f = Gio.File.new_for_uri(uri)
                    (status, content, tag) = f.load_contents()
                    self.__add_pixbuf(uri, status, content, print)
                except Exception as e:
                    print("ArtworkSearch::populate()", e)
        # Then google
        uri = Lp().art.get_google_search_uri(self.__get_current_search())
        helper = TaskHelper()
        helper.load_uri_content(uri, self.__cancellable,
                                self.__on_google_content_loaded)
Ejemplo n.º 4
0
 def __download_genius_lyrics(self):
     """
         Download lyrics from genius
     """
     self.__downloads_running += 1
     # Update lyrics
     if self.__current_track.id == Type.RADIOS:
         split = App().player.current_track.name.split(" - ")
         if len(split) < 2:
             return
         artist = split[0]
         title = split[1]
     else:
         if self.__current_track.artists:
             artist = self.__current_track.artists[0]
         elif self.__current_track.album_artists:
             artist = self.__current_track.album_artists[0]
         else:
             artist = ""
         title = self.__current_track.name
     string = escape("%s %s" % (artist, title))
     uri = "https://genius.com/%s-lyrics" % string.replace(" ", "-")
     helper = TaskHelper()
     helper.load_uri_content(uri, self.__cancellable,
                             self.__on_lyrics_downloaded,
                             "song_body-lyrics", "")
Ejemplo n.º 5
0
    def populate(self):
        """
            Populate view
        """
        image = Gtk.Image.new_from_icon_name("edit-clear-all-symbolic",
                                             Gtk.IconSize.DIALOG)
        image.set_property("valign", Gtk.Align.CENTER)
        image.set_property("halign", Gtk.Align.CENTER)
        context = image.get_style_context()
        context.add_class("cover-frame")
        padding = context.get_padding(Gtk.StateFlags.NORMAL)
        border = context.get_border(Gtk.StateFlags.NORMAL)
        image.set_size_request(
            ArtSize.BIG + padding.left + padding.right + border.left +
            border.right, ArtSize.BIG + padding.top + padding.bottom +
            border.top + border.bottom)
        image.show()
        self.__view.add(image)

        # First load local files
        if self.__album is not None:
            uris = App().art.get_album_artworks(self.__album)
            for uri in uris:
                try:
                    f = Gio.File.new_for_uri(uri)
                    (status, content, tag) = f.load_contents()
                    self.__add_pixbuf(uri, status, content, print)
                except Exception as e:
                    Logger.error("ArtworkSearch::populate(): %s" % e)
        # Then google
        uri = App().art.get_google_search_uri(self.__get_current_search())
        helper = TaskHelper()
        helper.load_uri_content(uri, self.__cancellable,
                                self.__on_google_content_loaded)
Ejemplo n.º 6
0
 def get_artist_id(self, artist_name, callback):
     """
         Get artist id
         @param artist_name as str
         @param callback as function
     """
     if self.wait_for_token():
         GLib.timeout_add(
             500, self.get_artist_id, artist_name, callback)
         return
     try:
         def on_content(uri, status, data):
             found = False
             if status:
                 decode = json.loads(data.decode("utf-8"))
                 for item in decode["artists"]["items"]:
                     found = True
                     artist_id = item["uri"].split(":")[-1]
                     callback(artist_id)
                     return
             if not found:
                 callback(None)
         artist_name = GLib.uri_escape_string(
             artist_name, None, True).replace(" ", "+")
         token = "Bearer %s" % self.__token
         helper = TaskHelper()
         helper.add_header("Authorization", token)
         uri = "https://api.spotify.com/v1/search?q=%s&type=artist" %\
             artist_name
         helper.load_uri_content(uri, None, on_content)
     except Exception as e:
         Logger.error("SpotifyHelper::get_artist_id(): %s", e)
         callback(None)
Ejemplo n.º 7
0
 def __download_images(self):
     """
         Download and set image for TuneItem
         @thread safe
     """
     if self.__covers_to_download and not self.__cancellable.is_cancelled():
         (item, image) = self.__covers_to_download.pop(0)
         helper = TaskHelper()
         helper.load_uri_content(item.LOGO, self.__cancellable,
                                 self.__on_image_downloaded, image)
Ejemplo n.º 8
0
 def copy_uri_to_cache(self, uri, name, size):
     """
         Copy uri to cache at size
         @param uri as str
         @param name as str
         @param size as int
         @thread safe
     """
     helper = TaskHelper()
     helper.load_uri_content(uri, None, self.__on_uri_content, name, size)
Ejemplo n.º 9
0
 def __populate(self, uris):
     """
         Add uris to view
         @param uris as [str]
     """
     if uris:
         uri = uris.pop(0)
         helper = TaskHelper()
         helper.load_uri_content(uri, self.__cancellable, self.__add_pixbuf,
                                 self.__populate, uris)
     elif len(self.__view.get_children()) == 0:
         self.__stack.set_visible_child_name("notfound")
Ejemplo n.º 10
0
 def __populate(self, uri="http://opml.radiotime.com/Browse.ashx?c="):
     """
         Populate view for uri
         @param uri as str
     """
     self.__clear()
     self.__spinner.start()
     self.__stack.set_visible_child_name("spinner")
     self.__back_btn.set_sensitive(False)
     self.__home_btn.set_sensitive(False)
     self.__label.set_text(_("Please wait…"))
     helper = TaskHelper()
     helper.load_uri_content(uri, self.__cancellable, self.__on_uri_content)
     self.__cancellable.reset()
Ejemplo n.º 11
0
 def __on_web_search_populated(self, web_search, uri):
     """
         Load available uri
         @param web_search as ArtworkSearchWebView
         @param uri as str
     """
     if self.__stack.get_visible_child() == web_search:
         for child in self.__view.get_children():
             child.destroy()
         self.__stack.set_visible_child_name("main")
         self.__spinner.start()
         self.__back_button.set_sensitive(True)
     helper = TaskHelper()
     helper.load_uri_content(uri, self.__cancellable, self.__add_pixbuf,
                             self.__populate, [])
Ejemplo n.º 12
0
 def _on_image_button_clicked(self, widget):
     """
         Update radio image
         @param widget as Gtk.Widget
     """
     self.__save_radio()
     name = self.__radios.get_name(self.__radio_id)
     uri = App().art.get_google_search_uri("%s+%s+%s" %
                                           (name, "logo", "radio"))
     self.__stack.get_visible_child().hide()
     self.__stack.set_visible_child_name("spinner")
     helper = TaskHelper()
     helper.load_uri_content(uri, self.__cancellable,
                             self.__on_google_content_loaded)
     self.set_size_request(700, 400)
Ejemplo n.º 13
0
 def __download_wikia_lyrics(self, track, methods, callback, *args):
     """
         Downloas lyrics from wikia
         @param track as Track
         @param methods as []
         @param callback as function
     """
     title = self.__get_title(track, False)
     artist = self.__get_artist(track, False).lower()
     string = "%s:%s" % (artist, title)
     uri = "https://lyrics.wikia.com/wiki/%s" % string.replace(" ", "_")
     helper = TaskHelper()
     helper.load_uri_content(uri, self.__cancellable,
                             self.__on_lyrics_downloaded, "lyricbox", "\n",
                             track, methods, callback, *args)
Ejemplo n.º 14
0
 def __on_search_timeout(self, string):
     """
         Populate widget
         @param string as str
     """
     self.__cancellable.cancel()
     for child in self.__view.get_children():
         child.destroy()
     self.__spinner.start()
     self.__timeout_id = None
     self.__cancellable.reset()
     if get_network_available():
         uri = App().art.get_google_search_uri(string)
         helper = TaskHelper()
         helper.load_uri_content(uri, self.__cancellable,
                                 self.__on_google_content_loaded)
Ejemplo n.º 15
0
 def __add_radio(self, item):
     """
         Add selected radio
         @param item as TuneIn Item
     """
     # Get cover art
     try:
         helper = TaskHelper()
         helper.load_uri_content(item.LOGO, None,
                                 self.__on_logo_uri_content, item.TEXT)
     except Exception as e:
         Logger.error("TuneinPopover::__add_radio: %s" % e)
     # Tunein in embbed uri in ashx files, so get content if possible
     helper = TaskHelper()
     helper.load_uri_content(item.URL, self.__cancellable,
                             self.__on_item_content, item.TEXT)
Ejemplo n.º 16
0
 def populate(self, uri="http://opml.radiotime.com/Browse.ashx?c="):
     """
         Populate views
         @param uri as str
     """
     if not get_network_available():
         self.__show_not_found(_("Can't connect to TuneIn…"))
         return
     self.__spinner.start()
     self.__clear()
     self.__stack.set_visible_child_name("spinner")
     self.__back_btn.set_sensitive(False)
     self.__home_btn.set_sensitive(False)
     self.__label.set_text(_("Please wait…"))
     helper = TaskHelper()
     helper.load_uri_content(uri, self.__cancellable, self.__on_uri_content)
     self.__cancellable.reset()
Ejemplo n.º 17
0
 def __add_radio(self, item):
     """
         Add selected radio
         @param item as TuneIn Item
     """
     # Get cover art
     try:
         cache = Art._RADIOS_PATH
         s = Gio.File.new_for_uri(item.LOGO)
         d = Gio.File.new_for_path("%s/%s.png" %
                                   (cache, item.TEXT.replace("/", "-")))
         s.copy(d, Gio.FileCopyFlags.OVERWRITE, None, None)
     except Exception as e:
         print("TuneinPopover::_add_radio: %s" % e)
     # Tunein in embbed uri in ashx files, so get content if possible
     helper = TaskHelper()
     helper.load_uri_content(item.URL, self.__cancellable,
                             self.__on_item_content, item.TEXT)
Ejemplo n.º 18
0
 def __download_genius_lyrics(self, track, methods, callback, *args):
     """
         Download lyrics from genius
         @param track as Track
         @param methods as []
         @param callback as function
     """
     title = self.__get_title(track, False)
     artist = self.__get_artist(track, False)
     string = escape("%s %s" % (artist, title),
                     ignore=["_", "-", " ", ".", "/"]).replace(".", "")
     string = string.replace("/", " ")
     uri = "https://genius.com/%s-lyrics" % string.replace(" ", "-")
     helper = TaskHelper()
     helper.load_uri_content(uri, self.__cancellable,
                             self.__on_lyrics_downloaded,
                             "song_body-lyrics", "", track, methods,
                             callback, *args)
Ejemplo n.º 19
0
 def __populate(self, uris):
     """
         Add uris to view
         @param uris as [str]
     """
     if self.__cancellable.is_cancelled():
         return
     helper = TaskHelper()
     # Fallback to link extraction
     if uris is None:
         self._label.set_text(_("Low quality, missing API key…"))
         uri = "https://www.google.fr/search?q=%s&tbm=isch" %\
             GLib.uri_escape_string(self.__get_current_search(), None, True)
         helper.load_uri_content(uri, self.__cancellable,
                                 self.__extract_links)
     # Populate the view
     elif uris:
         uri = uris.pop(0)
         helper.load_uri_content(uri, self.__cancellable, self.__add_pixbuf,
                                 self.__populate, uris)
     # Nothing to load, stop
     else:
         self._spinner.stop()
Ejemplo n.º 20
0
    def _on_btn_add_modify_clicked(self, widget):
        """
            Add/Modify a radio
            @param widget as Gtk.Widget
        """
        uri = self.__uri_entry.get_text()
        new_name = self.__name_entry.get_text()
        rename = self.__name != "" and self.__name != new_name

        if uri != "" and new_name != "":
            self.__stack.get_visible_child().hide()
            if rename:
                self.__radios_manager.rename(self.__name, new_name)
                Lp().art.rename_radio(self.__name, new_name)
            else:
                self.__radios_manager.add(new_name, uri.lstrip().rstrip())
            self.__stack.set_visible_child_name("spinner")
            self.__name = new_name
            uri = Lp().art.get_google_search_uri(self.__name + "+logo+radio")
            helper = TaskHelper()
            helper.load_uri_content(uri, self.__cancellable,
                                    self.__on_google_content_loaded)
            self.set_size_request(700, 400)