Skip to content

Instantly share code, notes, and snippets.

@dnet
Created June 12, 2011 08:53
Show Gist options
  • Save dnet/1021359 to your computer and use it in GitHub Desktop.
Save dnet/1021359 to your computer and use it in GitHub Desktop.
Indavideó downloader
% Downloader for http://indavideo.hu/
% Author: András Veres-Szentkirályi <vsza@vsza.hu>
% License: MIT
-module(ivd).
-export([getvideos/1]).
getvideos(URL) ->
VID = url2vid(URL),
AmfReq = <<"\0\x03\0\0\0\x01\0!player.playerHandler.getVideoData\0\x02"
"/1\0\0\0!\n\0\0\0\x04\x02\0\n", VID/binary,
"\0@(\0\0\0\0\0\0\x02\0\0\x02\0\0">>,
HttpReq = {"http://amfphp.indavideo.hu/gateway.php", [],
"application/x-amf", AmfReq},
{ok, {_, _, AmfResp}} = httpc:request(post, HttpReq, [], []),
{match, Videos} = re:run(AmfResp,
"http://[a-zA-Z0-9/._\\-]+\\.(?:mp4|webm)",
[{capture, first, list}, global]),
lists:map(fun lists:flatten/1, sets:to_list(sets:from_list(Videos))).
url2vid(URL) ->
{ok, {_, _, Body}} = httpc:request(URL),
{match, [VID]} = re:run(Body,
"vID=([a-z0-9]{10})",
[{capture, all_but_first, binary}]),
VID.
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
Downloader for http://indavideo.hu/
Author: András Veres-Szentkirályi <vsza@vsza.hu>
License: MIT
"""
from lxml import html
from urllib2 import urlopen
from subprocess import call
import re
import sys
__prefs__ = ('720', '360', 'webm')
__amftpl__ = ('\0\x03\0\0\0\x01\0!player.playerHandler.getVideoData\0\x02/1'
'\0\0\0!\n\0\0\0\x04\x02\0\n{vid}\0@(\0\0\0\0\0\0\x02\0\0\x02\0\0')
def main():
"""Downloads the video from the URL in argv[1] (if specified)"""
if len(sys.argv) < 2:
print >> sys.stderr, 'Usage: %s <url>' % sys.argv[0]
else:
download(sys.argv[1])
def download(url):
"""Downloads the video from the URL in the url parameter"""
videos = getvideos(url)
video_url = preferred(videos)
call(['wget', video_url])
def preferred(videos):
"""Returns the preferred URL from the iterable in the videos parameter"""
for pref in __prefs__:
for video in videos:
if pref in video:
return video
return videos[0]
def url2vid(url):
"""Returns the ID of the video on the URL in the url parameter"""
video = html.parse(urlopen(url)).getroot()
video_src = video.xpath('/html/head/link[@rel = "video_src"]/@href'
' | /html/head/meta[@property="og:video"]/@content')[0]
return re.search('vID=([^&]+)&', video_src).group(1)
def getvideos(url):
"""Returns URLs that contain the video on the URL in the url parameter"""
amfreq = __amftpl__.format(vid=url2vid(url))
amfresp = urlopen('http://amfphp.indavideo.hu/gateway.php', amfreq).read()
return set(re.findall(r'http://[a-zA-Z0-9/._\-]+\.(?:mp4|webm)', amfresp))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment