def get_from_soundcloud(url, bitrate, extension, output, verbose): raise NotImplementedError('Not yet implemented') logger.info('fetching: {}'.format(url)) sc.process_soundcloud( make_args_dict(url, bitrate, extension, output, verbose)) # todo: change base audio if int(best_audio.bitrate[:-1]) < bitrate: raise BitrateException() if output: tempfile = os.path.join( output, make_safe('.'.join([best_audio.title, best_audio.extension]))) new_file = os.path.join( output, make_safe('.'.join([best_audio.title, extension]))) else: new_file = make_safe('.'.join([best_audio.title, extension])) tempfile = make_safe('.'.join([best_audio.title, best_audio.extension])) best_audio.download(filepath=tempfile, quiet=not (verbose > 1)) logger.debug('temp file created: {}'.format(tempfile)) logger.info('converting downloaded stream...') # todo: check on adding metadata from here AudioSegment.from_file(tempfile).export(new_file, format=args.extension, bitrate=args.bitrate).close() logger.debug('removing temp file: {}'.format(tempfile)) os.remove(tempfile) return new_file
def test_soundcloud(self): for f in glob.glob('*.mp3'): os.unlink(f) mp3_count = len(glob.glob1('', "*.mp3")) vargs = { 'folders': False, 'group': False, 'track': '', 'num_tracks': 9223372036854775807, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://soundcloud.com/bxsswxrshp/the-king-is-dead-and-i-couldnt-be-happier' } process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) for f in glob.glob('*.mp3'): os.unlink(f)
def test_soundcloud(self): for f in glob.glob('*.mp3'): os.unlink(f) mp3_count = len(glob.glob1('', "*.mp3")) vargs = { 'folders': False, 'group': False, 'track': '', 'num_tracks': 9223372036854775807, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://soundcloud.com/bxsswxrshp/astronauts-etc-sadie-x-wxrhp-remix' } process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) for f in glob.glob('*.mp3'): os.unlink(f)
def test_soundcloud_hard(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': 1, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'puptheband', 'keep': False } process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) self.assertTrue( new_mp3_count == 1 ) # This used to be 3, but is now 'Not available in United States.' for f in glob.glob('*.mp3'): os.unlink(f)
def test_soundcloud(self): rm_mp3() mp3_count = len(glob.glob1('', "*.mp3")) vargs = {'path':'', 'folders': False, 'group': False, 'track': '', 'num_tracks': 9223372036854775807, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://soundcloud.com/fzpz/revised', 'keep': True} process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) rm_mp3()
def test_soundcloud_hard_2(self): rm_mp3() mp3_count = len(glob.glob1('', "*.mp3")) vargs = {'path':'', 'folders': False, 'group': False, 'track': '', 'num_tracks': 1, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://soundcloud.com/lostdogz/snuggles-chapstick', 'keep': False} process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) self.assertTrue(new_mp3_count == 1) # This used to be 3, but is now 'Not available in United States.' rm_mp3()
def test_soundcloud(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, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://soundcloud.com/fzpz/revised', 'keep': True} process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) for f in glob.glob('*.mp3'): os.unlink(f)
def test_soundcloud(self): for f in glob.glob('*.mp3'): os.unlink(f) mp3_count = len(glob.glob1('', "*.mp3")) vargs = {'folders': False, 'group': False, 'track': '', 'num_tracks': 9223372036854775807, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://soundcloud.com/bxsswxrshp/the-king-is-dead-and-i-couldnt-be-happier'} process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) for f in glob.glob('*.mp3'): os.unlink(f)
def test_soundcloud_hard(self): for f in glob.glob('*.mp3'): os.unlink(f) mp3_count = len(glob.glob1('', "*.mp3")) vargs = {'folders': False, 'group': False, 'track': '', 'num_tracks': 9223372036854775807, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'puptheband'} process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) for f in glob.glob('*.mp3'): os.unlink(f)
def sc_download(url_playlist: str, path: str) -> list: args_sc = { 'artist_url': url_playlist, 'path': path, 'track': None, 'keep': False, 'folders': False, 'num_tracks': sys.maxsize, 'downloadable': False, 'open': False } sc.process_soundcloud(args_sc)
def test_soundcloud_hard(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': 1, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'puptheband', 'keep': False} process_soundcloud(vargs) new_mp3_count = len(glob.glob1('', "*.mp3")) self.assertTrue(new_mp3_count > mp3_count) self.assertTrue(new_mp3_count == 1) # This used to be 3, but is now 'Not available in United States.' for f in glob.glob('*.mp3'): os.unlink(f)
def test_soundcloud_wav(self): for f in glob.glob('*.wav'): os.unlink(f) wav_count = len(glob.glob1('', "*.wav")) vargs = {'path':'', 'folders': False, 'group': False, 'track': '', 'num_tracks': 1, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'https://soundcloud.com/coastal/major-lazer-aerosol-can-coastal-flip', 'keep': False} process_soundcloud(vargs) new_wav_count = len(glob.glob1('', "*.wav")) self.assertTrue(new_wav_count > wav_count) self.assertTrue(new_wav_count == 1) for f in glob.glob('*.wav'): os.unlink(f)
import soundscrape from soundscrape.soundscrape import process_soundcloud client = soundcloud.Client(client_id='175c043157ffae2c6d5fed16c3d95a4c') #print("Welcome to SoundScraper Pro. \nBuilt on Miserlou's SoundScrape at https://github.com/Miserlou/SoundScrape. \nBy dallen4 @ https://github.com/dallen4.") #USERNAME = raw_input("What is the username of the artist you are looking for (as appears in the URL on their page)?\n") # userTracks = client.get('/users/brianfresco/tracks') # for track in userTracks: # trackURI = track.uri # track_info = client.get(trackURI) # trackTitle = track_info.title # print (trackTitle) #Download track from SoundCloud Example vargs = { 'path': '', 'folders': False, 'group': False, 'track': 'miracle-prod-mano', 'num_tracks': 1, 'bandcamp': False, 'downloadable': False, 'likes': False, 'open': False, 'artist_url': 'brianfresco', 'keep': False } process_soundcloud(vargs)
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)
async def run(self, msg: dict, bot) -> None: content_type, chat_type, chat_id = glance(msg) m_id = msg['message_id'] args = msg['text'].split(' ')[1:] if len(args) < 1: # reply = "You must specify a YouTube or SoundCloud URL." reply = "You must specify a URL." await bot.sendMessage(chat_id, reply, reply_to_message_id=m_id) return url = args[0].replace('www.', '') url_p = up.urlparse(url) if not os.path.isdir('data/mediasnag'): os.mkdir('data/mediasnag') if url_p.netloc in ['youtube.com', 'youtu.be']: if url_p.netloc == 'youtu.be': v_id = url_p.path[1:] else: v_id = up.parse_qs(url_p.query)['v'][0] found = glob.glob('data/mediasnag/youtube/*-{}.mp3'.format(v_id)) if len(found) == 0: bot._dbg('Snagging audio from {}...'.format(v_id), tag='PLUGIN', level=2) await bot.sendMessage(chat_id, 'One sec, I gotta snag it first.', reply_to_message_id=m_id) with youtube_dl.YoutubeDL(self._ydl_opts) as ydl: ydl.download([url]) fn = glob.glob('data/mediasnag/youtube/*-{}.mp3'.format(v_id))[0] self._dbg('Sending audio...', tag='PLUGIN', level=2) else: bot._dbg('Sending cached audio for {}...'.format(v_id), tag='PLUGIN', level=2) await bot.sendMessage(chat_id, 'Already snagged that one. Lemme send it.', reply_to_message_id=m_id) fn = found[0] title = os.path.basename(fn).replace('-{}.mp3'.format(v_id), '') await bot.sendChatAction(chat_id, 'upload_audio') with open(fn, 'rb') as f: await bot.sendAudio(chat_id, f, title=title, reply_to_message_id=m_id) elif url_p.netloc == 'soundcloud.com': ss_opts = self._ss_opts.copy() ss_opts['artist_url'] = url a_id = url_p.path.split('/')[1] t_id = url_p.path.split('/')[-1] fbase = t_id.replace('-', ' - ').title() fname = 'data/mediasnag/soundcloud/{0}/{0} - {1}.mp3'.format(a_id, fbase) if os.path.isfile(fname): bot._dbg() bot._dbg('Sending cached audio for {}/{}...'.format(a_id, t_id), tag='PLUGIN', level=2) await bot.sendMessage(chat_id, 'Already snagged that one. Lemme send it.', reply_to_message_id=m_id) await bot.sendChatAction(chat_id, 'upload_audio') with open(fname, 'rb') as f: await bot.sendAudio(chat_id, f, title=fbase, reply_to_message_id=m_id) else: bot._dbg('Snagging audio from {}/{}...'.format(a_id, t_id), tag='PLUGIN', level=2) await bot.sendMessage(chat_id, 'One sec, I gotta snag it first.', reply_to_message_id=m_id) soundscrape.process_soundcloud(ss_opts) shutil.move(a_id, 'data/mediasnag/soundcloud/') await bot.sendChatAction(chat_id, 'upload_audio') with open(fname, 'rb') as f: await bot.sendAudio(chat_id, f, title=fbase, reply_to_message_id=m_id) else: # reply = "You must specify a YouTube or SoundCloud URL." reply = "You must specify a YouTube URL." await bot.sendMessage(chat_id, reply, reply_to_message_id=m_id)