2014-02-11 06:45:17 +11:00
from __future__ import unicode_literals
2013-06-24 06:30:16 +10:00
import re
from . common import InfoExtractor
class HowcastIE ( InfoExtractor ) :
2014-02-11 06:45:17 +11:00
_VALID_URL = r ' https?://(?:www \ .)?howcast \ .com/videos/(?P<id> \ d+) '
2013-06-28 04:46:46 +10:00
_TEST = {
2014-02-11 06:45:17 +11:00
' url ' : ' http://www.howcast.com/videos/390161-How-to-Tie-a-Square-Knot-Properly ' ,
' md5 ' : ' 8b743df908c42f60cf6496586c7f12c3 ' ,
' info_dict ' : {
' id ' : ' 390161 ' ,
' ext ' : ' mp4 ' ,
2014-11-24 06:41:03 +11:00
' description ' : ' The square knot, also known as the reef knot, is one of the oldest, most basic knots to tie, and can be used in many different ways. Here \' s the proper way to tie a square knot. ' ,
2014-02-11 06:45:17 +11:00
' title ' : ' How to Tie a Square Knot Properly ' ,
2013-06-28 04:46:46 +10:00
}
}
2013-06-24 06:30:16 +10:00
def _real_extract ( self , url ) :
mobj = re . match ( self . _VALID_URL , url )
video_id = mobj . group ( ' id ' )
2013-09-12 01:36:23 +10:00
webpage = self . _download_webpage ( url , video_id )
2013-06-24 06:30:16 +10:00
self . report_extraction ( video_id )
video_url = self . _search_regex ( r ' \' ?file \' ?: " (http://mobile-media \ .howcast \ .com/[0-9]+ \ .mp4) ' ,
2014-02-11 06:45:17 +11:00
webpage , ' video URL ' )
2013-06-24 06:30:16 +10:00
video_description = self . _html_search_regex ( r ' <meta content=(?: " ([^ " ]+) " | \' ([^ \' ]+) \' ) name= \' description \' ' ,
2014-02-11 06:45:17 +11:00
webpage , ' description ' , fatal = False )
2013-06-24 06:30:16 +10:00
2014-02-11 06:45:17 +11:00
return {
' id ' : video_id ,
' url ' : video_url ,
' title ' : self . _og_search_title ( webpage ) ,
2013-06-24 06:30:16 +10:00
' description ' : video_description ,
2014-02-11 06:45:17 +11:00
' thumbnail ' : self . _og_search_thumbnail ( webpage ) ,
}