http post - Make a request to download a video in Python -


i have links of form:

http://youtubeinmp3.com/fetch/?video=link_to_youtube_video_here 

if put links of type in <a> tag on webpage, clicking them download mp3 of youtube video @ end of link. source here.

i'd mimic process command-line making post requests (or of sort), i'm not sure how in python! can advice, please, or more difficult i'm making out be?

as mark ma mentioned, can done without leaving standard library utilizing urllib2. use requests, cooked up:

import os import requests  dump_directory = os.path.join(os.getcwd(), 'mp3') if not os.path.exists(dump_directory):     os.makedirs(dump_directory)   def dump_mp3_for(resource):     payload = {         'api': 'advanced',         'format': 'json',         'video': resource     }     initial_request = requests.get('http://youtubeinmp3.com/fetch/', params=payload)     if initial_request.status_code == 200:  # go         download_mp3_at(initial_request)   def download_mp3_at(initial_request):     j = initial_request.json()     filename = '{0}.mp3'.format(j['title'])     r = requests.get(j['link'], stream=true)     open(os.path.join(dump_directory, filename), 'wb') f:         print('dumping "{0}"...'.format(filename))         chunk in r.iter_content(chunk_size=1024):             if chunk:                 f.write(chunk)                 f.flush() 

it's trivial iterate on list of youtube video links , pass them dump_mp3_for() one-by-one.

for video in ['http://www.youtube.com/watch?v=i62zjga8jom']:     dump_mp3_for(video) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -