Beispiel #1
0
    def test_mixcloud(self):

        for f in glob.glob('*.mp3'):
            os.unlink(f)

        for f in glob.glob('*.m4a'):
            os.unlink(f)

        # shortest mix I could find that was still semi tolerable
        mp3_count = len(glob.glob1('', "*.mp3"))
        m4a_count = len(glob.glob1('', "*.m4a"))
        vargs = {
            'redownload':
            False,
            'folders':
            False,
            'group':
            False,
            'track':
            '',
            'num_tracks':
            9223372036854775807,
            'bandcamp':
            False,
            'downloadable':
            False,
            'likes':
            False,
            'open':
            False,
            'artist_url':
            'https://www.mixcloud.com/Bobby_T_FS15/coffee-cigarettes-saturday-morning-hip-hop-fix/'
        }
        process_mixcloud(vargs)
        new_mp3_count = len(glob.glob1('', "*.mp3"))
        new_m4a_count = len(glob.glob1('', "*.m4a"))
        self.assertTrue((new_mp3_count > mp3_count)
                        or (new_m4a_count > m4a_count))

        for f in glob.glob('*.mp3'):
            os.unlink(f)

        for f in glob.glob('*.m4a'):
            os.unlink(f)
Beispiel #2
0
    def test_mixcloud(self):

        for f in glob.glob('*.mp3'):
           os.unlink(f)

        for f in glob.glob('*.m4a'):
           os.unlink(f)

        # shortest mix I could find that was still semi tolerable
        mp3_count = len(glob.glob1('', "*.mp3"))
        m4a_count = len(glob.glob1('', "*.m4a"))
        vargs = {'folders': False, 'group': False, 'track': '', 'num_tracks': 9223372036854775807, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://www.mixcloud.com/Bobby_T_FS15/coffee-cigarettes-saturday-morning-hip-hop-fix/'}
        process_mixcloud(vargs)
        new_mp3_count = len(glob.glob1('', "*.mp3"))
        new_m4a_count = len(glob.glob1('', "*.m4a"))
        self.assertTrue((new_mp3_count > mp3_count) or (new_m4a_count > m4a_count))
        
        for f in glob.glob('*.mp3'):
           os.unlink(f)

        for f in glob.glob('*.m4a'):
           os.unlink(f)
Beispiel #3
0
    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)