Beispiel #1
0
def _intelli_resolve_song(obj):
    if isinstance(obj, Song):
        return {"url": obj.url, "id": obj.id}
    if isinstance(obj, (str, unicode)):
        if os.path.exists(obj):
            return {"url": obj}
        song_filename_by_id = songdb.getSongFilenameById(obj)
        if song_filename_by_id:
            return {"url": song_filename_by_id, "id": obj}
        songs = resolve_txt_song(obj, single=True)
        assert songs, "Did not find song %r" % obj
        obj = songs[0]
    assert isinstance(obj, dict), "Expected dict but got %r" % obj
    obj = obj.copy()
    if "url" in obj:
        if os.path.exists(obj["url"]):
            if "id" in obj: return {"url": obj["url"], "id": obj["id"]}
            return {"url": obj["url"]}
        if "id" not in obj:
            song_id = songdb.getSongId_viaUrl(obj["url"])
            obj["id"] = song_id
    if "id" in obj:
        song_filename_by_id = songdb.getSongFilenameById(obj["id"])
        assert song_filename_by_id, "Song id %r is invalid in %r" % (obj["id"],
                                                                     obj)
        assert os.path.exists(
            song_filename_by_id
        ), "Unexpected non-existing song %r" % song_filename_by_id
        return {"url": song_filename_by_id, "id": obj["id"]}
    assert False, "Cannot resolve song %r" % obj
Beispiel #2
0
def _intelli_resolve_song(obj):
	if isinstance(obj, Song):
		return {"url": obj.url, "id": obj.id}
	if isinstance(obj, (str, unicode)):
		if os.path.exists(obj):
			return {"url": obj}
		song_filename_by_id = songdb.getSongFilenameById(obj)
		if song_filename_by_id:
			return {"url": song_filename_by_id, "id": obj}
		songs = resolve_txt_song(obj, single=True)
		assert songs, "Did not find song %r" % obj
		obj = songs[0]
	assert isinstance(obj, dict), "Expected dict but got %r" % obj
	obj = obj.copy()
	if "url" in obj:
		if os.path.exists(obj["url"]):
			if "id" in obj: return {"url": obj["url"], "id": obj["id"]}
			return {"url": obj["url"]}
		if "id" not in obj:
			song_id = songdb.getSongId_viaUrl(obj["url"])
			obj["id"] = song_id
	if "id" in obj:
		song_filename_by_id = songdb.getSongFilenameById(obj["id"])
		assert song_filename_by_id, "Song id %r is invalid in %r" % (obj["id"], obj)
		assert os.path.exists(song_filename_by_id), "Unexpected non-existing song %r" % song_filename_by_id
		return {"url": song_filename_by_id, "id": obj["id"]}
	assert False, "Cannot resolve song %r" % obj
Beispiel #3
0
	def selectUrlById(self):
		assert self._useDb, "Song.selectUrl: need to use the songdb"
		id = getattr(self, "_id", None)
		assert id, "Song.selectUrl: need a song-id"
		import songdb
		url = songdb.getSongFilenameById(id)
		if url: self.url = url
		return url
Beispiel #4
0
	def selectUrlById(self):
		assert self._useDb, "Song.selectUrl: need to use the songdb"
		id = getattr(self, "_id", None)
		assert id, "Song.selectUrl: need a song-id"
		import songdb
		url = songdb.getSongFilenameById(id)
		if url: self.url = url
		return url