Beispiel #1
0
 def get_artist(self, artist_id):
     url = self._api_url + "GetArtistById?id={id}".format(id=artist_id)
     try:
         res = requests.get(url, timeout=MAX_TIME_OUT)
     except ConnectionError:
         raise SourceNetworkError("Cannot connect to Navahang server.")
     except HTTPError:
         raise SourceNetworkError(
             "Cannot connect to Navahang server. (HTTPError)")
     musics = []
     albums = []
     data = res.json()
     for i in data['works']:
         if i['category'] == 'MP3':
             musics.append(
                 Music(id=i["post_id"],
                       title=self._reformat(i['song_name']),
                       artist=i['artist_name'],
                       image=i['image'],
                       source=Navahang,
                       download_url=i['high_quality']))
         elif i['category'] == 'Album':
             albums.append(
                 Music(id=i["albumId"],
                       title=self._reformat(i['song']),
                       artist=i['artist'],
                       image=i['playerimage'],
                       source=Navahang))
     return SearchResult(musics=musics,
                         albums=albums,
                         artists=[
                             Artist(full_name=data['name'],
                                    id=artist_id,
                                    source=Navahang)
                         ])
Beispiel #2
0
    def search(self, query):
        # type: (str) -> SearchResult
        try:
            res = requests.get(self._search_url.format(query=quote(query)),
                               timeout=MAX_TIME_OUT)
        except ConnectionError:
            raise SourceNetworkError("Cannot connect to Navahang server.")
        except HTTPError:
            raise SourceNetworkError(
                "Cannot connect to Navahang server. (HTTPError)")

        data = res.json()

        musics = []
        albums = []
        artists = []
        if 'MP3' in data:
            for i in data['MP3']:
                title, artist = i['title'].split(' – ')
                musics.append(
                    Music(id=int(i["id"]),
                          title=self._reformat(title),
                          artist=artist,
                          url=self._site_url + i['url'],
                          image=i['image'],
                          source=Navahang))

        if 'Artist' in data:
            for i in data['Artist']:
                artists.append(
                    Artist(id=int(i["id"]),
                           full_name=i['title'],
                           url=self._site_url + i['url'],
                           image=i['image'],
                           source=Navahang))

        if 'Album' in data:
            for i in data['Album']:
                try:
                    album, artist = i['title'].split(' – ')
                except:
                    album, artist = i['title'], None
                albums.append(
                    Album(id=int(i["id"]),
                          title=self._reformat(album),
                          artist=self._reformat(artist),
                          url=self._site_url + i['url'],
                          image=i['image'],
                          source=Navahang))

        return SearchResult(musics, albums, artists)
Beispiel #3
0
    def search(self, query):
        # type: (str) -> SearchResult
        try:
            res = requests.post(self._search_url,
                                data={
                                    "engine_key": self._engine_key,
                                    "q": query,
                                    "per_page": 50
                                },
                                timeout=MAX_TIME_OUT)
        except ConnectionError:
            raise SourceNetworkError("Cannot connect to bia2music server.")
        except HTTPError:
            raise SourceNetworkError(
                "Cannot connect to bia2music server. (HTTPError)")

        if res.status_code == 404:
            raise SearchResult(None, None, None)
        data = res.json()['records']['page']
        musics = []
        albums = []
        artists = []
        for i in data:
            if i['type'] == 'music':
                musics.append(
                    Music(id=i["music_id"],
                          title=self._reformat(i['title']),
                          artist=i['artist'],
                          url=i['url'],
                          image=i['image'],
                          source=Bia2))
            elif i['type'] == 'artist':
                artists.append(
                    Artist(id=i["artist_id"],
                           full_name=i['title'],
                           url=i['url'],
                           image=i['image'],
                           source=Bia2))
            elif i['type'] == '':
                title = self._split_album_title(i['title'])
                albums.append(
                    Album(id=i["url"].split('/')[-1],
                          title=self._reformat(title[0]),
                          artist=self._reformat(title[1]),
                          url=i['url'],
                          image=i['image'],
                          source=Bia2))

        return SearchResult(musics, albums, artists)
