Beispiel #1
0
  def _add_song(self, name=None, artist=None):
    listener = Listener()
    if name is None:
      name = listener.get_input("Song title")
    if artist is None:
      artist = listener.get_input("Artist")

    query_string = urllib.parse.urlencode({"search_query" : artist + " " +name})
    html_content = urllib.request.urlopen("http://www.youtube.com/results?" +
    query_string)
    search_results = re.findall(r'href=\"\/watch\?v=(.{11})',
    html_content.read().decode())

    top_result = "http://www.youtube.com/watch?v=" + search_results[0]

    song = Song(name, top_result, artist=artist)
    song.create()
    print(song.title + " by " + song.artist + " added")
    return song
Beispiel #2
0
    def _add_song(self, name=None, artist=None):
        listener = Listener()
        if name is None:
            name = listener.get_input("Song title")
        if artist is None:
            artist = listener.get_input("Artist")

        query_string = urllib.parse.urlencode(
            {"search_query": artist + " " + name})
        html_content = urllib.request.urlopen(
            "http://www.youtube.com/results?" + query_string)
        search_results = re.findall(r'href=\"\/watch\?v=(.{11})',
                                    html_content.read().decode())

        top_result = "http://www.youtube.com/watch?v=" + search_results[0]

        song = Song(name, top_result, artist=artist)
        song.create()
        print(song.title + " by " + song.artist + " added")
        return song