From e314ba675b6ce6683395d04e4621aae2b5aca0ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Tue, 1 Jan 2013 14:12:14 +0100 Subject: [PATCH] SteamIE --- youtube_dl/InfoExtractors.py | 49 ++++++++++++++++++++++++++++++++++++ youtube_dl/__init__.py | 1 + 2 files changed, 50 insertions(+) diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index d74751a55..d7295ae3f 100755 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -3756,3 +3756,52 @@ class TweetReelIE(InfoExtractor): 'upload_date': upload_date } return [info] + +class SteamIE(InfoExtractor): + _VALID_URL = r"""http://store.steampowered.com/ + (?Pvideo|app)/ #If the page is only for videos or for a game + (?P\d+)/? + (?P\d*)(?P\??) #For urltype == video we sometimes get the videoID + """ + IE_NAME = u'Steam' + + def suitable(self, url): + """Receives a URL and returns True if suitable for this IE.""" + return re.match(self._VALID_URL, url, re.VERBOSE) is not None + + def report_download_video_page(self, game_id): + self._downloader.to_screen(u'[%s] %s: Downloading video page' % (self.IE_NAME, game_id)) + + def _real_extract(self, url): + m = re.match(self._VALID_URL, url, re.VERBOSE) + urlRE = r"'movie_(?P\d+)': \{\s*FILENAME: \"(?P[\w:/\.\?=]+)\"(,\s*MOVIE_NAME: \"(?P[\w:/\.\?=\+-]+)\")?\s*\}," + gameID = m.group('gameID') + videourl = 'http://store.steampowered.com/video/%s/' % gameID + try: + self.report_download_video_page(gameID) + urlh = compat_urllib_request.urlopen(videourl) + webpage_bytes = urlh.read() + webpage = webpage_bytes.decode('utf-8', 'ignore') + except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err: + self._downloader.trouble(u'ERROR: unable to download webpage: %s' % compat_str(err)) + return + mweb = re.finditer(urlRE, webpage) + namesRE = r'(?P[\w:/\.\?=\+\s-]+)' + titles = list(re.finditer(namesRE, webpage)) + videos = [] + i = 0 + for vid in mweb: + video_id = vid.group('videoID') + title = titles[i].group('videoName') + video_url=vid.group('videoURL') + if not video_url: + self._downloader.trouble(u'ERROR: Cannot find video url for %s' % video_id) + i += 1 + info = { + 'id':video_id, + 'url':video_url, + 'ext': 'flv', + 'title': title + } + videos.append(info) + return videos diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 8068810ca..62ecdf6b6 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -313,6 +313,7 @@ def gen_extractors(): JustinTVIE(), FunnyOrDieIE(), TweetReelIE(), + SteamIE(), GenericIE() ] -- 2.22.2