Beispiel #4
0
 def get_artist(self, artist_id):
     try:
         res = requests.post(self._api_url + "artist_data.php",
                             data={
                                 "user_id": 217604,
                                 "artist_id": artist_id,
                                 "is_iran": 1
                             },
                             timeout=MAX_TIME_OUT)
     except ConnectionError:
         raise SourceNetworkError("Cannot connect to MrTehran server.")
     except HTTPError:
         raise SourceNetworkError(
             "Cannot connect to MrTehran server. (HTTPError)")
     musics = []
     albums = []
     data = res.json()
     for i in data['all_tracks']:
         musics.append(
             Music(id=int(i["track_id"]),
                   title=self._reformat(i["track_title"]),
                   artist=i["track_artist"],
                   url=self._download_url + i["track_audio"],
                   image=self._download_url + i["track_thumbnail"],
                   source=MrTehran))
     for i in data['all_albums']:
         image = None
         if not i["track_artwork"] is None:
             image = self._download_url + i["track_artwork"]
         albums.append(
             Album(id=int(i["album_id"]),
                   title=self._reformat(i["album_title"]),
                   artist=i["album_artist"],
                   url=(self._site_url + "mp3/" + i["track_id"] + "/" +
                        i["track_artist"] + "/" +
                        i["track_title"]).lower().replace(" ", "-"),
                   image=image,
                   source=MrTehran))
     return SearchResult(
         musics=musics,
         albums=albums,
         artists=[
             Artist(full_name=data.get('artist_info').get('artist_name'),
                    id=data.get('artist_info').get('artist_id'),
                    source=MrTehran)
         ])
Beispiel #5
0
    def search(self, query):
        # type: (str) -> SearchResult
        try:
            res = requests.get(self._search_url.format(query=quote(query)),
                               timeout=MAX_TIME_OUT)
        except ConnectionError:
            raise SourceNetworkError("Cannot connect to RadioJavan server.")
        except HTTPError:
            raise SourceNetworkError(
                "Cannot connect to RadioJavan server. (HTTPError)")
        data = res.json()
        musics = []
        albums = []
        artists = []
        if 'mp3s' in data:
            for i in data['mp3s']:
                musics.append(
                    Music(id=int(i["id"]),
                          title=i['song'],
                          artist=i['artist'],
                          url=i['share_link'],
                          image=i['photo'],
                          source=RadioJavan,
                          download_url=i['link']))

        if 'artists' in data:
            for i in data['artists']:
                artists.append(
                    Artist(id=quote(i['name']),
                           full_name=i['name'],
                           image=i['photo'],
                           source=RadioJavan))

        if 'albums' in data:
            for i in data['albums']:
                albums.append(
                    Album(id=int(i["id"]),
                          title=self._reformat(i['album_album']),
                          artist=self._reformat(i['album_artist']),
                          url=i['share_link'],
                          image=i['photo'],
                          source=RadioJavan))

        return SearchResult(musics, albums, artists)
Beispiel #6
0
    def get_artist(self, artist_id):
        # type: (str) -> SearchResult
        try:
            res = requests.get(self._download_url +
                               "artist?query={id}".format(id=artist_id),
                               timeout=MAX_TIME_OUT)
        except ConnectionError:
            raise SourceNetworkError("Cannot connect to Next1 server.")
        except HTTPError:
            raise SourceNetworkError(
                "Cannot connect to Next1 server. (HTTPError)")
        musics = []
        albums = []
        data = res.json()
        if 'mp3s' in data:
            for i in data['mp3s']:
                musics.append(
                    Music(id=int(i["id"]),
                          title=i['song'],
                          artist=i['artist'],
                          url=i['share_link'],
                          image=i['photo'],
                          source=RadioJavan,
                          download_url=i['link']))

        if 'albums' in data:
            for i in data['albums']:
                albums.append(
                    Album(id=int(i["album_id"]),
                          title=self._reformat(i['album_album']),
                          artist=self._reformat(i['album_artist']),
                          url=i['album']['share_link'],
                          image=i['photo'],
                          source=RadioJavan))

        return SearchResult(musics=musics,
                            albums=albums,
                            artists=[
                                Artist(full_name=data['query'],
                                       id=artist_id,
                                       source=RadioJavan)
                            ])
