-retrait de ICapCollection -correction du fonctionnement de get_video pour gérer les id à la place d'objets video

Signed-off-by: Bezleputh <carton_ben@yahoo.fr>
This commit is contained in:
Bezleputh 2013-05-13 22:01:29 +02:00 committed by Florent
commit d2724577c8
2 changed files with 14 additions and 12 deletions

View file

@ -20,12 +20,11 @@
from weboob.tools.backend import BaseBackend
from weboob.capabilities.video import ICapVideo, BaseVideo
from weboob.capabilities.collection import ICapCollection
from .browser import GroovesharkBrowser
__all__ = ['GroovesharkBackend']
class GroovesharkBackend(BaseBackend, ICapVideo, ICapCollection):
class GroovesharkBackend(BaseBackend, ICapVideo):
NAME = 'grooveshark'
DESCRIPTION = u'grooveshark website'
MAINTAINER = u'Bezleputh'
@ -48,8 +47,8 @@ class GroovesharkBackend(BaseBackend, ICapVideo, ICapCollection):
for video in self.browser.search_videos(pattern, max_results):
yield video
def get_video(self, video):
def get_video(self, _id):
with self.browser:
return self.browser.fill_stream_list(video)
return self.browser.get_video_from_song_id(_id)
OBJECTS = {BaseVideo: fill_video}

View file

@ -28,7 +28,6 @@ import string
import random
import datetime
__all__ = ['GroovesharkBrowser']
@ -60,6 +59,8 @@ class GroovesharkBrowser(BaseBrowser):
GROOVESHARK_CONSTANTS = ('mobileshark', '20120830', 'gooeyFlubber')
COMMUNICATION_TOKEN = None
VIDEOS_FROM_SONG_RESULTS = None
def home(self):
self.get_communication_token()
@ -81,8 +82,7 @@ class GroovesharkBrowser(BaseBrowser):
return songs
def create_video_from_songs_result(self, songs, max_results):
videos = []
self.VIDEOS_FROM_SONG_RESULTS = []
if max_results:
songs = songs[0:max_results]
@ -98,8 +98,8 @@ class GroovesharkBrowser(BaseBrowser):
video.date = datetime.date(year=int(song['Year']), month=1, day=1)
except ValueError:
video.date = NotAvailable
videos.append(video)
return videos
self.VIDEOS_FROM_SONG_RESULTS.append(video)
return self.VIDEOS_FROM_SONG_RESULTS
def create_video_from_playlist_result(self, playlists):
videos = []
@ -132,9 +132,12 @@ class GroovesharkBrowser(BaseBrowser):
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()
def fill_stream_list(self, video):
if isinstance(video, BaseVideo):
video.url = self.get_stream_url_from_song_id(video.id)
def get_video_from_song_id(self, song_id):
if self.VIDEOS_FROM_SONG_RESULTS:
for video in self.VIDEOS_FROM_SONG_RESULTS:
if video.id == song_id:
video.url = self.get_stream_url_from_song_id(song_id)
return video
def get_stream_url_from_song_id(self, song_id):
method = 'getStreamKeyFromSongIDEx'