Commandline tool to extract audio from online flash videos as mp3.
It communicates with listentoyoutube.com for this purpose.
Vimeo.com, dailymotion.com, metacafe.com are also supported by this tool.
Now it is an early release so better you try it in a virtual environment or
if you want to install it in your system it requires su/superuser access.
To install the script do this
Option 1 : Install via pip
$ sudo pip install vid2mp3
Option 2 : If you have downloaded the source
$ sudo python setup.py install
1 #!/usr/bin/env python 2 3 ''' 4 Commandline tool to extract audio from online flash videos as mp3. 5 It communicates with listentoyoutube.com for this purpose. 6 Vimeo.com, dailymotion.com, metacafe.com are also supported by this tool. 7 ''' 8 9 __appname__ = "vid2mp3" 10 __version__ = "0.1.1" 11 __author__ = "iamsudip <iamsudip@programmer.net>" 12 __license__ = "MIT" 13 14 import requests 15 import sys, os 16 from bs4 import BeautifulSoup 17 import time 18 19 def download(data): 20 try: 21 with open("%s" %data[1], "wb") as fobj: 22 print "File size: " + data[2] 23 response = requests.get(data[0], stream=True) 24 fsrc = response.raw 25 size = response.headers.get("content-length") 26 length = 16*1024 27 while True: 28 buf = fsrc.read(length) 29 if not buf: 30 break 31 fobj.write(buf) 32 sys.stdout.write("Downloaded " + str(os.path.getsize(data[1])/1024) + "kb of " + str(int(size)/1024) + " kb\r") 33 sys.stdout.flush() 34 print "Download complete." 35 sys.exit(0) 36 except IOError: 37 data[1] = "Rename_manually.mp3" 38 download(data) 39 40 def process_url(s_url, sleep_time = 10): 41 try: 42 s_url_soup = BeautifulSoup(requests.get(s_url).text, "xml") 43 data = [str(s_url_soup.downloadurl.contents[0]), 44 str(s_url_soup.file.contents[0]), 45 str(s_url_soup.filesize.contents[0]) 46 ] 47 if not data[0]: 48 raise AttributeError 49 print "Downloading: %s" % data[1] 50 print "Fetching data from: %s" % data[0] 51 return data 52 except AttributeError: 53 time.sleep(sleep_time) 54 sleep_time += 10 55 process_url(s_url, sleep_time) 56 57 def make_url(url): 58 try: 59 response = requests.post("http://www.listentoyoutube.com/cc/conversioncloud.php", data={"mediaurl": url}) 60 s_url = eval(response.text)['statusurl'].replace('\/', '/') 61 data = process_url(s_url) 62 download(data) 63 except KeyError: 64 print "Please check the given link.\n Exiting" 65 sys.exit(1) 66 67 if __name__ == '__main__': 68 if len(sys.argv) == 2: 69 make_url(sys.argv[1]) 70 else: 71 print "usage:\n vid2mp3 [link-to-video]"
Use it as
$ vid2mp3 [video-link]
Please report bugs at github issue tracker: https://github.com/iamsudip/vid2mp3/issues