Commits

A2K  committed e6f3079

Modified Search to work with new vkontakte's search page

  • Participants
  • Parent commits 4fabead

Comments (0)

Files changed (2)

                                {'tree-state': {'file-sort-method': 'by name',
         'list-files-first': False,
         'tree-states': {'deep': {'column-widths': [1.0],
-                                 'expanded-nodes': [(3,)],
-                                 'selected-nodes': [(30,)],
-                                 'top-node': (3,
-        22)}},
+                                 'expanded-nodes': [(4,)],
+                                 'selected-nodes': [(4,
+        8)],
+                                 'top-node': (7,)}},
         'tree-style': 'deep'}}),
                               ('pylintpanel#02EFWRQK9X24',
                                'tall',
         'top-node': [('class def',
                       loc('guicomponents/searchwidget.py'),
                       'CustomFilterProxyModel')]},
+        loc('guicomponents/trackinfowidget.py'): {'column-widths': [1.0],
+        'expanded-nodes': [],
+        'selected-nodes': [],
+        'top-node': [('class def',
+                      loc('guicomponents/trackinfowidget.py'),
+                      'TrackinfoWidget')]},
         loc('lastfm.py'): {'column-widths': [1.0],
                            'expanded-nodes': [],
                            'selected-nodes': [],
                          'top-node': [('generic attribute',
                                        loc('main.py'),
                                        'app')]},
-        u'All Classes': {'column-widths': [1.0],
-                         'expanded-nodes': [],
-                         'selected-nodes': [[('class def',
-        loc('gui.py'),
-        'MainWindow')]],
-                         'top-node': [('class def',
-                                       loc('collectionmodel.py'),
-                                       'ColRoot')]},
-        loc('guicomponents/trackinfowidget.py'): {'column-widths': [1.0],
-        'expanded-nodes': [],
-        'selected-nodes': [],
-        'top-node': [('class def',
-                      loc('guicomponents/trackinfowidget.py'),
-                      'TrackinfoWidget')]},
-        loc('minigui.py'): {'column-widths': [1.0],
-                            'expanded-nodes': [],
-                            'selected-nodes': [],
-                            'top-node': [('class def',
-        loc('minigui.py'),
-        'ComboModel')]},
         loc('minigui_qt.py'): {'column-widths': [1.0],
                                'expanded-nodes': [],
                                'selected-nodes': [],
                             'top-node': [('function def',
         loc('queries.py'),
         'add_album_cover')]},
+        loc('searchprocessor.py'): {'column-widths': [1.0],
+                                    'expanded-nodes': [],
+                                    'selected-nodes': [],
+                                    'top-node': [('class def',
+        loc('searchprocessor.py'),
+        'SearchProcessor')]},
+        loc('source.py'): {'column-widths': [1.0],
+                           'expanded-nodes': [],
+                           'selected-nodes': [],
+                           'top-node': [('class def',
+        loc('source.py'),
+        'Source')]},
+        u'All Classes': {'column-widths': [1.0],
+                         'expanded-nodes': [],
+                         'selected-nodes': [[('class def',
+        loc('gui.py'),
+        'MainWindow')]],
+                         'top-node': [('class def',
+                                       loc('collectionmodel.py'),
+                                       'ColRoot')]},
+        loc('minigui.py'): {'column-widths': [1.0],
+                            'expanded-nodes': [],
+                            'selected-nodes': [],
+                            'top-node': [('class def',
+        loc('minigui.py'),
+        'ComboModel')]},
         loc('resultsmodel.py'): {'column-widths': [1.0],
                                  'expanded-nodes': [],
                                  'selected-nodes': [],
                            'top-node': [('class def',
         loc('search.py'),
         'Search')]},
