def __init__(self, song, config): if song.info["background"]: self.background = song.info["background"] else: self.background = os.path.join(image_path, "bg.png") for key in ["movie", "filename", "title", "artist", "startat", "endat", "banner"]: self.__dict__[key] = song.info[key] self.soffset = song.info["gap"] * 1000 self.crapout = 0 self.__dict__.update(config) try: # if user used some internationalization in the configuration file, # so in mainconfig["lyriccolor"], maybe there is invalid colors # TODO: not save translated colors in the config file, only English clrs = [colors.color[_(c)] for c in mainconfig["lyriccolor"].split("/")] except: clrs = ["cyan","aqua"] clrs.reverse() self.lyricdisplay = Lyrics(clrs) atsec = 0 for lyr in song.lyrics: self.lyricdisplay.addlyric(*lyr)
def updateDisplay(self, eventDetails=None): SonosControllerWindow.updateDisplay(self, eventDetails) # Now we have updated the track currently playing read the details out and # set the windows properties for ArtistSlideshow # Only update if the track has changed if self.currentTrack not in [None, '']: # Check if we want to show lyrics for the track, although not part of the # artist slideshow feature (it is part of script.cu.lrclyrics) we treat # this in a similar manner, first set the values lyrics = None if Settings.isLyricsInfoLayout(): lyrics = Lyrics(self.currentTrack, self.getControl(SonosArtistSlideshow.LYRICS), self.lyricListLinesCount) lyrics.setLyricRequest() # Artist Slideshow will set these properties for us xbmcgui.Window(self.windowId).setProperty( 'CURRENTARTIST', self.currentTrack['artist']) xbmcgui.Window(self.windowId).setProperty( 'CURRENTTITLE', self.currentTrack['title']) xbmcgui.Window(self.windowId).setProperty( 'CURRENTALBUM', self.currentTrack['album']) # Check if lyrics are enabled, and set the test if they are if lyrics is not None: self.currentTrack = lyrics.populateLyrics() lyrics.refresh() del lyrics
def __init__(self): self.client = zulip.Client(site="https://fazeup.zulipchat.com/api/") self.subscribe_all() self.hacknews = Hackernews() self.trans = Translate() self.movie = Movie() self.lyrics = Lyrics() self.holiday = Holiday() self.currency = Currency() self.cricket = Cricket() # self.chatbot.train("chatterbot.corpus.english") self.crypto = Crypto() self.trans = Translate() self.g = Giphy() self.w = WikiPedia() # self.tw = Twimega() # self.motivate = Motivate() self.shortenedurl = Urlshortener() self.geo = Geocode() self.weather = Weather() self.dict_ = Dictionary() self.joke = Joke() self.pnr = Pnr() self.mustread = Mustread() self.ss = Ss() self.cricket = Cricket() self.poll = Poll() print("done init") self.subkeys = [ "crypto", "translate", "define", "joke", "weather", "giphy", "pnr", "mustread", "poll", "hackernews", "hn", "HN", "motivate", "twitter", "screenshot", "memo", "cricnews", "help", "shorturl", "movie", "currency", "holiday", "lyrics" ]
def __init__(self): self.client = zulip.Client(site="https://technh.zulipchat.com/api/", api_key="vkEQgQYDPUgAGmXaTXdMPsMwlkkgMfM5", email="*****@*****.**") self.subscribe_all() self.hacknews = Hackernews() self.trans = Translate() self.movie= Movie() self.lyrics = Lyrics() self.holiday = Holiday() self.currency = Currency() self.cricket = Cricket() self.github = GitHub() self.chatbot = ChatBot(name="technehru") print("done init") self.subkeys = ["use", "help", "translate", "hackernews", "hn", "hotel", "HN", "cricnews", "cricketnews", "movie", "currency", "holiday", "lyrics", "github"]
def parse_sanoitus(self, line): try: if line.strip() != "": parts = line.split(",") measure = int(parts[0].strip()) # measure start = parts[1].split("/") start = float(int(start[0].strip()) / int(start[1].strip())) # start string = parts[2].strip() lyric = Lyrics(measure, start, string) Composition.add_lyric(self.comp, lyric) return True except: print("Huono sanoitustavu.")
def __init__(self): self.client = zulip.Client(site="https://myra.zulipchat.com/api/") self.subscribe_all() self.hacknews = Hackernews() self.trans = Translate() self.movie = Movie() self.lyrics = Lyrics() self.holiday = Holiday() self.currency = Currency() self.cricket = Cricket() print("done init") self.subkeys = [ "translate", "hackernews", "hn", "hotel", "HN", "askme", "cricnews", "movie", "currency", "holiday", "lyrics" ]
def __init__(self, app): super().__init__() self.setupUi(self) # Это нужно для инициализации нашего дизайна # config loading self.config = config.Config(self) library.init(self.config.getLibraryDirs()) self.lyrics = Lyrics(self.config) # make post ui setup after library is initialized self.postSetupUi() # Load config goes after postSetupUi() to be able to restore columns width self.config.load(app) self.connectEvents(app) self.tableModel.refreshPlaylist()
def read_lyrics(lyrics_dir='lyrics_en', artist=None, album=None, print_stats=False, language='en-us', lookback=15): ''' Read lyrics and compute Rhyme factor (riimikerroin) for each artist. Input: lyrics_dir Path to the directory containing the lyrics. artist Name of the artist directory under lyrics_dir (if this is not provided, all artists are analyzed). album Name of the album directory under lyrics_dir/artist/ print_stats Whether we print summary statistics for each individual song. language Use either Finnish (fi), American English (en-us), or English (en). lookback How many previous words are checked for rhymes. For Finnish I've used 10 and for English 15. ''' if artist is not None: artists = [artist] else: artists = os.listdir(lyrics_dir) artist_scores = [] song_scores = [] song_names = [] uniq_words = [] longest_rhymes = [] max_rhymes = 5 for a in artists: print "Analyzing artist: %s" % a rls = [] all_words = [] if album is not None: albums = [album] else: albums = os.listdir(os.path.join(lyrics_dir, a)) albums = sort_albums_by_year(albums) for al in albums: album_rls = [] songs = os.listdir(os.path.join(lyrics_dir, a, al)) # Only the .txt files songs = [s for s in songs if len(s)>=4 and s[-4:]=='.txt'] for song in songs: file_name = os.path.join(lyrics_dir, a, al, song) l = Lyrics(file_name, print_stats=print_stats, language=language, lookback=lookback) rl = l.get_avg_rhyme_length() rls.append(rl) song_scores.append(rl) song_names.append(file_name) album_rls.append(rl) if len(longest_rhymes) < max_rhymes: heapq.heappush(longest_rhymes, l.get_longest_rhyme()) else: heapq.heappushpop(longest_rhymes, l.get_longest_rhyme()) if language == 'fi': all_words += l.text.split() else: text = l.text_orig.lower() rx = re.compile(u'[^\wåäö]+') text = rx.sub(' ', text) all_words += text.split() # Print stats for the album #print "%s - %s: %.3f" % (a, al, np.mean(np.array(album_rls))) #print "%.5f" % (np.mean(np.array(album_rls))) # Compute the number of unique words the artist has used n_words = len(all_words) min_w = 20000 if n_words >= min_w: n_uniq_words = len(set(all_words[:min_w])) uniq_words.append(n_uniq_words) else: uniq_words.append(-n_words) mean_rl = np.mean(np.array(rls)) artist_scores.append(mean_rl) # Sort the artists based on their avg rhyme lengths artist_scores = np.array(artist_scores) artists = np.array(artists) uniq_words = np.array(uniq_words) order = np.argsort(artist_scores)[::-1] artists = artists[order] uniq_words = uniq_words[order] artist_scores = artist_scores[order] print "\nBest rhymes" while len(longest_rhymes) > 0: l, rhyme = heapq.heappop(longest_rhymes) print rhyme print "\nBest songs:" song_scores = np.array(song_scores) song_names = np.array(song_names) song_names = song_names[np.argsort(song_scores)[::-1]] song_scores = sorted(song_scores)[::-1] for i in range(min(10,len(song_scores))): print '%.3f\t%s' % (song_scores[i], song_names[i]) print "\nBest artists:" for i in range(len(artist_scores)): rx = re.compile(u'_') name = rx.sub(' ', artists[i]) print '%d.\t%.3f\t%s' % (i+1, artist_scores[i], name)
def main(search, verbose): print('*** Searching for lyrics. ***') ly = Lyrics() lyrics = ly.get_lyrics(search) YT_search = search if lyrics == []: print("INFO: Could not found lyrics for your search.") lyric = None else: lyric = lyrics[0] if verbose: # list lyrics for user to choose for i, lyric in enumerate(lyrics, start=1): print(f'{i}. {lyric["author"]} {lyric["songName"]}') print('0. For no lyrics.') num = int(input('Choose lyrics: ')) if num == 0: lyric = None YT_search = search elif num > len(lyrics) or num < 0: sys.exit('ERROR: Wrong input.') else: lyric = lyrics[num - 1] YT_search = f'{lyric["author"]} {lyric["songName"]}' else: print(f'Found: {lyric["author"]} - {lyric["songName"]}') print('Done.\n') # search youtube print(f"*** Searching Youtube for '{YT_search}'. ***") youtube = Youtube() songs = youtube.search(YT_search, sortByViews=False) song = songs[0] if verbose: # list youtube songs for use to choose for i, song in enumerate(songs, start=1): print( f'{i}. {song["title"]}, {song["views"]} views, {song["link"]}') print('0. Exit.') num = int(input('Choose lyrics: ')) if num == 0: print('INFO: Exiting.') sys.exit(0) elif num > len(lyrics) or num < 0: exit('ERROR: Wrong input.') else: song = songs[num - 1] else: print( f'Found {song["title"]}, {song["views"]} views, {song["link"]}\n') print('Done.\n') # download a song from youtube print('*** Downloading and converting to mp3. ***') filepath, folder = youtube.download_and_convert_to_mp3( song['link'], DOWNLOAD_FOLDER) print('Done.\n') print('*** Filtering vocals. This could take a minute. ***') filter = Filter() vocals, instrum = filter.extract_vocals(filepath, folder) filter.mix_vocals_with_instrum(folder, vocals, instrum) print(f'Done.\n') if lyric is not None: print('*** Saving lyrics to file ***') ly.save(folder, lyric) print('Done saving lyrics to file.\n') absPath = os.path.abspath(folder) print(f'Output folder: {absPath}')
from lyrics import Lyrics from colored import fg, bg, attr import random file_name = 'lyrics_fr/Feu_Zoe_short.txt' language = 'fr' print_stats = True lookback = 30 rhyme_cutoff = 2 l = Lyrics(file_name, language=language, lookback=lookback) def generate_color(number_of_colors): color = [ "#" + ''.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in range(number_of_colors) ] return color def get_text_in_color(text, color): ''' :param text: text that you're planning to print in color :param color: Hex color :return: str ''' color = fg(color) + bg("#FFFFFF") # white background is kept constant. res = attr('reset') return color + text + res
action='store_true') args = parser.parse_args() print(args.__dict__) cm = CmusPlayer() if not cm.is_cmus_playing(): sys.exit() # TODO # arguments like: # - credential file # - retry if NOT FOUND try: s = Settings() s.get_settings() lyrics = Lyrics(s.settings) except Exception as e: sys.exit(e) main = Main(cm) if (main.cms.is_cmus_playing()): main.set_file(args.lyricspath) if not main.file_save_exists() or args.overwrite: main.get_lyrics(lyrics) main.print_lyrics()
from lyrics import Lyrics file_name = 'lyrics_fr/Feu_Zoe_short.txt' language = 'fr' print_stats = True lookback = 30 l = Lyrics(file_name, print_stats=print_stats, language=language, lookback=lookback) for rhyme in (sorted(l.rhyme_map.items(), key=lambda x: x[1])): print rhyme[0], rhyme[1]