def stream(self, request, response): song = Song.from_export(json.loads(request.query['song'][0]), self.client.connection) if song.id in self._cache['streams']: stream, cache = self._cache['streams'][song.id] else: stream = song.stream cache = Cache(stream.data, stream.size) self._cache['streams'][song.id] = stream, cache if 'Range' in request.headers: response.status = 206 start_byte, end_byte = request.headers['Range'].replace('bytes=', '').split('-') if start_byte: start_byte = int(start_byte) else: start_byte = 0 if end_byte: end_byte = int(end_byte) else: end_byte = stream.size cache.offset = start_byte if 'download' in request.query: response.headers['Content-Disposition'] = 'attachment; filename="{} - {} - {}.mp3"'.format(song.name, song.album.name, song.artist.name) response.headers['Accept-Ranges'] = 'bytes' response.headers['Content-Type'] = stream.data.info()['Content-Type'] response.headers['Content-Length'] = str(stream.size) response.headers['Content-Range'] = 'bytes {}-{}/{}'.format(start_byte, end_byte, stream.size) response.body = FileWrapper(cache) else: cache.reset() if 'download' in request.query: response.headers['Content-Disposition'] = 'attachment; filename="{} - {} - {}.mp3"'.format(song.name, song.album.name, song.artist.name) response.headers['Accept-Ranges'] = 'bytes' response.headers['Content-Type'] = stream.data.info()['Content-Type'] response.headers['Content-Length'] = str(stream.size) response.body = FileWrapper(cache)
def stream(request): song = Song.from_export(json.loads(request.GET['song']), client.connection) if song.id in _cache['streams']: stream, cache = _cache['streams'][song.id] else: stream = song.stream cache = Cache(stream.data, stream.size) _cache['streams'][song.id] = stream, cache response = HttpResponse() if 'HTTP_RANGE' in request.META: response.status = 206 start_byte, end_byte = request.META['HTTP_RANGE'].replace( 'bytes=', '').split('-') if start_byte: start_byte = int(start_byte) else: start_byte = 0 if end_byte: end_byte = int(end_byte) else: end_byte = stream.size cache.offset = start_byte if 'download' in request.GET: response[ 'Content-Disposition'] = 'attachment; filename="{} - {} - {}.mp3"'.format( song.name, song.album.name, song.artist.name) response['Accept-Ranges'] = 'bytes' response['Content-Type'] = stream.data.info()['Content-Type'] response['Content-Length'] = str(stream.size) response['Content-Range'] = 'bytes {}-{}/{}'.format( start_byte, end_byte, stream.size) else: cache.reset() if 'download' in request.GET: response[ 'Content-Disposition'] = 'attachment; filename="{} - {} - {}.mp3"'.format( song.name, song.album.name, song.artist.name) response['Accept-Ranges'] = 'bytes' response['Content-Type'] = stream.data.info()['Content-Type'] response['Content-Length'] = str(stream.size) response.content = FileWrapper(cache) return response
def addSong(response, phoneNumber): song = Song.from_export(response, gsClient.connection) newSong = {"phoneNumber" : phoneNumber, "date" : datetime.datetime.utcnow(), "link" : song.stream.url, "songId" : song.id, "songName" :song.name, "duration" : song.duration, "artistName" : song.artist.name, "playlist" : "default", "serialized" : song.export()} songId = db.songs.insert(newSong) return str(songId)
def song(self): """ :class:`Song` object of next song to play """ song = self._connection.request('autoplayGetSong', {'weightModifierRange' : [-9,9], 'seedArtists' : dict([(artist, 'p') for artist in self._artists]), 'tagID' : self._radio, 'recentArtists' : self._recent_artists, 'songQueueID' : self._connection.session.queue, 'secondaryArtistWeightModifier' : 0.75, 'country' : self._connection.session.country, 'seedArtistWeightRange' : [110,130], 'songIDsAlreadySeen' : self._songs_already_seen, 'maxDuration' : 1500, 'minDuration' : 60, 'frowns' : []}, self._connection.header('autoplayGetSong', 'jsqueue'))[1] return Song(song['SongID'], song['SongName'], song['ArtistID'], song['ArtistName'], song['AlbumID'], song['AlbumName'], song['CoverArtUrl'], None, song['EstimateDuration'], None, self._connection)
def addSong(response, phoneNumber): song = Song.from_export(response, gsClient.connection) newSong = { "phoneNumber": phoneNumber, "date": datetime.datetime.utcnow(), "link": song.stream.url, "songId": song.id, "songName": song.name, "duration": song.duration, "artistName": song.artist.name, "playlist": "default", "serialized": song.export() } songId = db.songs.insert(newSong) return str(songId)
def stream(request): song = Song.from_export(json.loads(request.GET['song']), client.connection) if song.id in _cache['streams']: stream, cache = _cache['streams'][song.id] else: stream = song.stream cache = Cache(stream.data, stream.size) _cache['streams'][song.id] = stream, cache response = HttpResponse() if 'HTTP_RANGE' in request.META: response.status = 206 start_byte, end_byte = request.META['HTTP_RANGE'].replace('bytes=', '').split('-') if start_byte: start_byte = int(start_byte) else: start_byte = 0 if end_byte: end_byte = int(end_byte) else: end_byte = stream.size cache.offset = start_byte if 'download' in request.GET: response['Content-Disposition'] = 'attachment; filename="{} - {} - {}.mp3"'.format(song.name, song.album.name, song.artist.name) response['Accept-Ranges'] = 'bytes' response['Content-Type'] = stream.data.info()['Content-Type'] response['Content-Length'] = str(stream.size) response['Content-Range'] = 'bytes {}-{}/{}'.format( start_byte, end_byte, stream.size) else: cache.reset() if 'download' in request.GET: response['Content-Disposition'] = 'attachment; filename="{} - {} - {}.mp3"'.format(song.name, song.album.name, song.artist.name) response['Accept-Ranges'] = 'bytes' response['Content-Type'] = stream.data.info()['Content-Type'] response['Content-Length'] = str(stream.size) response.content = FileWrapper(cache) return response
def stream(self, request, response): song = Song.from_export(json.loads(request.query['song'][0]), self.client.connection) if song.id in self._cache['streams']: stream, cache = self._cache['streams'][song.id] else: stream = song.stream cache = Cache(stream.data, stream.size) self._cache['streams'][song.id] = stream, cache if 'Range' in request.headers: response.status = 206 start_byte, end_byte = request.headers['Range'].replace( 'bytes=', '').split('-') if start_byte: start_byte = int(start_byte) else: start_byte = 0 if end_byte: end_byte = int(end_byte) else: end_byte = stream.size cache.offset = start_byte if 'download' in request.query: response.headers[ 'Content-Disposition'] = 'attachment; filename="{} - {} - {}.mp3"'.format( song.name, song.album.name, song.artist.name) response.headers['Accept-Ranges'] = 'bytes' response.headers['Content-Type'] = stream.data.info( )['Content-Type'] response.headers['Content-Length'] = str(stream.size) response.headers['Content-Range'] = 'bytes {}-{}/{}'.format( start_byte, end_byte, stream.size) response.body = FileWrapper(cache) else: cache.reset() if 'download' in request.query: response.headers[ 'Content-Disposition'] = 'attachment; filename="{} - {} - {}.mp3"'.format( song.name, song.album.name, song.artist.name) response.headers['Accept-Ranges'] = 'bytes' response.headers['Content-Type'] = stream.data.info( )['Content-Type'] response.headers['Content-Length'] = str(stream.size) response.body = FileWrapper(cache)
def download_musics(request): musicas = json.loads(request.GET.get('musicas', '[]')) if musicas: client = Client() client.init() musics_list = [] for musica in musicas: song = Song.from_export(musica, client.connection) musics_list.append(song) zip_path = download_music_temp_file(musics_list) response = HttpResponse(FileWrapper(file(zip_path)), content_type='application/zip', mimetype="application/zip") response['Content-Disposition'] = 'attachment; filename=myfile.zip' response['Content-Length'] = os.path.getsize(zip_path) return response else: raise Http404
def stream(self, request, response): song = Song.from_export(json.loads(request.query["song"][0]), self.client.connection) if song.id in self._cache["streams"]: stream, cache = self._cache["streams"][song.id] else: stream = song.stream cache = Cache(stream.data, stream.size) self._cache["streams"][song.id] = stream, cache if "Range" in request.headers: response.status = 206 start_byte, end_byte = request.headers["Range"].replace("bytes=", "").split("-") if start_byte: start_byte = int(start_byte) else: start_byte = 0 if end_byte: end_byte = int(end_byte) else: end_byte = stream.size cache.offset = start_byte if "download" in request.query: response.headers["Content-Disposition"] = 'attachment; filename="{} - {} - {}.mp3"'.format( song.name, song.album.name, song.artist.name ) response.headers["Accept-Ranges"] = "bytes" response.headers["Content-Type"] = stream.data.info()["Content-Type"] response.headers["Content-Length"] = str(stream.size) response.headers["Content-Range"] = "bytes {}-{}/{}".format(start_byte, end_byte, stream.size) response.body = FileWrapper(cache) else: cache.reset() if "download" in request.query: response.headers["Content-Disposition"] = 'attachment; filename="{} - {} - {}.mp3"'.format( song.name, song.album.name, song.artist.name ) response.headers["Accept-Ranges"] = "bytes" response.headers["Content-Type"] = stream.data.info()["Content-Type"] response.headers["Content-Length"] = str(stream.size) response.body = FileWrapper(cache)
def downloadSong(): song = Song.from_export(json.loads(request.form["song"]), gsClient.connection) song.download(song_name=song.id + "-" + request.form["phoneNumber"]) return song.id
def downloadSong(): song = Song.from_export(json.loads(request.form['song']), gsClient.connection) song.download(song_name=song.id + "-" + request.form['phoneNumber']) return song.id