-        loc('searchprocessor.py'): {'column-widths': [1.0],
-                                    'expanded-nodes': [],
-                                    'selected-nodes': [],
-                                    'top-node': [('class def',
-        loc('searchprocessor.py'),
-        'SearchProcessor')]},
         loc('similarartistspopulator.py'): {'column-widths': [1.0],
         'expanded-nodes': [],
         'selected-nodes': [],
         'top-node': [('class def',
                       loc('similarartistspopulator.py'),
                       'SimilarArtistsPopulator')]},
-        loc('source.py'): {'column-widths': [1.0],
-                           'expanded-nodes': [],
-                           'selected-nodes': [],
-                           'top-node': [('class def',
-        loc('source.py'),
-        'Source')]},
         loc('tagreader.py'): {'column-widths': [1.0],
                               'expanded-nodes': [],
                               'selected-nodes': [],
                       'wide',
                       1,
                       {})],
-        'primary_view_state': {'editor_states': {'bookmarks': ([(loc('player_phonon.py'),
-        {'attrib-starts': [('Player',
-                            10),
-                           ('Player.stateChanged',
-                            61)],
-         'first-line': 55,
+        'primary_view_state': {'editor_states': {'bookmarks': ([(loc('resultsmodel.py'),
+        {'attrib-starts': [('ResultsModel',
+                            12),
+                           ('ResultsModel.data',
+                            38)],
+         'first-line': 0,
          'folded-linenos': [],
-         'sel-line': 69,
-         'sel-line-start': 2455,
-         'selection_end': 2480,
-         'selection_start': 2480},
-        1252243370.536998),
-        (loc('gui.py'),
-         {'attrib-starts': [('MainWindow',
-                             44),
-                            ('MainWindow.__init__',
-                             59)],
-          'first-line': 57,
-          'folded-linenos': [],
-          'sel-line': 72,
-          'sel-line-start': 1750,
-          'selection_end': 1807,
-          'selection_start': 1807},
-         1252243787.6845579),
-        (loc('options.py'),
-         {'attrib-starts': [('Options',
-                             14),
-                            ('Options.__init__',
-                             16),
-                            ('Options.__init__.conf',
-                             46)],
-          'first-line': 39,
-          'folded-linenos': [],
-          'sel-line': 58,
-          'sel-line-start': 2676,
-          'selection_end': 2729,
-          'selection_start': 2729},
-         1252243819.1332059),
-        (loc('shortcuts.py'),
-         {'attrib-starts': [('Shortcuts',
-                             15),
-                            ('Shortcuts.bind_keys',
-                             31)],
-          'first-line': 12,
-          'folded-linenos': [],
-          'sel-line': 34,
-          'sel-line-start': 1326,
-          'selection_end': 1342,
-          'selection_start': 1342},
-         1252249808.8433721),
-        (loc('logger.py'),
-         {'attrib-starts': [],
-          'first-line': 0,
-          'folded-linenos': [],
-          'sel-line': 4,
-          'sel-line-start': 57,
-          'selection_end': 278,
-          'selection_start': 57},
-         1252269021.4784141),
-        (loc('bufferer.py'),
-         {'attrib-starts': [],
-          'first-line': 0,
-          'folded-linenos': [],
-          'sel-line': 9,
-          'sel-line-start': 134,
-          'selection_end': 159,
-          'selection_start': 159},
-         1252269123.7557609),
-        (loc('bufferer.py'),
-         {'attrib-starts': [('Buffer',
-                             21),
-                            ('Buffer.run',
-                             41)],
-          'first-line': 48,
-          'folded-linenos': [],
-          'sel-line': 70,
-          'sel-line-start': 1841,
-          'selection_end': 2143,
-          'selection_start': 1841},
-         1252269130.199208),
-        (loc('resultsmodel.py'),
-         {'attrib-starts': [('ResultsModel',
-                             12),
-                            ('ResultsModel.data',
-                             38)],
-          'first-line': 0,
-          'folded-linenos': [],
-          'sel-line': 76,
-          'sel-line-start': 2581,
-          'selection_end': 2584,
-          'selection_start': 2584},
-         1252269277.8462591),
+         'sel-line': 76,
+         'sel-line-start': 2581,
+         'selection_end': 2584,
+         'selection_start': 2584},
+        1252269277.8462591),
         (loc('guicomponents/searchwidget.py'),
          {'attrib-starts': [('CustomFilterProxyModel',
                              54),
           'sel-line-start': 0,
           'selection_end': 0,
           'selection_start': 0},
-         1252272801.2649889]],
+         1252272801.2649889],
+        (loc('source_phonon.py'),
+         {'attrib-starts': [('Source',
+                             7),
+                            ('Source.seek',
+                             38)],
+          'first-line': 15,
+          'folded-linenos': [],
+          'sel-line': 40,
+          'sel-line-start': 1027,
+          'selection_end': 1057,
+          'selection_start': 1057},
+         1252955871.367425),
+        (loc('guicomponents/playlistwidget.py'),
+         {'attrib-starts': [('PlaylistWidget',
+                             13),
+                            ('PlaylistWidget.fill_with_tracks',
+                             232)],
+          'first-line': 46,
+          'folded-linenos': [],
+          'sel-line': 239,
+          'sel-line-start': 9890,
+          'selection_end': 9928,
+          'selection_start': 9928},
+         1252956583.3810329),
+        (loc('guicomponents/playlistwidget.py'),
+         {'attrib-starts': [('PlaylistWidget',
+                             13),
+                            ('PlaylistWidget.toggle_shuffle',
+                             183)],
+          'first-line': 198,
+          'folded-linenos': [],
+          'sel-line': 183,
+          'sel-line-start': 7375,
+          'selection_end': 7397,
+          'selection_start': 7383},
+         1252956594.933836),
+        (loc('guicomponents/playlistwidget.py'),
+         {'attrib-starts': [('PlaylistWidget',
+                             13),
+                            ('PlaylistWidget.status_receiver',
+                             345)],
+          'first-line': 321,
+          'folded-linenos': [],
+          'sel-line': 345,
+          'sel-line-start': 14171,
+          'selection_end': 14194,
+          'selection_start': 14179},
+         1252956608.6183441),
+        (loc('guicomponents/playlistwidget.py'),
+         {'attrib-starts': [('PlaylistWidget',
+                             13),
+                            ('PlaylistWidget.play_next',
+                             350)],
+          'first-line': 27,
+          'folded-linenos': [],
+          'sel-line': 350,
+          'sel-line-start': 14314,
+          'selection_end': 14331,
+          'selection_start': 14322},
+         1252956610.505022),
+        (loc('guicomponents/playlistwidget.py'),
+         {'attrib-starts': [('PlaylistWidget',
+                             13),
+                            ('PlaylistWidget.toggle_shuffle',
+                             183)],
+          'first-line': 159,
+          'folded-linenos': [],
+          'sel-line': 184,
+          'sel-line-start': 7405,
+          'selection_end': 7462,
+          'selection_start': 7462},
+         1252956639.7428551),
+        [loc('guicomponents/fileswidget.py'),
+         {'attrib-starts': [],
+          'first-line': 0,
+          'folded-linenos': [],
+          'sel-line': 0,
+          'sel-line-start': 0,
+          'selection_end': 0,
+          'selection_start': 0},
+         1253113718.167717]],
         19),
-        'current-loc': loc('Makefile'),
-        'editor-states': {loc('Makefile'): {'attrib-starts': [],
-        'first-line': 24,
-        'folded-linenos': [],
-        'sel-line': 57,
-        'sel-line-start': 1288,
-        'selection_end': 1319,
-        'selection_start': 1319},
-                          loc('bufferer.py'): {'attrib-starts': [('Buffer',
+        'current-loc': loc('guicomponents/fileswidget.py'),
+        'editor-states': {loc('bufferer.py'): {'attrib-starts': [('Buffer',
         21),
         ('Buffer.end',
          129)],
         'sel-line-start': 1750,
         'selection_end': 1807,
         'selection_start': 1807},
+                          loc('guicomponents/fileswidget.py'): {'attrib-star'\
+        'ts': [],
+        'first-line': 11,
+        'folded-linenos': [],
+        'sel-line': 0,
+        'sel-line-start': 0,
+        'selection_end': 0,
+        'selection_start': 0},
+                          loc('guicomponents/playlistwidget.py'): {'attrib-s'\
+        'tarts': [('PlaylistWidget',
+                   13),
+                  ('PlaylistWidget.toggle_shuffle',
+                   183)],
+        'first-line': 159,
+        'folded-linenos': [],
+        'sel-line': 184,
+        'sel-line-start': 7405,
+        'selection_end': 7462,
+        'selection_start': 7462},
                           loc('guicomponents/searchwidget.py'): {'attrib-sta'\
         'rts': [('CustomFilterProxyModel',
                  54),
         7),
         ('Source.seek',
          38)],
-        'first-line': 18,
+        'first-line': 15,
         'folded-linenos': [],
         'sel-line': 40,
         'sel-line-start': 1027,
         'selection_end': 1057,
         'selection_start': 1057}},
         'has-focus': True},
-                               'open_files': [u'source_phonon.py',
+                               'open_files': [u'bufferer.py',
+        u'common.py',
+        u'gui.py',
+        u'guicomponents/playlistwidget.py',
+        u'guicomponents/searchwidget.py',
+        u'logger.py',
+        u'options.py',
         u'player_phonon.py',
-        u'gui.py',
+        u'resultsmodel.py',
         u'shortcuts.py',
-        u'logger.py',
-        u'resultsmodel.py',
-        u'guicomponents/searchwidget.py',
-        u'common.py',
-        u'bufferer.py',
-        u'options.py',
-        u'Makefile']},
+        u'source_phonon.py',
+        u'guicomponents/fileswidget.py']},
         'split_percents': {0: 0.5},
         'splits': 2,
         'tab_location': 'top',
                          31,
                          1260,
                          934)}]}
-guimgr.recent-documents = [loc('Makefile'),
-                           loc('options.py'),
-                           loc('bufferer.py'),
-                           loc('common.py'),
-                           loc('guicomponents/searchwidget.py'),
-                           loc('resultsmodel.py'),
-                           loc('logger.py'),
-                           loc('shortcuts.py'),
-                           loc('gui.py'),
-                           loc('player_phonon.py'),
-                           loc('source_phonon.py')]
+guimgr.recent-documents = [loc('guicomponents/fileswidget.py')]
 guimgr.visual-state = {loc('../../.wingide3/pylintpanel.cfg'): {'attrib-star'\
         'ts': [],
         'first-line': 0,
         'sel-line-start': 889,
         'selection_end': 936,
         'selection_start': 936},
+                       loc('Makefile'): {'attrib-starts': [],
+        'first-line': 16,
+        'folded-linenos': [],
+        'sel-line': 57,
+        'sel-line-start': 1303,
+        'selection_end': 1319,
+        'selection_start': 1319},
                        loc('PlaylistsWindow.py'): {'attrib-starts': [],
         'first-line': 0,
         'folded-linenos': [],
         if not cookies:
             self.run = lambda:self.emit(QtCore.SIGNAL('status'), 'nologin')
             return
-        self.url = 'http://vkontakte.ru/audiosearch.php'
+        self.url = 'http://vkontakte.ru/gsearch.php'
         self.headers = {'User-agent': 'Mozilla/5.0 (X11; U; Linux; ' + \
                         'en-US) AppleWebKit/527+ (KHTML, like Gecko, ' + \
                         'Safari/419.3) Arora/0.6',
             self.track_count = 0
             self.page_count = 0
             self.last_page = -1
-        post = urllib.urlencode({ 'q': self.target })
+        post = urllib.urlencode({ 'section': 'audio', 'q': self.target })
         req = urllib2.Request(self.url, post, self.headers)
         try:
             urlreq = urllib2.urlopen(req)
             self.emit(QtCore.SIGNAL('status'), 'end')
             return
         pagetext = urlreq.read()
+        #print pagetext
         f = open('f.html', 'w')
         f.write(pagetext)
         f.close()
 
+        self.results = self._parse_page(pagetext)
+        self.emit(QtCore.SIGNAL('status'), 'end')
+        return self.results
+
         rx = re.compile('<div class="summary">[^\d]*(\d+).*</')
         rxres = rx.findall(pagetext)
         if len(rxres)>0:
             return []
 
     def _parse_page(self, text):
+        print 'parsing page...'
         tracks = []
-        rxa = re.compile('<b id="\w+\d+">([^<]*)</b>')
-        rxt = re.compile('<span id=\"[\w\d]*\">([^<]*)<')
-        artist = ''
-        title = ''
-        info = ''
-
-        def clean(string):
-            if string:
-                string = re.sub('\s+', ' ', string)
-                while string and string[-1] == ' ':
-                    string = string[:-1]
-                while string and string[0] == ' ':
-                    string = string[1:]
-            return string
-
-
-        for record in text.split('\n'):
-            if 'performer' in record:
-                artist = unicode(rxa.findall(record)[0], 'cp1251', 'replace')
-                artist = decode_entities(artist)
-                artist = clean(artist)
-                title = unicode(rxt.findall(record)[0], 'cp1251', 'replace')
-                title = decode_entities(title)
-                title = clean(title)
-            if 'operate' in record:
-                info = record[record.find('(')+1:record.find(')')]
-                info = info.split(',')
-                server = info[1]
-                user = info[2]
-                fname = info[3][1:-1]
-                length = info[4]
-                aid = int(info[0])
-                oid = int(info[2])
-                link = 'http://cs' + server + '.vkontakte.ru/u' + user \
-                + '/audio/' + fname + '.mp3'
-            if artist and title and length and link:
-                if int(length) == 0:
-                    continue
-                track = Track(artist, title, link, length, aid, oid)
-                tracks.append(track)
-                artist = title = link = ''
-                length = 0
+        import libxml2dom
+        dom = libxml2dom.parseString(text, html=1)
+        doc = dom.childNodes[0]
+        table = doc.getElementById('searchResults')
+        results = table.childNodes[0].childNodes[0].childNodes
+        rx = re.compile('return operate\((?P<audioid>\d+),(?P<server>\d+),(?P<user>\d+),\'(?P<filename>\w+)\',(?P<length>\d+)\)')
+        for node in results:
+            if node.name != 'div': continue
+            info = node.childNodes[1].childNodes[0].childNodes[0]
+            artist = info.childNodes[2].childNodes[0].childNodes[1].childNodes[0].data
+            title = info.childNodes[2].childNodes[0].childNodes[3].childNodes[0].data
+            operate = info.childNodes[0].childNodes[1].getAttribute('onclick')
+            data = rx.search(operate).groupdict()
+            link = 'http://cs' + data['server'] + '.vkontakte.ru/u' + data['user'] \
+                + '/audio/' + data['filename'] + '.mp3'
+            length = data['length']
+            track = Track(artist = artist, title = title, length = int(length),
+                          url = link)
+            tracks.append(track)
         return tracks
 
 
         if not cookies:
             self.run = lambda:self.emit(QtCore.SIGNAL('status'), 'nologin')
             return
-        self.url = 'http://vkontakte.ru/audiosearch.php'
+        self.url = 'http://vkontakte.ru/gsearch.php'
         self.headers = {'User-agent': 'Mozilla/5.0 (X11; U; Linux; ' + \
                         'en-US) AppleWebKit/527+ (KHTML, like Gecko, ' + \
                         'Safari/419.3) Arora/0.6',