cleanup
This commit is contained in:
parent
6eedb3a396
commit
37b94a79f2
3 changed files with 12 additions and 43 deletions
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.capabilities.radio import ICapRadio, Radio, Stream, Emission
|
||||
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||
from weboob.capabilities.collection import ICapCollection
|
||||
from .browser import GroovesharkBrowser
|
||||
|
|
|
|||
|
|
@ -20,22 +20,22 @@
|
|||
from weboob.tools.browser import BaseBrowser
|
||||
from weboob.tools.json import json as simplejson
|
||||
from weboob.capabilities.video import BaseVideo
|
||||
from weboob.capabilities import NotAvailable
|
||||
from weboob.tools.capabilities.thumbnail import Thumbnail
|
||||
import urllib2
|
||||
import hashlib
|
||||
import uuid
|
||||
import string
|
||||
import random
|
||||
import datetime
|
||||
from .pages import IndexPage
|
||||
|
||||
|
||||
__all__ = ['GroovesharkBrowser']
|
||||
|
||||
|
||||
class APIError(Exception):
|
||||
pass
|
||||
|
||||
class GroovesharkBrowser(BaseBrowser):
|
||||
|
||||
PROTOCOL = 'http'
|
||||
DOMAIN = 'html5.grooveshark.com'
|
||||
#SAVE_RESPONSE = True
|
||||
|
|
@ -59,14 +59,8 @@ class GroovesharkBrowser(BaseBrowser):
|
|||
#those values depends on a grooveshark version and may change
|
||||
GROOVESHARK_CONSTANTS = ('mobileshark', '20120830', 'gooeyFlubber')
|
||||
COMMUNICATION_TOKEN = None
|
||||
|
||||
PAGES = {
|
||||
'http://html5.grooveshark.com/.*': IndexPage,
|
||||
}
|
||||
|
||||
def home(self):
|
||||
self.location('/');
|
||||
assert self.is_on_page(IndexPage)
|
||||
self.get_communication_token()
|
||||
|
||||
def search_videos(self, pattern, max_results):
|
||||
|
|
@ -100,8 +94,11 @@ class GroovesharkBrowser(BaseBrowser):
|
|||
video.thumbnail = Thumbnail(u'http://images.gs-cdn.net/static/albums/40_' + song['CoverArtFilename'])
|
||||
video.duration = datetime.timedelta(seconds=int(float(song['EstimateDuration'])))
|
||||
video.rating = float(song['AvgRating'])
|
||||
video.date = datetime.date(year=int(song['Year']), month=1, day=1)
|
||||
videos.append(video)
|
||||
try:
|
||||
video.date = datetime.date(year=int(song['Year']), month=1, day=1)
|
||||
except ValueError:
|
||||
video.date = NotAvailable
|
||||
videos.append(video)
|
||||
return videos
|
||||
|
||||
def create_video_from_playlist_result(self, playlists):
|
||||
|
|
@ -129,9 +126,8 @@ class GroovesharkBrowser(BaseBrowser):
|
|||
self.COMMUNICATION_TOKEN = result['result']
|
||||
|
||||
def create_token(self, method):
|
||||
|
||||
if self.COMMUNICATION_TOKEN is None:
|
||||
self.get_communication_token()
|
||||
self.get_communication_token()
|
||||
|
||||
rnd = (''.join(random.choice(string.hexdigits) for x in range(6)))
|
||||
return rnd + hashlib.sha1('%s:%s:%s:%s' % (method, self.COMMUNICATION_TOKEN, self.GROOVESHARK_CONSTANTS[2], rnd)).hexdigest()
|
||||
|
|
@ -179,8 +175,8 @@ class GroovesharkBrowser(BaseBrowser):
|
|||
"""
|
||||
data = self.create_json_data(method, parameters, token)
|
||||
req = self.create_request(method)
|
||||
response = urllib2.urlopen(req, data)
|
||||
return self.parse_response(response)
|
||||
response = self.openurl(req, data)
|
||||
return self.parse_response(response)
|
||||
|
||||
def create_json_data(self, method, parameters, token):
|
||||
data = {}
|
||||
|
|
@ -194,7 +190,7 @@ class GroovesharkBrowser(BaseBrowser):
|
|||
return simplejson.dumps(data)
|
||||
|
||||
def create_request(self, method):
|
||||
req = urllib2.Request('%s?%s' %(self.API_URL, method))
|
||||
req = self.request_class('%s?%s' %(self.API_URL, method))
|
||||
req.add_header('Content-Type', 'application/json')
|
||||
return req
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2013 Bezleputh
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
# weboob is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# weboob is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
__all__ = ['IndexPage']
|
||||
|
||||
class IndexPage(BasePage):
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue