def main(source_folder, destination_folder):
    dict_list = {}
    # folder = 'D:\Music Download\No Albumart'
    mt = MusicTools()
    for root, dirs, files in os.walk(source_folder):
        for name in files:
            dict_file = {}
            if name.endswith((".mp3")):
                logger.info(name)
                mp3 = eyed3.load(os.path.realpath(os.path.join(root, name)))
                # print ("File: {}".format(name))
                if mp3.tag:
                    if len(mp3.tag.images) != 0:
                        # print ("No AlbumArt")
                        logger.info(
                            'AlbumArt already present...moving the file to completion...'
                        )
                        shutil.move(
                            os.path.realpath(os.path.join(root, name)),
                            os.path.realpath(
                                os.path.join(destination_folder, name)))
                    else:
                        try:
                            image_link = mt.get_album_art(
                                mp3.tag.artist, mp3.tag.title)
                            imagedata = requests.get(image_link).content
                            mp3.tag.images.set(0, imagedata, "image/jpeg",
                                               u"Album Art")
                            mp3.tag.save()
                            logger.info(
                                "******************Albumart saved to {}*********************"
                                .format(name))
                            shutil.move(
                                os.path.realpath(os.path.join(root, name)),
                                os.path.realpath(
                                    os.path.join('destination_folder', name)))

                        except Exception as e:
                            logger.error(
                                "Error in getting AlbumArt. Won't be saved to Tag - {}"
                                .format(name))
                            logger.debug(e)
def main(max_song_download=Config.BILLBOARD_MAX_SONG_DOWNLOAD):
    global MAX_SONG_DOWNLOAD
    MAX_SONG_DOWNLOAD = max_song_download
    open(Config.BILLBOARD_DOWNLOAD_FAILED_FILE_NAME, 'w').close()
    song_list = get_chart_songs_to_download()
    if len(song_list.index)>0:
        mt = MusicTools()
        logger.info('Downloading {} songs...'.format(len(song_list)))
        for index, row in song_list.iterrows():
            song = mt.get_song_from_title(row['full_title'])
            if song:
                # pass
                logger.info(u"Song- title: {}".format(row['full_title']))
                status = mt.download_music(song.video_link, row['full_title'], is_quiet=True)
                # status = 1
                if status == 0:
                            mt.fix_id3(song)
                else:
                    logger.error(u"Downloading of {} failed. Moving to the next item...".format(row['full_title']))
                    with codecs.open(Config.BILLBOARD_DOWNLOAD_FAILED_FILE_NAME,encoding='utf-8', mode='a+') as f:
                        f.write("{}\n".format(row['full_title']))
            else:
                logger.error(u"No results found for {}. Moving to the next item...".format(row['full_title']))
                with codecs.open(Config.BILLBOARD_DOWNLOAD_FAILED_FILE_NAME,encoding='utf-8', mode='a+') as f:
                    f.write(u"{}\n".format(row['full_title']))
        logger.info('*************************Billboard Chart Download Finished***************************')
    else:
        logger.error("No Songs to be downloaded. Quiting...")
def get_chart_songs_to_download():
    logger.info('Getting charts from Billboard')
    billboard = Billboard()
    billboard_chart_df = billboard.get_concatenated_billboard_chart()
    logger.debug('Billboard chart length: {}'.format(len(billboard_chart_df.index)))
    logger.info('Checking for new songs from last download'.format(len(billboard_chart_df.index)))
    last_download_chart = pd.read_pickle(Config.BILLBOARD_LAST_DOWNLOAD)
    billboard_chart_df.to_pickle(Config.BILLBOARD_LAST_DOWNLOAD)
    mt = MusicTools()
    billboard_chart_df['old_matched_title'] = billboard_chart_df['full_title_stripped'].apply(lambda x: mt.closest_match(x,last_download_chart.full_title_stripped.values))
    billboard_chart_df = billboard_chart_df[billboard_chart_df['old_matched_title']=='No Match'].reset_index(drop=True)
    logger.info('Getting songs from iTunes library')
    itunes = iTunes()
    itunes_lib = itunes.get_itunes_lib_as_df()
    logger.debug('Itunes Lib length: {}'.format(len(itunes_lib.index)))
    logger.info('Finding out songs which are already in the library')
    billboard_chart_df['matched_title'] = billboard_chart_df['full_title_stripped'].apply(lambda x: mt.closest_match(x,itunes_lib.full_title_stripped.values))
    songs_not_in_lib = billboard_chart_df[billboard_chart_df['matched_title']=='No Match'].reset_index(drop=True)
    logger.debug('songs not in lib length: {}'.format(len(songs_not_in_lib.index)))
    global MAX_SONG_DOWNLOAD
    if MAX_SONG_DOWNLOAD < len(songs_not_in_lib.index):
        MAX_SONG_DOWNLOAD = len(songs_not_in_lib.index)+1
    return songs_not_in_lib.loc[:MAX_SONG_DOWNLOAD-1,:]
示例#4
0
 def walk_items_in_project(self):
     items = self.api.state['items']
     mt = MusicTools()
     result = 1
     song_list = []
     logger.info("Scanning and Downloading ToDoist List:{}".format(
         self.PROJECT_NAME))
     for item in items:
         song_dict = {}
         logger.debug(u"Scanning {}|{}".format(item['content'], item['id']))
         if ((item['project_id'] == self.find_project_id_by_name(
                 self.PROJECT_NAME)) &
             (item['checked'] == 0)):  #For Debug  & (item['id']==112286022)
             #print(item['content'] + "|" + str(item['id']))
             song_dict = self.get_song_dict(item['content'], mt)
             if song_dict:
                 song_list.append(song_dict)
                 logger.info(u"Scanned Results: {}|{}".format(
                     song_dict['title'], song_dict['link']))
                 result = mt.download_music(song_dict['link'],
                                            song_dict['title'],
                                            is_quiet=True)
                 # result = 1
                 logger.debug(
                     "Download Result: {} | 1 is a failure, 0 is a success".
                     format(result))
                 #1 is a failure, 0 is a success
                 if result == 0:
                     logger.info(
                         "Download Success. Marking item as completed...")
                     item.complete()
                     mt.fix_id3(song_dict['title'])
                 else:
                     logger.error(
                         u"Downloading of {} failed. Moving to the next item..."
                         .format(song_dict['title']))
     self.api.commit()
def get_thumbs_up_list():

	thumbs_up_list = []
	end = ''
	with codecs.open(LAST_READ_FILE_NAME,encoding='utf-8') as f:
		#Skipping first line
		next(f)
		for line in f:
			end = line
	logger.info(u'Searching till {}'.format(end))
	count = 0
	new_end = ''
	mt = MusicTools()
	with codecs.open(DUMP_FILE_NAME, encoding='utf-8') as f:
		#Skipping first line
		next(f)
	    for line in f:
	    	logger.info(line)
	    	logger.info(end in line)
	        if end in line:
	        	# logger.info('Found end')
	            break
	        if count == 0:
	            new_end = line
	            count = count+1
	        song_dict={}
	        logger.debug(line)
	        try:
	        	line = unidecode(line)
	        except UnicodeDecodeError:
	        	logger.warning("Unicode Error when decoding {}".format(line))

	        logger.debug(line)
	        parts = line.split(' - ')
	        logger.debug(parts)
	        song_dict['artist'] = parts[0].lstrip()
	        song_dict['title'] = parts[1].rstrip()
	        # logger.debug(song_dict)
	        thumbs_up_list.append(song_dict)
			# else:
			# 	logger.error(u"Downloading of {} failed. Moving to the next item...".format(song_dict['title']))
			# 	with open(DOWNLOAD_FAILED_FILE_NAME, 'a+') as f:
			# 		f.write("{}\n".format(line))
	logger.info(u'New Last File Read Name:{}'.format(new_end))
	# with codecs.open(LAST_READ_FILE_NAME, encoding='utf-8', mode='w') as f:
	#     f.write(new_end)
	logger.debug(thumbs_up_list)
	logger.info('{} songs from Thumbs Up List'.format(len(thumbs_up_list)))
	return pd.DataFrame(thumbs_up_list)
def main():
    open(DOWNLOAD_FAILED_FILE_NAME, 'w').close()
    song_list = get_songs_to_be_downloaded()
    if len(song_list.index) > 0:
        mt = MusicTools()
        logger.info('Downloading {} songs...'.format(len(song_list)))
        for index, row in song_list.iterrows():
            song_dict = mt.get_song_dict_from_title(row['full_title'])
            if song_dict:
                # pass
                logger.info(u"song_dict - title: {}".format(
                    song_dict['title']))
                status = mt.download_music(song_dict['link'],
                                           row['full_title'],
                                           is_quiet=True)
                # status = 1
                if status == 0:
                    mt.fix_id3(row['full_title'])
                else:
                    logger.error(
                        u"Downloading of {} failed. Moving to the next item..."
                        .format(song_dict['title']))
                    with codecs.open(DOWNLOAD_FAILED_FILE_NAME,
                                     encoding='utf-8',
                                     mode='a+') as f:
                        f.write("{}\n".format(row['full_title']))
            else:
                logger.error(
                    u"No results found for {}. Moving to the next item...".
                    format(row['full_title']))
                with codecs.open(DOWNLOAD_FAILED_FILE_NAME,
                                 encoding='utf-8',
                                 mode='a+') as f:
                    f.write(u"{}\n".format(row['full_title']))
        logger.info(
            '*************************Google Music Download Finished***************************'
        )
    else:
        logger.error("No Songs to be downloaded. Quiting...")
    logger.info(u'New Last File Read Name:{}'.format(new_end))
    with codecs.open(LAST_READ_FILE_NAME, encoding='utf-8', mode='w') as f:
        f.write('******END****\n{}'.format(new_end))
