[Python] Simple terminal lyrics scrolling player

Source: Internet
Author: User

Integration of some of the NetEase Cloud API, want to write a terminal version of the music player, but has not been written to what look.

Temporarily wrote a must function: with the lyrics scrolling player, with the Pygame in the mixer to play music.

Ready to have time to implement other functions.

1 #-*-coding:utf-8-*-2 ImportRe3 ImportOS4 Import Time5 ImportCopy6 ImportThreading7 ImportPygame8  fromPygameImportMixer9 Ten  One defread_file (path): A     if  notos.path.exists (path): -         Print 'path: \ ''+ Path +'\ ' not find.' -         return [] theContent ="' -     Try: -With open (path,'R') as FP: -Content + = reduce (LambdaX, Y:x +y, FP) +     finally: - fp.close () +     returnContent.split ('\ n') A  at classLyrics: -Time_axis_regexp = Re.compile ('\[(\d+) \:(\d+) \. (\d+) \]') -Del_time_axis_regexp = Re.compile ('\[\d+\:\d+\.\d+\] (. *)') -  -     def __init__(self, path): -Self.path =Path in  -     def_get_time_diff (self, line): toTM = Map (Lambdaeach:map (int, each), self. Time_axis_regexp.findall (line)) +TM = Map (LambdaEACH:EACH[0] * + * + each[1] * + each[2], TM) -         return(Tm[0], line) the  *     def_show_lyric (self, line): $         Print LinePanax Notoginseng  -     defstatic_lyric (self, lyrics): the          forLineinchLyrics: + self._show_lyric (line) A  the     defdynamic_lyric (self, lyrics): +          forLineinchLyrics: -             Try: $Time.sleep (float (line[0])/1000.0) $Self._show_lyric (line[1]) -             except: -                 Pass the  -     defget_lyric (self):WuyiLyrics =read_file (Self.path) theTmp_lyric =Lyrics -Lyrics = Filter (LambdaLine:len (self. Time_axis_regexp.findall (line))! =0, lyrics) Wu         ifLen (lyrics) = =0: -             returnFalse, Tmp_lyric AboutLyrics =map (Self._get_time_diff, lyrics) $Tmp_lyric = Copy.deepcopy (lyrics[:-1]) -Tmp_lyric.insert (0, (0,"')) -Lyrics = Map (Lambdax: (X[0][0]-x[1][0], x[0][1]), zip (lyrics, tmp_lyric)) -Lyrics = Map (Lambdax: (X[0], self. Del_time_axis_regexp.findall (x[1]) [0]), lyrics) A         returnTrue, lyrics +  the     defshow_lyric (self): -Play_option, lyrics =self.get_lyric () $         ifPlay_option = =True: the Self.dynamic_lyric (lyrics) the         Else: the Self.static_lyric (lyrics) the  - defPlay_mp3 (path): in Mixer.init () theTrack =mixer.music.load (path) theMixer.music.play (1) About  the defPlay (Mp3_path, Lrc_path): theT_mp3 = Threading. Thread (target=Play_mp3 (mp3_path)) theLyrics =lyrics (Lrc_path) +T_lyric = Threading. Thread (target=lyrics.show_lyric ()) -  the T_mp3.start ()Bayi T_lyric.start () the T_mp3.join () the T_lyric.join () -  -  the def __main__(): thePlay'./test1.mp3','./TEST1.LRC') the  the if __name__=='__main__': -     __main__()

[Python] Simple terminal lyrics scrolling player

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.