Beispiel #7
0
    def search(self, query):
        # type: (str) -> SearchResult
        try:
            res = requests.post(self._search_url.format(query=quote(query)),
                                timeout=MAX_TIME_OUT)
        except ConnectionError:
            raise SourceNetworkError("Cannot connect to WikiSeda server.")
        except HTTPError:
            raise SourceNetworkError(
                "Cannot connect to WikiSeda server. (HTTPError)")
        data = res.json()
        musics = []
        albums = []
        artists = []
        for i in data:
            if i['type'] == 'song':
                musics.append(
                    Music(id=int(i["id"]),
                          title=self._reformat(i['songname']),
                          artist=i['artist'],
                          url=i['url'],
                          image=i['poster'],
                          source=WikiSeda,
                          download_url=i['mp3']))
            elif i['type'] == 'artist':
                artists.append(
                    Artist(id=int(i["id"]),
                           full_name=i['artist'],
                           url=i['url'],
                           image=i['poster'],
                           source=WikiSeda))
            elif i['type'] == 'album':
                albums.append(
                    Album(id=i["id"],
                          title=self._reformat(i['album']),
                          artist=self._reformat(i['artist']),
                          url=i['url'],
                          image=i['poster'],
                          source=WikiSeda))

        return SearchResult(musics, albums, artists)
Beispiel #8
0
 def get_album(self, album_id):
     # type: (int) -> SearchResult
     try:
         res = requests.get(self._download_url +
                            "mp3?id={id}".format(id=album_id),
                            timeout=MAX_TIME_OUT)
     except ConnectionError:
         raise SourceNetworkError("Cannot connect to Next1 server.")
     except HTTPError:
         raise SourceNetworkError(
             "Cannot connect to Next1 server. (HTTPError)")
     musics = []
     data = res.json()
     albums = []
     artist = [
         Artist(full_name=data['artist'], id=quote(data['artist']).lower())
     ]
     if 'album_tracks' in data:
         albums.append(
             Album(artist=data['album_artist'], title=data['album_album']))
         for i in data['album_tracks']:
             if i['type'] == 'mp3':
                 musics.append(
                     Music(id=i['id'],
                           title=self._reformat(i['song']),
                           artist=i['artist'],
                           url=i['share_link'],
                           image=i["photo"],
                           source=RadioJavan,
                           download_link=i['link']))
     else:
         if data['type'] == 'mp3':
             musics.append(
                 Music(id=data['id'],
                       title=self._reformat(data['song']),
                       artist=data['artist'],
                       url=data['share_link'],
                       image=data["photo"],
                       source=RadioJavan,
                       download_link=data['link']))
     return SearchResult(musics=musics, albums=albums, artists=artist)
Beispiel #9
0
    def get_artist(self, artist_id):
        # type: (int) -> SearchResult
        url = self._download_url + '/artist.xml?id={}'.format(artist_id)
        try:
            res = requests.get(url, timeout=MAX_TIME_OUT)
        except ConnectionError:
            raise SourceNetworkError("Cannot connect to bia2music server.")
        except HTTPError:
            raise SourceNetworkError(
                "Cannot connect to bia2music server. (HTTPError)")
        data = ElementTree.fromstring(res.content)[0]
        musics = []
        albums = []
        for i in range(len(data)):
            if data[i].tag == 'albums':
                for j in data[i]:
                    albums.append(
                        Album(id=int(j.get('id')),
                              title=self._reformat(j.get('title')),
                              artist=self._reformat(data.get("name")),
                              image=j.get('cover'),
                              source=Bia2))

            if data[i].tag == 'singles':
                for j in data[i]:
                    musics.append(
                        Music(id=int(j.get('id')),
                              title=self._reformat(j.get('title')),
                              artist=data.get("name"),
                              url=data.get('share_url'),
                              image=j.get('cover'),
                              source=Bia2))
        return SearchResult(musics=musics,
                            albums=albums,
                            artists=[
                                Artist(full_name=data.get("name"),
                                       id=artist_id,
                                       image=data.get("cover"),
                                       source=Bia2)
                            ])
