From c5c2d9c1e92b9c429afe7be7e2797837d6c17984 Mon Sep 17 00:00:00 2001 From: Abhishek Kedia Date: Sun, 20 Dec 2015 23:51:00 +0100 Subject: [PATCH] generalise regex for other url formats also, and return all possible video formats instead of just 360p --- youtube_dl/extractor/genvideos.py | 40 +++++++++++-------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/youtube_dl/extractor/genvideos.py b/youtube_dl/extractor/genvideos.py index d3362e059..76cd89bd1 100644 --- a/youtube_dl/extractor/genvideos.py +++ b/youtube_dl/extractor/genvideos.py @@ -4,35 +4,24 @@ from __future__ import unicode_literals from .common import InfoExtractor import requests -import json import urllib from urlparse import parse_qs, urlparse class GenVideosIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?genvideos.org/watch\?v=(?P\w+)#?' #Tests only the basic url format. Example - https://genvideos.org/watch?v=kMjlhMWE5OT - # TODO check for other possible url formats also - # For example - # * http://genvideos.com/watch_kMjlhMWE5OT.html#video=tBa-Q-WkbPqwzs34b7ArqU7VomQMb2n-RAlARWKWKTI - # * http://genvideos.org/watch_kMjlhMWE5OT.html#video=tBa-Q-WkbPqwzs34b7ArqU7VomQMb2n-RAlARWKWKTI + _VALID_URL = r'https?://(?:www\.)?genvideos.(org|com)/watch(\?v=|_)(?P\w+)#?' _TESTS = [{ 'url': 'http://genvideos.org/watch?v=kMjlhMWE5OT', - 'md5': '666118ec1176f14259bb9f11c74bea83', + 'md5': 'f610bd838c21c083ede8a05ca18d55e2', #1080p quality 'info_dict': { 'id': 'kMjlhMWE5OT', 'ext': 'mp4', 'title': 'The Hunger Games (2012) - HD 1080p', 'description': 'In a dystopian future, the totalitarian nation of Panem is divided between 12 districts and the Capitol. Each year two young representatives from each distri...' - #'thumbnail': 're:^https?://.*\.jpg$', - # TODO more properties, either as: - # * A value - # * MD5 checksum; start the string with md5: - # * A regular expression; start the string with re: - # * Any Python type (for example int or float) } }, { 'url': 'https://genvideos.org/watch?v=Pitch_Perfect_2_2015#video=tBa-Q-WkbPqwzs34b7ArqU7VomQMb2n-RAlARWKWKTI', - 'md5': '441b5c9f0445724b0f6f9d6e5498e577', + 'md5': 'df4011514016747ea3478d1776ffece2', #1080p quality 'info_dict':{ 'id': 'Pitch_Perfect_2_2015', 'ext': 'mp4', @@ -46,24 +35,23 @@ class GenVideosIE(InfoExtractor): webpage = self._download_webpage(url, video_id) title = self._html_search_regex(r'

(.+?)

', webpage, 'title') - #TODO retrieve video url + #TODO retrieve video url (using requests dependency for the moment) urls_data = requests.post( "https://genvideos.org/video_info/iframe", data={'v':video_id}, headers={'referer': 'https://genvideos.org/'} - ) #returns json containing the url of the video (in 360p, 720p and 1080p). - #For example - {"360":"\/\/html5player.org\/embed?url=https%3A%2F%2Flh3.googleusercontent.com%2FW6-SNGaDLWNyucD3pMqa1uMBapGDbtMTOtwpXrEu-w%3Dm18","720":"\/\/html5player.org\/embed?url=https%3A%2F%2Flh3.googleusercontent.com%2FW6-SNGaDLWNyucD3pMqa1uMBapGDbtMTOtwpXrEu-w%3Dm22","1080":"\/\/html5player.org\/embed?url=https%3A%2F%2Flh3.googleusercontent.com%2FW6-SNGaDLWNyucD3pMqa1uMBapGDbtMTOtwpXrEu-w%3Dm37"} - urls_data_json = json.loads(urls_data.text) - _360p_url = parse_qs(urlparse(urls_data_json['360']).query)['url'][0] - #_360p_url = urllib.urlopen(_360p_redirect_url).geturl() - # TODO : return all possible formats instead of just 360p - + ) #returns json containing the url of the video (in 360p, 720p and 1080p). For example - {"360":"\/\/html5player.org\/embed?url=https%3A%2F%2Flh3.googleusercontent.com%2FW6-SNGaDLWNyucD3pMqa1uMBapGDbtMTOtwpXrEu-w%3Dm18","720":"\/\/html5player.org\/embed?url=https%3A%2F%2Flh3.googleusercontent.com%2FW6-SNGaDLWNyucD3pMqa1uMBapGDbtMTOtwpXrEu-w%3Dm22","1080":"\/\/html5player.org\/embed?url=https%3A%2F%2Flh3.googleusercontent.com%2FW6-SNGaDLWNyucD3pMqa1uMBapGDbtMTOtwpXrEu-w%3Dm37"} + urls_data_json = self._parse_json(urls_data.text,video_id) + formats = [] + for quality in sorted(urls_data_json,key=lambda q:int(q)): + formats.append({ + 'url':parse_qs(urlparse(urls_data_json[quality]).query)['url'][0], + 'ext':'mp4', + 'format_id':quality + }) return { 'id': video_id, 'title': title, - 'url': _360p_url, - 'ext': 'mp4', 'description': self._og_search_description(webpage), - #'uploader': self._search_regex(r']+id="uploader"[^>]*>([^<]+)<', webpage, 'uploader', fatal=False), - # TODO more properties (see youtube_dl/extractor/common.py) + 'formats':formats }