示例#7
0
 def __init__(self):
     self.api = TodoistAPI(Config.TODOIST_API_KEY)
     self.api.sync()
     self.mt = MusicTools()
示例#8
0
class ToDoist:
    
    __metaclass__ = Singleton
    
    def __init__(self):
        self.api = TodoistAPI(Config.TODOIST_API_KEY)
        self.api.sync()
        self.mt = MusicTools()

    def find_project_id_by_name(self,project_name):
        projects = self.api.state['projects']
        for project in projects:
            if project['name'] == project_name:
                return project['id']
            
    def add_item(self, item, project_id=None, project_name = None):
        if (project_id is None) and (project_name is None):
            raise ValueError('Either project_id or project_name should be provided')
        if project_id is None:
            project_id = self.find_project_id_by_name(project_name)
        self.api.items.add(item,project_id)

    def walk_items_in_project(self, function_to_call, project=Config.TODOIST_PROJECT_NAME, commit=True, mark_read = True):
        items = self.api.state['items']
        logger.info("Scanning and Downloading ToDoist List:{}".format(project))
        for item in items:
            logger.debug(u"Scanning {}|{}".format(item['content'], item['id']))
            if item and ('checked' in item.data.keys()):
                if ((item['project_id'] == self.find_project_id_by_name(project)) & (item['checked']==0)): #For Debug  & (item['id']==112286022)    
                    function_to_call(item, mark_read)
        if commit:
            self.api.commit()

    def download_song(self,item, mark_read):
        result = 1
        song = self.get_song(item['content'])
        if song:
            logger.info(u"Scanned Results: {}|{}".format(song.full_title, song.video_link))
            result = self.mt.download_music(song.video_link, song.full_title, is_quiet=True)
            # result = 1
            logger.debug("Download Result: {} | 1 is a failure, 0 is a success".format(result))
        #1 is a failure, 0 is a success
            if result == 0:
                logger.info("Download Success. Marking item as completed...")
                if mark_read:
                    item.complete()
                self.mt.fix_id3(song)
            else:
                logger.error(u"Downloading of {} failed. Moving to the next item...".format(song.full_title))

    def get_song(self,item):
        #Checking Youtube Links
        youtube=Youtube()
        link = youtube.extract_youtube_link_from_text(item)
        if link:
            full_title = youtube.get_title_from_youtube_code(get_youtube_code_from_link(link))
            song = Song(full_title= full_title, video_link = link, )
        else:
            soundcloud = Soundcloud()
            link = soundcloud.extract_soundcloud_link_from_text(item)
            if link:
                song= Song(full_title=soundcloud.get_title_soundcloud(link), video_link = link)
            else:
                #Items without a link
                songs = youtube.youtube_search(item,1)
                if len(songs) >0 :
                    song = songs[0]
                else:
                    return None
        return song
示例#9
0
def get_music_tools():
    global music_tools
    if music_tools is None:
        music_tools = MusicTools()
    return music_tools
示例#10
0
import os
import eyed3
from MusicTools import MusicTools
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

folder = 'D:\Music Download\downloaded_music - Copy'
mt = MusicTools()
for root, dirs, files in os.walk(folder):
    for name in files:
        dict_file = {}
        if name.endswith((".mp3")):
            logger.debug('File: {}'.format(name))
            mp3 = eyed3.load(os.path.realpath(os.path.join(root, name)))
            # print ("File: {}".format(name))
            genre = mt.get_genre_from_last_fm(mp3)
            logger.debug('Genre: {}'.format(genre))
            if genre == 'Unavailable':
                logger.info(u'Genre not available for {} - {}'.format(
                    mp3.tag.artist, mp3.tag.title))
            if mp3.tag:
                mp3.tag.genre = unicode(genre)
            else:
                mp3.tag = eyed3.id3.Tag()
                mp3.tag.genre = unicode(genre)
            mp3.tag.save()