Beispiel #10
0
 def get_artist(self, artist_id):
     # type: (int) -> SearchResult
     try:
         url = self._download_url + "getnewcases?signer_id={id}&lang=en".format(
             id=artist_id)
         res = requests.get(url, timeout=MAX_TIME_OUT)
     except ConnectionError:
         raise SourceNetworkError("Cannot connect to Next1 server.")
     except HTTPError:
         raise SourceNetworkError(
             "Cannot connect to Next1 server. (HTTPError)")
     musics = []
     albums = []
     data = res.json()
     for i in data['items']:
         if i['type'] == 'song':
             musics.append(
                 Music(id=int(i["id"]),
                       title=self._reformat(i['songname']),
                       artist=i['artist'],
                       url=i['url'],
                       image=i['poster'],
                       source=WikiSeda))
         elif i['type'] == 'album':
             albums.append(
                 Album(id=i["id"],
                       title=self._reformat(i['album']),
                       artist=self._reformat(i['artist']),
                       url=i['url'],
                       image=i['poster'],
                       source=WikiSeda))
     return SearchResult(musics=musics,
                         albums=albums,
                         artists=[
                             Artist(full_name=data['artist'][0]['artist'],
                                    image=data['artist'][0]['poster'],
                                    id=int(data['artist'][0]['id']))
                         ])
Beispiel #11
0
    def search(self, query):
        # type: (str) -> SearchResult
        try:
            res_tracks = requests.post(self._api_url +
                                       "main_search_tracks.php",
                                       data={
                                           "search_text": query,
                                           "page": 0,
                                           "is_iran": 1
                                       },
                                       timeout=MAX_TIME_OUT)
            res_albums = requests.post(self._api_url +
                                       "main_search_albums.php",
                                       data={
                                           "search_text": query,
                                           "page": 0,
                                           "is_iran": 1
                                       },
                                       timeout=MAX_TIME_OUT)
            res_artists = requests.post(self._api_url +
                                        "main_search_artists.php",
                                        data={
                                            "search_text": query,
                                            "page": 0
                                        },
                                        timeout=MAX_TIME_OUT)
        except ConnectionError:
            raise SourceNetworkError("Cannot connect to MrTehran server.")
        except HTTPError:
            raise SourceNetworkError(
                "Cannot connect to MrTehran server. (HTTPError)")

        data_tracks = res_tracks.json()
        data_albums = res_albums.json()
        data_artists = res_artists.json()

        musics = []
        albums = []
        artists = []
        for i in data_tracks:
            musics.append(
                Music(id=int(i["track_id"]),
                      title=self._reformat(i["track_title"]),
                      artist=i["track_artist"],
                      url=self._download_url + i["track_audio"],
                      image=self._download_url + i["track_thumbnail"],
                      source=MrTehran))

        for i in data_artists:
            image = None
            if not i["artist_thumbnail"] is None:
                image = self._download_url + i["artist_thumbnail"]
            artists.append(
                Artist(id=int(i["artist_id"]),
                       full_name=i["artist_name"],
                       url=self._site_url + "artist/" + i["artist_id"],
                       image=image,
                       source=MrTehran))

        for i in data_albums:
            image = None
            if not i["track_artwork"] is None:
                image = self._download_url + i["track_artwork"]
            albums.append(
                Album(id=int(i["album_id"]),
                      title=self._reformat(i["album_title"]),
                      artist=self._reformat(i["album_artist"]),
                      url=(self._site_url + "mp3/" + i["track_id"] + "/" +
                           i["track_artist"] + "/" +
                           i["track_title"]).lower().replace(" ", "-"),
                      image=image,
                      source=MrTehran))

        return SearchResult(musics, albums, artists)