mirror of https://github.com/yt-dlp/yt-dlp.git
[photobucket] Modernize and remove the old extraction code
This commit is contained in:
parent
ee95c09333
commit
90f3476180
|
@ -1,52 +1,38 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
|
||||||
from ..utils import (
|
|
||||||
ExtractorError,
|
|
||||||
)
|
|
||||||
|
|
||||||
class PhotobucketIE(InfoExtractor):
|
class PhotobucketIE(InfoExtractor):
|
||||||
"""Information extractor for photobucket.com."""
|
_VALID_URL = r'http://(?:[a-z0-9]+\.)?photobucket\.com/.*(([\?\&]current=)|_)(?P<id>.*)\.(?P<ext>(flv)|(mp4))'
|
||||||
|
|
||||||
# TODO: the original _VALID_URL was:
|
|
||||||
# r'(?:http://)?(?:[a-z0-9]+\.)?photobucket\.com/.*[\?\&]current=(.*\.flv)'
|
|
||||||
# Check if it's necessary to keep the old extracion process
|
|
||||||
_VALID_URL = r'(?:http://)?(?:[a-z0-9]+\.)?photobucket\.com/.*(([\?\&]current=)|_)(?P<id>.*)\.(?P<ext>(flv)|(mp4))'
|
|
||||||
IE_NAME = u'photobucket'
|
|
||||||
_TEST = {
|
_TEST = {
|
||||||
u'url': u'http://media.photobucket.com/user/rachaneronas/media/TiredofLinkBuildingTryBacklinkMyDomaincom_zpsc0c3b9fa.mp4.html?filters[term]=search&filters[primary]=videos&filters[secondary]=images&sort=1&o=0',
|
u'url': u'http://media.photobucket.com/user/rachaneronas/media/TiredofLinkBuildingTryBacklinkMyDomaincom_zpsc0c3b9fa.mp4.html?filters[term]=search&filters[primary]=videos&filters[secondary]=images&sort=1&o=0',
|
||||||
u'file': u'zpsc0c3b9fa.mp4',
|
u'file': u'zpsc0c3b9fa.mp4',
|
||||||
u'md5': u'7dabfb92b0a31f6c16cebc0f8e60ff99',
|
u'md5': u'7dabfb92b0a31f6c16cebc0f8e60ff99',
|
||||||
u'info_dict': {
|
u'info_dict': {
|
||||||
u"upload_date": u"20130504",
|
'upload_date': '20130504',
|
||||||
u"uploader": u"rachaneronas",
|
'uploader': 'rachaneronas',
|
||||||
u"title": u"Tired of Link Building? Try BacklinkMyDomain.com!"
|
'title': 'Tired of Link Building? Try BacklinkMyDomain.com!',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
# Extract id from URL
|
|
||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
if mobj is None:
|
|
||||||
raise ExtractorError(u'Invalid URL: %s' % url)
|
|
||||||
|
|
||||||
video_id = mobj.group('id')
|
video_id = mobj.group('id')
|
||||||
|
|
||||||
video_extension = mobj.group('ext')
|
video_extension = mobj.group('ext')
|
||||||
|
|
||||||
# Retrieve video webpage to extract further information
|
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
|
|
||||||
# Extract URL, uploader, and title from webpage
|
# Extract URL, uploader, and title from webpage
|
||||||
self.report_extraction(video_id)
|
self.report_extraction(video_id)
|
||||||
# We try first by looking the javascript code:
|
info_json = self._search_regex(r'Pb\.Data\.Shared\.put\(Pb\.Data\.Shared\.MEDIA, (.*?)\);',
|
||||||
mobj = re.search(r'Pb\.Data\.Shared\.put\(Pb\.Data\.Shared\.MEDIA, (?P<json>.*?)\);', webpage)
|
webpage, 'info json')
|
||||||
if mobj is not None:
|
info = json.loads(info_json)
|
||||||
info = json.loads(mobj.group('json'))
|
return {
|
||||||
return [{
|
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': info[u'downloadUrl'],
|
'url': info[u'downloadUrl'],
|
||||||
'uploader': info[u'username'],
|
'uploader': info[u'username'],
|
||||||
|
@ -54,23 +40,4 @@ class PhotobucketIE(InfoExtractor):
|
||||||
'title': info[u'title'],
|
'title': info[u'title'],
|
||||||
'ext': video_extension,
|
'ext': video_extension,
|
||||||
'thumbnail': info[u'thumbUrl'],
|
'thumbnail': info[u'thumbUrl'],
|
||||||
}]
|
}
|
||||||
|
|
||||||
# We try looking in other parts of the webpage
|
|
||||||
video_url = self._search_regex(r'<link rel="video_src" href=".*\?file=([^"]+)" />',
|
|
||||||
webpage, u'video URL')
|
|
||||||
|
|
||||||
mobj = re.search(r'<title>(.*) video by (.*) - Photobucket</title>', webpage)
|
|
||||||
if mobj is None:
|
|
||||||
raise ExtractorError(u'Unable to extract title')
|
|
||||||
video_title = mobj.group(1).decode('utf-8')
|
|
||||||
video_uploader = mobj.group(2).decode('utf-8')
|
|
||||||
|
|
||||||
return [{
|
|
||||||
'id': video_id.decode('utf-8'),
|
|
||||||
'url': video_url.decode('utf-8'),
|
|
||||||
'uploader': video_uploader,
|
|
||||||
'upload_date': None,
|
|
||||||
'title': video_title,
|
|
||||||
'ext': video_extension.decode('utf-8'),
|
|
||||||
}]
|
|
||||||
|
|
Loading…
Reference in New Issue