Source

VPlayer / playliststorage.py

# -*- coding: utf-8 -*-

import re
import urllib
import urllib2
from math import ceil
from hashlib import md5


class ServerError(Exception):
    pass

class PlaylistStorage:
    def __init__(self):
        self.url = 'http://vkontakte.ru/notes.php'
        sets = QtCore.QSettings()
        cookies = unicode(settings.value('cookies', QtCore.QVariant('')).toString())
        self.headers = {'User-agent': 'Mozilla/5.0 (X11; U;\
                         Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko,\
                         Safari/419.3) Arora/0.6',
                        'Cookie': self.cookies }

    def get_hash(self):
        url = 'http://vkontakte.ru/notes.php?act=new'
        req = urllib2.Request(url, headers = self.headers)
        urlreq = urllib2.urlopen(req)
        page = urlreq.read()
        results = re.findall('<input type="hidden" name="hash" id="hash" value="([a-z0-9]*)">', page)
        if len(results) == 0:
            print page
            raise ServerError()
        self.hash = results[0]

    def save_new_playlist(self):
        data = {}
        data['Post'] = "Playlist text"
        data['act'] = "add"
        data['commentable'] = 0
        data['hash'] = self.hash
        data['preview'] = 0
        data['title'] = "Playlist title"
        data['visible'] = 0
        post = urllib.urlencode(data)
        req = urllib2.Request(self.url, post, self.headers)
        urlreq = urllib2.urlopen(req)
        pagetext = urlreq.read()
        print pagetext

    def get_notes_list(self):
        url = 'http://vkontakte.ru/notes.php'
        headers = {'User-agent': 'Mozilla/5.0 (X11; U;\
                    Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko,\
                    Safari/419.3) Arora/0.6',
                    'Cookie': self.cookies }
        req = urllib2.Request(url, headers=headers)
        urlreq = urllib2.urlopen(req)
        page = urlreq.read()
        print re.findall("""<div class="note_title">[\n\t ]*<a href="([a-z0-9_]*)">([\w\d\ ]*)</a>[\n\t ]*</div>""", page)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.