예제 #1
0
 def download_link(self) -> str:
     """ :returns: link where the file awaits to be downloaded """
     data = Request.get(self.url).content
     soup = BeautifulSoup(data, "html.parser")
     track_meta = json.loads(BandcampJSON(soup).generate()[0])
     if track_meta['trackinfo'][0]['file'] is None:
         raise ValueError("could not find mp3 in %s" % self.url)
     return "https:" + track_meta['trackinfo'][0]['file']['mp3-128']
예제 #2
0
    def parse(self, url: str, art: bool=True, lyrics: bool=False, debugging: bool=False) -> dict or None:
        """Requests the page, cherry picks album info

        :param url: album/track url
        :param art: if True download album art
        :param lyrics: if True fetch track lyrics
        :param debugging: if True then verbose output
        :return: album metadata
        """
        if debugging:
            logging.basicConfig(level=logging.DEBUG)

        try:
            response = requests.get(url, headers=self.headers)
        except requests.exceptions.MissingSchema:
            return None

        try:
            self.soup = BeautifulSoup(response.text, "lxml")
        except FeatureNotFound:
            self.soup = BeautifulSoup(response.text, "html.parser")

        logging.debug(" Generating BandcampJSON..")
        bandcamp_json = BandcampJSON(self.soup, debugging).generate()
        album_json = json.loads(bandcamp_json[0])
        embed_json = json.loads(bandcamp_json[1])
        page_json = json.loads(bandcamp_json[2])
        logging.debug(" BandcampJSON generated..")

        logging.debug(" Generating Album..")
        self.tracks = album_json['trackinfo']

        album_release = album_json['album_release_date']
        if album_release is None:
            album_release = album_json['current']['release_date']

        try:
            album_title = embed_json['album_title']
        except KeyError:
            album_title = album_json['trackinfo'][0]['title']

        try:
            label = page_json['item_sellers']['{}'.format(album_json['current']['selling_band_id'])]['name']
        except KeyError:
            label = None

        album = {
            "tracks": [],
            "title": album_title,
            "artist": embed_json['artist'],
            "label": label,
            "full": False,
            "art": "",
            "date": str(dt.strptime(album_release, "%d %b %Y %H:%M:%S GMT").year),
            "url":url
        }

        artist_url = album_json['url'].rpartition('/album/')[0]
        for track in self.tracks:
            if lyrics:
                track['lyrics'] = self.get_track_lyrics("{}{}#lyrics".format(artist_url, track['title_link']))
            if track['file'] is not None:
                track = self.get_track_metadata(track)
                album['tracks'].append(track)

        album['full'] = self.all_tracks_available()
        if art:
            album['art'] = self.get_album_art()

        logging.debug(" Album generated..")
        print("ALBUM URL:", album["url"])
        return album
예제 #3
0
    def parse(self, url: str, art: bool = True) -> dict or None:
        """Requests the page, cherry picks album info

        :param url: album/track url
        :param art: if True download album art
        :return: album metadata
        """
        try:
            response = requests.get(url)
        except requests.exceptions.MissingSchema:
            return None

        try:
            self.soup = BeautifulSoup(response.text, "lxml")
        except FeatureNotFound:
            self.soup = BeautifulSoup(response.text, "html.parser")

        logger.debug('\n\tBeautifulSoup: {}\n'.format(self.soup))

        bandcamp_json = BandcampJSON(self.soup).generate()
        album_json = json.loads(bandcamp_json[0])
        embed_json = json.loads(bandcamp_json[1])
        page_json = json.loads(bandcamp_json[2])

        self.tracks = album_json['trackinfo']

        album_release = album_json['album_release_date']
        if album_release is None:
            album_release = album_json['current']['release_date']

        try:
            album_title = embed_json['album_title']
        except KeyError:
            album_title = album_json['trackinfo'][0]['title']

        try:
            label = page_json['item_sellers']['{}'.format(
                album_json['current']['selling_band_id'])]['name']
        except KeyError:
            label = None

        album = {
            "tracks": [],
            "title": album_title,
            "artist": embed_json['artist'],
            "label": label,
            "full": False,
            "art": "",
            "date":
            str(dt.strptime(album_release, "%d %b %Y %H:%M:%S GMT").year)
        }

        for track in self.tracks:
            if track['file'] is not None:
                track = self.get_track_metadata(track)
                album['tracks'].append(track)

        album['full'] = self.all_tracks_available()
        if art:
            album['art'] = self.get_album_art()

        return album