mightyroot

Python RadioTitleParser

Feb 5th, 2013
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import re
  3. import subprocess
  4.  
  5. class bcolors:
  6.     YELLOW = '\033[93m'
  7.     RED = '\033[95m'
  8.     ENDC = '\033[0m'
  9.  
  10.  
  11. url= "/root/Download/Play.pls"
  12. p= subprocess.Popen(['mplayer','-playlist', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  13. for line in p.stdout:
  14.     if line.startswith('Name'):
  15.         info = line.split(':', 1)[1].strip()
  16.         print bcolors.RED + '---{  ' + bcolors.ENDC, bcolors.YELLOW, info, bcolors.ENDC, bcolors.RED + '  }---'+ bcolors.ENDC
  17.  
  18.     if line.startswith('ICY Info:'):
  19.         info = line.split(':', 1)[1].strip()
  20.         attrs = dict(re.findall("(\w+)='([^']*)'", info))
  21.         f1=open('/tmp/nowplaying.log', 'w+')
  22.         print >>f1, attrs.get('StreamTitle', '(none)')
  23.         f1.close()
  24.         print bcolors.RED + '>>> ' + bcolors.ENDC, attrs.get('StreamTitle', '(none)')
  25.  
  26. ----------------------------------
  27. cat /root/Download/Play.pls
  28. #EXTM3U
  29. #EXTINF:-1 tvg-name="ТНТ"
  30. http://go.dnbfm.ru:8000/play
  31. #EXTINF:-1 tvg-name="ТНТ"
  32. http://online.radiorecord.ru:8102/ps_128
  33. #EXTINF:-1 tvg-name="ТНТ"
  34. http://deppy.dnbradio.com:8016
  35. #EXTINF:-1 tvg-name="ТНТ"
  36. http://aol.streams.bassdrive.com:8008
  37. #EXTINF:-1 tvg-name="ТНТ"  
  38. http://radio.dnbtv.com:8004/
  39. #EXTINF:-1 tvg-name="ТНТ"  
  40. http://u12.di.fm:80/di_liquiddnb
  41. #EXTINF:-1 tvg-name="ТНТ"                                                                                                                                                                                      
  42. http://sanfm.ru:8000/drum                                                                                                                                                                                      
  43. #EXTINF:-1 tvg-name="ТНТ"                                                                                                                                                                                      
  44. http://www.destroyer.net:8800                                                                                                                                                                                  
  45. #EXTINF:-1 tvg-name="ТНТ"                                                                                                                                                                                      
  46. http://stream2.jungletrain.net:8000
Add Comment
Please, Sign In to add comment