コード例 #1
0
ファイル: test.py プロジェクト: MasterFocus/SoundScrape
    def test_audiomack(self):
        for f in glob.glob('*.mp3'):
            os.unlink(f)

        mp3_count = len(glob.glob1('', "*.mp3"))
        vargs = {
            'redownload': False,
            'folders': False,
            'group': False,
            'track': '',
            'num_tracks': 9223372036854775807,
            'bandcamp': False,
            'audiomack': True,
            'downloadable': False,
            'likes': False,
            'open': False,
            'artist_url':
            'https://www.audiomack.com/song/bottomfeedermusic/power'
        }
        process_audiomack(vargs)
        new_mp3_count = len(glob.glob1('', "*.mp3"))
        self.assertTrue(new_mp3_count > mp3_count)

        for f in glob.glob('*.mp3'):
            os.unlink(f)
コード例 #2
0
ファイル: test.py プロジェクト: brachna/SoundScrape
    def test_audiomack(self):
        for f in glob.glob('*.mp3'):
           os.unlink(f)

        mp3_count = len(glob.glob1('', "*.mp3"))
        vargs = {'path':'', 'folders': False, 'group': False, 'track': '', 'num_tracks': 9223372036854775807, 'bandcamp': False, 'audiomack': True, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://www.audiomack.com/song/bottomfeedermusic/power'}
        process_audiomack(vargs)
        new_mp3_count = len(glob.glob1('', "*.mp3"))
        self.assertTrue(new_mp3_count > mp3_count)

        for f in glob.glob('*.mp3'):
           os.unlink(f)
コード例 #3
0
ファイル: store.py プロジェクト: amoraroma/droptrack
    def download(self, url: str, callback: Callable = open_files):
        print('player.store.download from url {1} to self.tracks {0}'.format(
            self.tracks, url))
        components = urlparse(url)
        print('player.store.download url components {0}'.format(components))
        filename = None
        ytid = None

        trackinfo = self.tracklog[self.tracklog.url == url]
        if len(trackinfo) > 0:
            filename = str(trackinfo.filename.asobject[0])
            filepath = str(trackinfo.filepath.asobject[0])
            print('filename', filename)
            print('filepath', filepath)
            # found existing file, returning that skipping download
            if os.path.exists(filepath):
                return path.join(self.tracks, filename)
            trkid = int(trackinfo['id'])
        else:
            trkid = self.tracklog.index.max() + 1

        # download file from webapp
        if self.from_webapp(url):
            filename = path.basename(components.path)
            location = path.join(self.tracks, filename)
            command = ['curl', '-s', url, '--output', location]
            run(command, check=True)
            # this might also work in case curl is not available
            # self.download_from_webapp(url, location)
            mocp_enqueue(location)

        # soundscrape handlers
        elif 'soundcloud.com' in components.netloc:
            vargs = self.soundscrape_vargs(url)
            soundscrape.process_soundcloud(vargs)
        elif 'mixcloud.com' in components.netloc:
            vargs = self.soundscrape_vargs(url)
            soundscrape.process_mixcloud(vargs)
        elif 'audiomack.com' in components.netloc:
            vargs = self.soundscrape_vargs(url)
            soundscrape.process_audiomack(vargs)
        elif 'hive.co' in components.netloc:
            vargs = self.soundscrape_vargs(url)
            soundscrape.process_hive(vargs)
        elif 'musicbed.com' in components.netloc:
            vargs = self.soundscrape_vargs(url)
            soundscrape.process_musicbed(vargs)

        # youtube
        elif 'youtube.com' in components.netloc or 'youtu.be' in components.netloc:
            # command = ['youtube-dl', '-x', '-o', '{0}/%(title)s.%(ext)s'.format(self.tracks), '--audio-format', 'aac', url]
            # command = ['youtube-dl', '-x', '--audio-format', 'aac', '--get-filename', '-o', '{0}/%(title)s-%(id)s.%(ext)s'.format(self.tracks), url]
            command = [
                'youtube-dl', '-x', '--audio-format', 'mp3', '--audio-quality',
                '4', '-o', '{0}/%(title)s-%(id)s.%(ext)s'.format(self.tracks),
                url
            ]
            ytid = components.query.split('v=')[-1]
            print('    ytid =', ytid)
        else:
            raise PlayerError('not soundscrape nor bandcamp nor youtube')

        # find most recent download
        search_dir = self.tracks
        files = list(filter(os.path.isfile, glob.glob(search_dir + "/*")))
        print('files', files)
        if ytid is None:
            files.sort(key=lambda x: os.path.getmtime(x))
            print('files', files)
            # filename is most recent file in listing
            filename = path.basename(files[-1])
        else:
            # filename is the entry matching the youtube id
            # filename = files[files.index(ytid)]
            filenames = list([f for f in files if ytid in f])
            if len(filenames) > 0:
                print('ytid filename', filename)
                filename = filenames[0]
                print('ytid filename', filename)
                filename = filename.split('/')[-1]
                print('ytid filename', filename)
            else:
                filename = 'N/A'
                print('could not generate filename')

        # maybe better not to hardcode track
        row = [trkid, url, filename, self.tracks + filename, None, None, None]
        self.tracklog.loc[trkid] = row
        self.tracklog.to_csv(self.tracklog_filename, index=False)