Merge branch 'master' into use-other-downloaders
This commit is contained in:
commit
c7fac575d1
1
.gitignore
vendored
1
.gitignore
vendored
@ -25,3 +25,4 @@ updates_key.pem
|
|||||||
*.mp4
|
*.mp4
|
||||||
*.part
|
*.part
|
||||||
test/testdata
|
test/testdata
|
||||||
|
.tox
|
||||||
|
@ -52,6 +52,9 @@ which means you can modify it, redistribute it or use it however you like.
|
|||||||
--datebefore DATE download only videos uploaded before this date
|
--datebefore DATE download only videos uploaded before this date
|
||||||
--dateafter DATE download only videos uploaded after this date
|
--dateafter DATE download only videos uploaded after this date
|
||||||
--no-playlist download only the currently playing video
|
--no-playlist download only the currently playing video
|
||||||
|
--age-limit YEARS download only videos suitable for the given age
|
||||||
|
--download-archive FILE Download only videos not present in the archive
|
||||||
|
file. Record all downloaded videos in it.
|
||||||
|
|
||||||
## Download Options:
|
## Download Options:
|
||||||
-r, --rate-limit LIMIT maximum download rate (e.g. 50k or 44.6m)
|
-r, --rate-limit LIMIT maximum download rate (e.g. 50k or 44.6m)
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import errno
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
|
import types
|
||||||
|
|
||||||
import youtube_dl.extractor
|
import youtube_dl.extractor
|
||||||
from youtube_dl import YoutubeDL, YoutubeDLHandler
|
from youtube_dl import YoutubeDL, YoutubeDLHandler
|
||||||
@ -9,30 +12,47 @@ from youtube_dl.utils import (
|
|||||||
compat_urllib_request,
|
compat_urllib_request,
|
||||||
)
|
)
|
||||||
|
|
||||||
# General configuration (from __init__, not very elegant...)
|
youtube_dl._setup_opener(timeout=10)
|
||||||
jar = compat_cookiejar.CookieJar()
|
|
||||||
cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
|
|
||||||
proxy_handler = compat_urllib_request.ProxyHandler()
|
|
||||||
opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
|
|
||||||
compat_urllib_request.install_opener(opener)
|
|
||||||
|
|
||||||
PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
|
PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
|
||||||
with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
|
with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
|
||||||
parameters = json.load(pf)
|
parameters = json.load(pf)
|
||||||
|
|
||||||
|
|
||||||
|
def try_rm(filename):
|
||||||
|
""" Remove a file if it exists """
|
||||||
|
try:
|
||||||
|
os.remove(filename)
|
||||||
|
except OSError as ose:
|
||||||
|
if ose.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
class FakeYDL(YoutubeDL):
|
class FakeYDL(YoutubeDL):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.result = []
|
|
||||||
# Different instances of the downloader can't share the same dictionary
|
# Different instances of the downloader can't share the same dictionary
|
||||||
# some test set the "sublang" parameter, which would break the md5 checks.
|
# some test set the "sublang" parameter, which would break the md5 checks.
|
||||||
self.params = dict(parameters)
|
params = dict(parameters)
|
||||||
def to_screen(self, s):
|
super(FakeYDL, self).__init__(params)
|
||||||
|
self.result = []
|
||||||
|
|
||||||
|
def to_screen(self, s, skip_eol=None):
|
||||||
print(s)
|
print(s)
|
||||||
|
|
||||||
def trouble(self, s, tb=None):
|
def trouble(self, s, tb=None):
|
||||||
raise Exception(s)
|
raise Exception(s)
|
||||||
|
|
||||||
def download(self, x):
|
def download(self, x):
|
||||||
self.result.append(x)
|
self.result.append(x)
|
||||||
|
|
||||||
|
def expect_warning(self, regex):
|
||||||
|
# Silence an expected warning matching a regex
|
||||||
|
old_report_warning = self.report_warning
|
||||||
|
def report_warning(self, message):
|
||||||
|
if re.match(regex, message): return
|
||||||
|
old_report_warning(message)
|
||||||
|
self.report_warning = types.MethodType(report_warning, self)
|
||||||
|
|
||||||
def get_testcases():
|
def get_testcases():
|
||||||
for ie in youtube_dl.extractor.gen_extractors():
|
for ie in youtube_dl.extractor.gen_extractors():
|
||||||
t = getattr(ie, '_TEST', None)
|
t = getattr(ie, '_TEST', None)
|
||||||
|
53
test/test_age_restriction.py
Normal file
53
test/test_age_restriction.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
# Allow direct execution
|
||||||
|
import os
|
||||||
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
|
from youtube_dl import YoutubeDL
|
||||||
|
from helper import try_rm
|
||||||
|
|
||||||
|
|
||||||
|
def _download_restricted(url, filename, age):
|
||||||
|
""" Returns true iff the file has been downloaded """
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'age_limit': age,
|
||||||
|
'skip_download': True,
|
||||||
|
'writeinfojson': True,
|
||||||
|
"outtmpl": "%(id)s.%(ext)s",
|
||||||
|
}
|
||||||
|
ydl = YoutubeDL(params)
|
||||||
|
ydl.add_default_info_extractors()
|
||||||
|
json_filename = filename + '.info.json'
|
||||||
|
try_rm(json_filename)
|
||||||
|
ydl.download([url])
|
||||||
|
res = os.path.exists(json_filename)
|
||||||
|
try_rm(json_filename)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
class TestAgeRestriction(unittest.TestCase):
|
||||||
|
def _assert_restricted(self, url, filename, age, old_age=None):
|
||||||
|
self.assertTrue(_download_restricted(url, filename, old_age))
|
||||||
|
self.assertFalse(_download_restricted(url, filename, age))
|
||||||
|
|
||||||
|
def test_youtube(self):
|
||||||
|
self._assert_restricted('07FYdnEawAQ', '07FYdnEawAQ.mp4', 10)
|
||||||
|
|
||||||
|
def test_youporn(self):
|
||||||
|
self._assert_restricted(
|
||||||
|
'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
|
||||||
|
'505835.mp4', 2, old_age=25)
|
||||||
|
|
||||||
|
def test_pornotube(self):
|
||||||
|
self._assert_restricted(
|
||||||
|
'http://pornotube.com/c/173/m/1689755/Marilyn-Monroe-Bathing',
|
||||||
|
'1689755.flv', 13)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import json
|
|
||||||
import io
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
# Allow direct execution
|
# Allow direct execution
|
||||||
@ -45,15 +43,18 @@ class TestDailymotionSubtitles(unittest.TestCase):
|
|||||||
subtitles = self.getSubtitles()
|
subtitles = self.getSubtitles()
|
||||||
self.assertEqual(len(subtitles.keys()), 5)
|
self.assertEqual(len(subtitles.keys()), 5)
|
||||||
def test_list_subtitles(self):
|
def test_list_subtitles(self):
|
||||||
|
self.DL.expect_warning(u'Automatic Captions not supported by this server')
|
||||||
self.DL.params['listsubtitles'] = True
|
self.DL.params['listsubtitles'] = True
|
||||||
info_dict = self.getInfoDict()
|
info_dict = self.getInfoDict()
|
||||||
self.assertEqual(info_dict, None)
|
self.assertEqual(info_dict, None)
|
||||||
def test_automatic_captions(self):
|
def test_automatic_captions(self):
|
||||||
|
self.DL.expect_warning(u'Automatic Captions not supported by this server')
|
||||||
self.DL.params['writeautomaticsub'] = True
|
self.DL.params['writeautomaticsub'] = True
|
||||||
self.DL.params['subtitleslang'] = ['en']
|
self.DL.params['subtitleslang'] = ['en']
|
||||||
subtitles = self.getSubtitles()
|
subtitles = self.getSubtitles()
|
||||||
self.assertTrue(len(subtitles.keys()) == 0)
|
self.assertTrue(len(subtitles.keys()) == 0)
|
||||||
def test_nosubtitles(self):
|
def test_nosubtitles(self):
|
||||||
|
self.DL.expect_warning(u'video doesn\'t have subtitles')
|
||||||
self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
|
self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
|
||||||
self.DL.params['writesubtitles'] = True
|
self.DL.params['writesubtitles'] = True
|
||||||
self.DL.params['allsubtitles'] = True
|
self.DL.params['allsubtitles'] = True
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import errno
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
@ -20,22 +19,6 @@ PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "para
|
|||||||
|
|
||||||
RETRIES = 3
|
RETRIES = 3
|
||||||
|
|
||||||
# General configuration (from __init__, not very elegant...)
|
|
||||||
jar = compat_cookiejar.CookieJar()
|
|
||||||
cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
|
|
||||||
proxy_handler = compat_urllib_request.ProxyHandler()
|
|
||||||
opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
|
|
||||||
compat_urllib_request.install_opener(opener)
|
|
||||||
socket.setdefaulttimeout(10)
|
|
||||||
|
|
||||||
def _try_rm(filename):
|
|
||||||
""" Remove a file if it exists """
|
|
||||||
try:
|
|
||||||
os.remove(filename)
|
|
||||||
except OSError as ose:
|
|
||||||
if ose.errno != errno.ENOENT:
|
|
||||||
raise
|
|
||||||
|
|
||||||
md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
|
md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
class YoutubeDL(youtube_dl.YoutubeDL):
|
class YoutubeDL(youtube_dl.YoutubeDL):
|
||||||
@ -54,7 +37,8 @@ def _file_md5(fn):
|
|||||||
with open(fn, 'rb') as f:
|
with open(fn, 'rb') as f:
|
||||||
return hashlib.md5(f.read()).hexdigest()
|
return hashlib.md5(f.read()).hexdigest()
|
||||||
|
|
||||||
from helper import get_testcases
|
import helper # Set up remaining global configuration
|
||||||
|
from helper import get_testcases, try_rm
|
||||||
defs = get_testcases()
|
defs = get_testcases()
|
||||||
|
|
||||||
with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
|
with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
|
||||||
@ -97,9 +81,9 @@ def generator(test_case):
|
|||||||
|
|
||||||
test_cases = test_case.get('playlist', [test_case])
|
test_cases = test_case.get('playlist', [test_case])
|
||||||
for tc in test_cases:
|
for tc in test_cases:
|
||||||
_try_rm(tc['file'])
|
try_rm(tc['file'])
|
||||||
_try_rm(tc['file'] + '.part')
|
try_rm(tc['file'] + '.part')
|
||||||
_try_rm(tc['file'] + '.info.json')
|
try_rm(tc['file'] + '.info.json')
|
||||||
try:
|
try:
|
||||||
for retry in range(1, RETRIES + 1):
|
for retry in range(1, RETRIES + 1):
|
||||||
try:
|
try:
|
||||||
@ -145,9 +129,9 @@ def generator(test_case):
|
|||||||
self.assertTrue(key in info_dict.keys() and info_dict[key])
|
self.assertTrue(key in info_dict.keys() and info_dict[key])
|
||||||
finally:
|
finally:
|
||||||
for tc in test_cases:
|
for tc in test_cases:
|
||||||
_try_rm(tc['file'])
|
try_rm(tc['file'])
|
||||||
_try_rm(tc['file'] + '.part')
|
try_rm(tc['file'] + '.part')
|
||||||
_try_rm(tc['file'] + '.info.json')
|
try_rm(tc['file'] + '.info.json')
|
||||||
|
|
||||||
return test_template
|
return test_template
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import json
|
|
||||||
import io
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
# Allow direct execution
|
# Allow direct execution
|
||||||
@ -56,6 +54,7 @@ class TestYoutubeSubtitles(unittest.TestCase):
|
|||||||
subtitles = self.getSubtitles()
|
subtitles = self.getSubtitles()
|
||||||
self.assertEqual(md5(subtitles['en']), '356cdc577fde0c6783b9b822e7206ff7')
|
self.assertEqual(md5(subtitles['en']), '356cdc577fde0c6783b9b822e7206ff7')
|
||||||
def test_youtube_list_subtitles(self):
|
def test_youtube_list_subtitles(self):
|
||||||
|
self.DL.expect_warning(u'Video doesn\'t have automatic captions')
|
||||||
self.DL.params['listsubtitles'] = True
|
self.DL.params['listsubtitles'] = True
|
||||||
info_dict = self.getInfoDict()
|
info_dict = self.getInfoDict()
|
||||||
self.assertEqual(info_dict, None)
|
self.assertEqual(info_dict, None)
|
||||||
@ -66,6 +65,7 @@ class TestYoutubeSubtitles(unittest.TestCase):
|
|||||||
subtitles = self.getSubtitles()
|
subtitles = self.getSubtitles()
|
||||||
self.assertTrue(subtitles['it'] is not None)
|
self.assertTrue(subtitles['it'] is not None)
|
||||||
def test_youtube_nosubtitles(self):
|
def test_youtube_nosubtitles(self):
|
||||||
|
self.DL.expect_warning(u'video doesn\'t have subtitles')
|
||||||
self.url = 'sAjKT8FhjI8'
|
self.url = 'sAjKT8FhjI8'
|
||||||
self.DL.params['writesubtitles'] = True
|
self.DL.params['writesubtitles'] = True
|
||||||
self.DL.params['allsubtitles'] = True
|
self.DL.params['allsubtitles'] = True
|
||||||
|
5
tox.ini
Normal file
5
tox.ini
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[tox]
|
||||||
|
envlist = py26,py27,py33
|
||||||
|
[testenv]
|
||||||
|
deps = nose
|
||||||
|
commands = nosetests --with-coverage --cover-package=youtube_dl --cover-html --verbose test
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import errno
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -84,6 +85,11 @@ class YoutubeDL(object):
|
|||||||
cachedir: Location of the cache files in the filesystem.
|
cachedir: Location of the cache files in the filesystem.
|
||||||
None to disable filesystem cache.
|
None to disable filesystem cache.
|
||||||
noplaylist: Download single video instead of a playlist if in doubt.
|
noplaylist: Download single video instead of a playlist if in doubt.
|
||||||
|
age_limit: An integer representing the user's age in years.
|
||||||
|
Unsuitable videos for the given age are skipped.
|
||||||
|
downloadarchive: File name of a file where all downloads are recorded.
|
||||||
|
Videos already present in the file are not downloaded
|
||||||
|
again.
|
||||||
|
|
||||||
The following parameters are not used by YoutubeDL itself, they are used by
|
The following parameters are not used by YoutubeDL itself, they are used by
|
||||||
the FileDownloader:
|
the FileDownloader:
|
||||||
@ -309,6 +315,13 @@ class YoutubeDL(object):
|
|||||||
dateRange = self.params.get('daterange', DateRange())
|
dateRange = self.params.get('daterange', DateRange())
|
||||||
if date not in dateRange:
|
if date not in dateRange:
|
||||||
return u'[download] %s upload date is not in range %s' % (date_from_str(date).isoformat(), dateRange)
|
return u'[download] %s upload date is not in range %s' % (date_from_str(date).isoformat(), dateRange)
|
||||||
|
age_limit = self.params.get('age_limit')
|
||||||
|
if age_limit is not None:
|
||||||
|
if age_limit < info_dict.get('age_limit', 0):
|
||||||
|
return u'Skipping "' + title + '" because it is age restricted'
|
||||||
|
if self.in_download_archive(info_dict):
|
||||||
|
return (u'%(title)s has already been recorded in archive'
|
||||||
|
% info_dict)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def extract_info(self, url, download=True, ie_key=None, extra_info={}):
|
def extract_info(self, url, download=True, ie_key=None, extra_info={}):
|
||||||
@ -578,6 +591,8 @@ class YoutubeDL(object):
|
|||||||
self.report_error(u'postprocessing: %s' % str(err))
|
self.report_error(u'postprocessing: %s' % str(err))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.record_download_archive(info_dict)
|
||||||
|
|
||||||
def download(self, url_list):
|
def download(self, url_list):
|
||||||
"""Download a given list of URLs."""
|
"""Download a given list of URLs."""
|
||||||
if len(url_list) > 1 and self.fixed_template():
|
if len(url_list) > 1 and self.fixed_template():
|
||||||
@ -617,3 +632,26 @@ class YoutubeDL(object):
|
|||||||
os.remove(encodeFilename(filename))
|
os.remove(encodeFilename(filename))
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
self.report_warning(u'Unable to remove downloaded video file')
|
self.report_warning(u'Unable to remove downloaded video file')
|
||||||
|
|
||||||
|
def in_download_archive(self, info_dict):
|
||||||
|
fn = self.params.get('download_archive')
|
||||||
|
if fn is None:
|
||||||
|
return False
|
||||||
|
vid_id = info_dict['extractor'] + u' ' + info_dict['id']
|
||||||
|
try:
|
||||||
|
with locked_file(fn, 'r', encoding='utf-8') as archive_file:
|
||||||
|
for line in archive_file:
|
||||||
|
if line.strip() == vid_id:
|
||||||
|
return True
|
||||||
|
except IOError as ioe:
|
||||||
|
if ioe.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
return False
|
||||||
|
|
||||||
|
def record_download_archive(self, info_dict):
|
||||||
|
fn = self.params.get('download_archive')
|
||||||
|
if fn is None:
|
||||||
|
return
|
||||||
|
vid_id = info_dict['extractor'] + u' ' + info_dict['id']
|
||||||
|
with locked_file(fn, 'a', encoding='utf-8') as archive_file:
|
||||||
|
archive_file.write(vid_id + u'\n')
|
||||||
|
@ -36,6 +36,7 @@ __authors__ = (
|
|||||||
__license__ = 'Public Domain'
|
__license__ = 'Public Domain'
|
||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
|
import collections
|
||||||
import getpass
|
import getpass
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
@ -188,6 +189,12 @@ def parseOpts(overrideArguments=None):
|
|||||||
selection.add_option('--datebefore', metavar='DATE', dest='datebefore', help='download only videos uploaded before this date', default=None)
|
selection.add_option('--datebefore', metavar='DATE', dest='datebefore', help='download only videos uploaded before this date', default=None)
|
||||||
selection.add_option('--dateafter', metavar='DATE', dest='dateafter', help='download only videos uploaded after this date', default=None)
|
selection.add_option('--dateafter', metavar='DATE', dest='dateafter', help='download only videos uploaded after this date', default=None)
|
||||||
selection.add_option('--no-playlist', action='store_true', dest='noplaylist', help='download only the currently playing video', default=False)
|
selection.add_option('--no-playlist', action='store_true', dest='noplaylist', help='download only the currently playing video', default=False)
|
||||||
|
selection.add_option('--age-limit', metavar='YEARS', dest='age_limit',
|
||||||
|
help='download only videos suitable for the given age',
|
||||||
|
default=None, type=int)
|
||||||
|
selection.add_option('--download-archive', metavar='FILE',
|
||||||
|
dest='download_archive',
|
||||||
|
help='Download only videos not present in the archive file. Record all downloaded videos in it.')
|
||||||
|
|
||||||
|
|
||||||
authentication.add_option('-u', '--username',
|
authentication.add_option('-u', '--username',
|
||||||
@ -445,27 +452,7 @@ def _real_main(argv=None):
|
|||||||
all_urls = batchurls + args
|
all_urls = batchurls + args
|
||||||
all_urls = [url.strip() for url in all_urls]
|
all_urls = [url.strip() for url in all_urls]
|
||||||
|
|
||||||
# General configuration
|
opener = _setup_opener(jar=jar, opts=opts)
|
||||||
cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
|
|
||||||
if opts.proxy is not None:
|
|
||||||
if opts.proxy == '':
|
|
||||||
proxies = {}
|
|
||||||
else:
|
|
||||||
proxies = {'http': opts.proxy, 'https': opts.proxy}
|
|
||||||
else:
|
|
||||||
proxies = compat_urllib_request.getproxies()
|
|
||||||
# Set HTTPS proxy to HTTP one if given (https://github.com/rg3/youtube-dl/issues/805)
|
|
||||||
if 'http' in proxies and 'https' not in proxies:
|
|
||||||
proxies['https'] = proxies['http']
|
|
||||||
proxy_handler = compat_urllib_request.ProxyHandler(proxies)
|
|
||||||
https_handler = make_HTTPS_handler(opts)
|
|
||||||
opener = compat_urllib_request.build_opener(https_handler, proxy_handler, cookie_processor, YoutubeDLHandler())
|
|
||||||
# Delete the default user-agent header, which would otherwise apply in
|
|
||||||
# cases where our custom HTTP handler doesn't come into play
|
|
||||||
# (See https://github.com/rg3/youtube-dl/issues/1309 for details)
|
|
||||||
opener.addheaders =[]
|
|
||||||
compat_urllib_request.install_opener(opener)
|
|
||||||
socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words)
|
|
||||||
|
|
||||||
extractors = gen_extractors()
|
extractors = gen_extractors()
|
||||||
|
|
||||||
@ -482,6 +469,8 @@ def _real_main(argv=None):
|
|||||||
if not ie._WORKING:
|
if not ie._WORKING:
|
||||||
continue
|
continue
|
||||||
desc = getattr(ie, 'IE_DESC', ie.IE_NAME)
|
desc = getattr(ie, 'IE_DESC', ie.IE_NAME)
|
||||||
|
if desc is False:
|
||||||
|
continue
|
||||||
if hasattr(ie, 'SEARCH_KEY'):
|
if hasattr(ie, 'SEARCH_KEY'):
|
||||||
_SEARCHES = (u'cute kittens', u'slithering pythons', u'falling cat', u'angry poodle', u'purple fish', u'running tortoise')
|
_SEARCHES = (u'cute kittens', u'slithering pythons', u'falling cat', u'angry poodle', u'purple fish', u'running tortoise')
|
||||||
_COUNTS = (u'', u'5', u'10', u'all')
|
_COUNTS = (u'', u'5', u'10', u'all')
|
||||||
@ -635,6 +624,8 @@ def _real_main(argv=None):
|
|||||||
'daterange': date,
|
'daterange': date,
|
||||||
'cachedir': opts.cachedir,
|
'cachedir': opts.cachedir,
|
||||||
'youtube_print_sig_code': opts.youtube_print_sig_code,
|
'youtube_print_sig_code': opts.youtube_print_sig_code,
|
||||||
|
'age_limit': opts.age_limit,
|
||||||
|
'download_archive': opts.download_archive,
|
||||||
})
|
})
|
||||||
|
|
||||||
if opts.verbose:
|
if opts.verbose:
|
||||||
@ -654,7 +645,12 @@ def _real_main(argv=None):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
write_string(u'[debug] Python version %s - %s' %(platform.python_version(), platform_name()) + u'\n')
|
write_string(u'[debug] Python version %s - %s' %(platform.python_version(), platform_name()) + u'\n')
|
||||||
write_string(u'[debug] Proxy map: ' + str(proxy_handler.proxies) + u'\n')
|
|
||||||
|
proxy_map = {}
|
||||||
|
for handler in opener.handlers:
|
||||||
|
if hasattr(handler, 'proxies'):
|
||||||
|
proxy_map.update(handler.proxies)
|
||||||
|
write_string(u'[debug] Proxy map: ' + compat_str(proxy_map) + u'\n')
|
||||||
|
|
||||||
ydl.add_default_info_extractors()
|
ydl.add_default_info_extractors()
|
||||||
|
|
||||||
@ -692,6 +688,37 @@ def _real_main(argv=None):
|
|||||||
|
|
||||||
sys.exit(retcode)
|
sys.exit(retcode)
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_opener(jar=None, opts=None, timeout=300):
|
||||||
|
if opts is None:
|
||||||
|
FakeOptions = collections.namedtuple(
|
||||||
|
'FakeOptions', ['proxy', 'no_check_certificate'])
|
||||||
|
opts = FakeOptions(proxy=None, no_check_certificate=False)
|
||||||
|
|
||||||
|
cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
|
||||||
|
if opts.proxy is not None:
|
||||||
|
if opts.proxy == '':
|
||||||
|
proxies = {}
|
||||||
|
else:
|
||||||
|
proxies = {'http': opts.proxy, 'https': opts.proxy}
|
||||||
|
else:
|
||||||
|
proxies = compat_urllib_request.getproxies()
|
||||||
|
# Set HTTPS proxy to HTTP one if given (https://github.com/rg3/youtube-dl/issues/805)
|
||||||
|
if 'http' in proxies and 'https' not in proxies:
|
||||||
|
proxies['https'] = proxies['http']
|
||||||
|
proxy_handler = compat_urllib_request.ProxyHandler(proxies)
|
||||||
|
https_handler = make_HTTPS_handler(opts)
|
||||||
|
opener = compat_urllib_request.build_opener(
|
||||||
|
https_handler, proxy_handler, cookie_processor, YoutubeDLHandler())
|
||||||
|
# Delete the default user-agent header, which would otherwise apply in
|
||||||
|
# cases where our custom HTTP handler doesn't come into play
|
||||||
|
# (See https://github.com/rg3/youtube-dl/issues/1309 for details)
|
||||||
|
opener.addheaders = []
|
||||||
|
compat_urllib_request.install_opener(opener)
|
||||||
|
socket.setdefaulttimeout(timeout)
|
||||||
|
return opener
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
try:
|
try:
|
||||||
_real_main(argv)
|
_real_main(argv)
|
||||||
|
@ -117,6 +117,7 @@ from .veehd import VeeHDIE
|
|||||||
from .veoh import VeohIE
|
from .veoh import VeohIE
|
||||||
from .vevo import VevoIE
|
from .vevo import VevoIE
|
||||||
from .vice import ViceIE
|
from .vice import ViceIE
|
||||||
|
from .viddler import ViddlerIE
|
||||||
from .videofyme import VideofyMeIE
|
from .videofyme import VideofyMeIE
|
||||||
from .vimeo import VimeoIE, VimeoChannelIE
|
from .vimeo import VimeoIE, VimeoChannelIE
|
||||||
from .vine import VineIE
|
from .vine import VineIE
|
||||||
@ -140,6 +141,7 @@ from .youtube import (
|
|||||||
YoutubeShowIE,
|
YoutubeShowIE,
|
||||||
YoutubeSubscriptionsIE,
|
YoutubeSubscriptionsIE,
|
||||||
YoutubeRecommendedIE,
|
YoutubeRecommendedIE,
|
||||||
|
YoutubeTruncatedURLIE,
|
||||||
YoutubeWatchLaterIE,
|
YoutubeWatchLaterIE,
|
||||||
YoutubeFavouritesIE,
|
YoutubeFavouritesIE,
|
||||||
)
|
)
|
||||||
|
@ -115,7 +115,7 @@ class BlipTVIE(InfoExtractor):
|
|||||||
ext = umobj.group(1)
|
ext = umobj.group(1)
|
||||||
|
|
||||||
info = {
|
info = {
|
||||||
'id': data['item_id'],
|
'id': compat_str(data['item_id']),
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
'uploader': data['display_name'],
|
'uploader': data['display_name'],
|
||||||
'upload_date': upload_date,
|
'upload_date': upload_date,
|
||||||
|
@ -54,6 +54,7 @@ class InfoExtractor(object):
|
|||||||
view_count: How many users have watched the video on the platform.
|
view_count: How many users have watched the video on the platform.
|
||||||
urlhandle: [internal] The urlHandle to be used to download the file,
|
urlhandle: [internal] The urlHandle to be used to download the file,
|
||||||
like returned by urllib.request.urlopen
|
like returned by urllib.request.urlopen
|
||||||
|
age_limit: Age restriction for the video, as an integer (years)
|
||||||
formats: A list of dictionaries for each format available, it must
|
formats: A list of dictionaries for each format available, it must
|
||||||
be ordered from worst to best quality. Potential fields:
|
be ordered from worst to best quality. Potential fields:
|
||||||
* url Mandatory. The URL of the video file
|
* url Mandatory. The URL of the video file
|
||||||
@ -318,6 +319,15 @@ class InfoExtractor(object):
|
|||||||
self._og_regex('video')],
|
self._og_regex('video')],
|
||||||
html, name, **kargs)
|
html, name, **kargs)
|
||||||
|
|
||||||
|
def _rta_search(self, html):
|
||||||
|
# See http://www.rtalabel.org/index.php?content=howtofaq#single
|
||||||
|
if re.search(r'(?ix)<meta\s+name="rating"\s+'
|
||||||
|
r' content="RTA-5042-1996-1400-1577-RTA"',
|
||||||
|
html):
|
||||||
|
return 18
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class SearchInfoExtractor(InfoExtractor):
|
class SearchInfoExtractor(InfoExtractor):
|
||||||
"""
|
"""
|
||||||
Base class for paged search queries extractors.
|
Base class for paged search queries extractors.
|
||||||
|
@ -117,7 +117,7 @@ class GenericIE(InfoExtractor):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
# since this is the last-resort InfoExtractor, if
|
# since this is the last-resort InfoExtractor, if
|
||||||
# this error is thrown, it'll be thrown here
|
# this error is thrown, it'll be thrown here
|
||||||
raise ExtractorError(u'Invalid URL: %s' % url)
|
raise ExtractorError(u'Failed to download URL: %s' % url)
|
||||||
|
|
||||||
self.report_extraction(video_id)
|
self.report_extraction(video_id)
|
||||||
# Look for BrightCove:
|
# Look for BrightCove:
|
||||||
@ -149,12 +149,12 @@ class GenericIE(InfoExtractor):
|
|||||||
# HTML5 video
|
# HTML5 video
|
||||||
mobj = re.search(r'<video[^<]*(?:>.*?<source.*?)? src="([^"]+)"', webpage, flags=re.DOTALL)
|
mobj = re.search(r'<video[^<]*(?:>.*?<source.*?)? src="([^"]+)"', webpage, flags=re.DOTALL)
|
||||||
if mobj is None:
|
if mobj is None:
|
||||||
raise ExtractorError(u'Invalid URL: %s' % url)
|
raise ExtractorError(u'Unsupported URL: %s' % url)
|
||||||
|
|
||||||
# It's possible that one of the regexes
|
# It's possible that one of the regexes
|
||||||
# matched, but returned an empty group:
|
# matched, but returned an empty group:
|
||||||
if mobj.group(1) is None:
|
if mobj.group(1) is None:
|
||||||
raise ExtractorError(u'Invalid URL: %s' % url)
|
raise ExtractorError(u'Did not find a valid video URL at %s' % url)
|
||||||
|
|
||||||
video_url = mobj.group(1)
|
video_url = mobj.group(1)
|
||||||
video_url = compat_urlparse.urljoin(url, video_url)
|
video_url = compat_urlparse.urljoin(url, video_url)
|
||||||
|
@ -41,7 +41,8 @@ class GooglePlusIE(InfoExtractor):
|
|||||||
|
|
||||||
# Extract update date
|
# Extract update date
|
||||||
upload_date = self._html_search_regex(
|
upload_date = self._html_search_regex(
|
||||||
['title="Timestamp">(.*?)</a>', r'<a.+?class="g-M.+?>(.+?)</a>'],
|
r'''(?x)<a.+?class="o-T-s\s[^"]+"\s+style="display:\s*none"\s*>
|
||||||
|
([0-9]{4}-[0-9]{2}-[0-9]{2})</a>''',
|
||||||
webpage, u'upload date', fatal=False)
|
webpage, u'upload date', fatal=False)
|
||||||
if upload_date:
|
if upload_date:
|
||||||
# Convert timestring to a format suitable for filename
|
# Convert timestring to a format suitable for filename
|
||||||
|
@ -6,6 +6,7 @@ import xml.etree.ElementTree
|
|||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
|
||||||
|
|
||||||
class JeuxVideoIE(InfoExtractor):
|
class JeuxVideoIE(InfoExtractor):
|
||||||
_VALID_URL = r'http://.*?\.jeuxvideo\.com/.*/(.*?)-\d+\.htm'
|
_VALID_URL = r'http://.*?\.jeuxvideo\.com/.*/(.*?)-\d+\.htm'
|
||||||
|
|
||||||
@ -23,25 +24,29 @@ class JeuxVideoIE(InfoExtractor):
|
|||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
title = re.match(self._VALID_URL, url).group(1)
|
title = re.match(self._VALID_URL, url).group(1)
|
||||||
webpage = self._download_webpage(url, title)
|
webpage = self._download_webpage(url, title)
|
||||||
m_download = re.search(r'<param name="flashvars" value="config=(.*?)" />', webpage)
|
xml_link = self._html_search_regex(
|
||||||
|
r'<param name="flashvars" value="config=(.*?)" />',
|
||||||
xml_link = m_download.group(1)
|
webpage, u'config URL')
|
||||||
|
|
||||||
id = re.search(r'http://www.jeuxvideo.com/config/\w+/0011/(.*?)/\d+_player\.xml', xml_link).group(1)
|
video_id = self._search_regex(
|
||||||
|
r'http://www\.jeuxvideo\.com/config/\w+/\d+/(.*?)/\d+_player\.xml',
|
||||||
|
xml_link, u'video ID')
|
||||||
|
|
||||||
xml_config = self._download_webpage(xml_link, title,
|
xml_config = self._download_webpage(
|
||||||
'Downloading XML config')
|
xml_link, title, u'Downloading XML config')
|
||||||
config = xml.etree.ElementTree.fromstring(xml_config.encode('utf-8'))
|
config = xml.etree.ElementTree.fromstring(xml_config.encode('utf-8'))
|
||||||
info = re.search(r'<format\.json>(.*?)</format\.json>',
|
info_json = self._search_regex(
|
||||||
xml_config, re.MULTILINE|re.DOTALL).group(1)
|
r'(?sm)<format\.json>(.*?)</format\.json>',
|
||||||
info = json.loads(info)['versions'][0]
|
xml_config, u'JSON information')
|
||||||
|
info = json.loads(info_json)['versions'][0]
|
||||||
|
|
||||||
video_url = 'http://video720.jeuxvideo.com/' + info['file']
|
video_url = 'http://video720.jeuxvideo.com/' + info['file']
|
||||||
|
|
||||||
return {'id': id,
|
return {
|
||||||
'title' : config.find('titre_video').text,
|
'id': video_id,
|
||||||
'ext' : 'mp4',
|
'title': config.find('titre_video').text,
|
||||||
'url' : video_url,
|
'ext': 'mp4',
|
||||||
'description': self._og_search_description(webpage),
|
'url': video_url,
|
||||||
'thumbnail': config.find('image').text,
|
'description': self._og_search_description(webpage),
|
||||||
}
|
'thumbnail': config.find('image').text,
|
||||||
|
}
|
||||||
|
@ -38,6 +38,7 @@ class PornotubeIE(InfoExtractor):
|
|||||||
VIDEO_UPLOADED_RE = r'<div class="video_added_by">Added (?P<date>[0-9\/]+) by'
|
VIDEO_UPLOADED_RE = r'<div class="video_added_by">Added (?P<date>[0-9\/]+) by'
|
||||||
upload_date = self._html_search_regex(VIDEO_UPLOADED_RE, webpage, u'upload date', fatal=False)
|
upload_date = self._html_search_regex(VIDEO_UPLOADED_RE, webpage, u'upload date', fatal=False)
|
||||||
if upload_date: upload_date = unified_strdate(upload_date)
|
if upload_date: upload_date = unified_strdate(upload_date)
|
||||||
|
age_limit = self._rta_search(webpage)
|
||||||
|
|
||||||
info = {'id': video_id,
|
info = {'id': video_id,
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
@ -45,6 +46,7 @@ class PornotubeIE(InfoExtractor):
|
|||||||
'upload_date': upload_date,
|
'upload_date': upload_date,
|
||||||
'title': video_title,
|
'title': video_title,
|
||||||
'ext': 'flv',
|
'ext': 'flv',
|
||||||
'format': 'flv'}
|
'format': 'flv',
|
||||||
|
'age_limit': age_limit}
|
||||||
|
|
||||||
return [info]
|
return [info]
|
||||||
|
@ -30,9 +30,14 @@ class RedTubeIE(InfoExtractor):
|
|||||||
r'<h1 class="videoTitle slidePanelMovable">(.+?)</h1>',
|
r'<h1 class="videoTitle slidePanelMovable">(.+?)</h1>',
|
||||||
webpage, u'title')
|
webpage, u'title')
|
||||||
|
|
||||||
|
# No self-labeling, but they describe themselves as
|
||||||
|
# "Home of Videos Porno"
|
||||||
|
age_limit = 18
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
'ext': video_extension,
|
'ext': video_extension,
|
||||||
'title': video_title,
|
'title': video_title,
|
||||||
|
'age_limit': age_limit,
|
||||||
}
|
}
|
||||||
|
64
youtube_dl/extractor/viddler.py
Normal file
64
youtube_dl/extractor/viddler.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
from .common import InfoExtractor
|
||||||
|
from ..utils import (
|
||||||
|
determine_ext,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ViddlerIE(InfoExtractor):
|
||||||
|
_VALID_URL = r'(?P<domain>https?://(?:www\.)?viddler.com)/(?:v|embed|player)/(?P<id>[0-9]+)'
|
||||||
|
_TEST = {
|
||||||
|
u"url": u"http://www.viddler.com/v/43903784",
|
||||||
|
u'file': u'43903784.mp4',
|
||||||
|
u'md5': u'fbbaedf7813e514eb7ca30410f439ac9',
|
||||||
|
u'info_dict': {
|
||||||
|
u"title": u"Video Made Easy",
|
||||||
|
u"uploader": u"viddler",
|
||||||
|
u"duration": 100.89,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
mobj = re.match(self._VALID_URL, url)
|
||||||
|
video_id = mobj.group('id')
|
||||||
|
|
||||||
|
embed_url = mobj.group('domain') + u'/embed/' + video_id
|
||||||
|
webpage = self._download_webpage(embed_url, video_id)
|
||||||
|
|
||||||
|
video_sources_code = self._search_regex(
|
||||||
|
r"(?ms)sources\s*:\s*(\{.*?\})", webpage, u'video URLs')
|
||||||
|
video_sources = json.loads(video_sources_code.replace("'", '"'))
|
||||||
|
|
||||||
|
formats = [{
|
||||||
|
'url': video_url,
|
||||||
|
'format': format_id,
|
||||||
|
} for video_url, format_id in video_sources.items()]
|
||||||
|
|
||||||
|
title = self._html_search_regex(
|
||||||
|
r"title\s*:\s*'([^']*)'", webpage, u'title')
|
||||||
|
uploader = self._html_search_regex(
|
||||||
|
r"authorName\s*:\s*'([^']*)'", webpage, u'uploader', fatal=False)
|
||||||
|
duration_s = self._html_search_regex(
|
||||||
|
r"duration\s*:\s*([0-9.]*)", webpage, u'duration', fatal=False)
|
||||||
|
duration = float(duration_s) if duration_s else None
|
||||||
|
thumbnail = self._html_search_regex(
|
||||||
|
r"thumbnail\s*:\s*'([^']*)'",
|
||||||
|
webpage, u'thumbnail', fatal=False)
|
||||||
|
|
||||||
|
info = {
|
||||||
|
'_type': 'video',
|
||||||
|
'id': video_id,
|
||||||
|
'title': title,
|
||||||
|
'thumbnail': thumbnail,
|
||||||
|
'uploader': uploader,
|
||||||
|
'duration': duration,
|
||||||
|
'formats': formats,
|
||||||
|
}
|
||||||
|
|
||||||
|
# TODO: Remove when #980 has been merged
|
||||||
|
info['formats'][-1]['ext'] = determine_ext(info['formats'][-1]['url'])
|
||||||
|
info.update(info['formats'][-1])
|
||||||
|
|
||||||
|
return info
|
@ -17,7 +17,7 @@ class VimeoIE(InfoExtractor):
|
|||||||
"""Information extractor for vimeo.com."""
|
"""Information extractor for vimeo.com."""
|
||||||
|
|
||||||
# _VALID_URL matches Vimeo URLs
|
# _VALID_URL matches Vimeo URLs
|
||||||
_VALID_URL = r'(?P<proto>https?://)?(?:(?:www|player)\.)?vimeo(?P<pro>pro)?\.com/(?:(?:(?:groups|album)/[^/]+)|(?:.*?)/)?(?P<direct_link>play_redirect_hls\?clip_id=)?(?:videos?/)?(?P<id>[0-9]+)(?:[?].*)?$'
|
_VALID_URL = r'(?P<proto>https?://)?(?:(?:www|player)\.)?vimeo(?P<pro>pro)?\.com/(?:(?:(?:groups|album)/[^/]+)|(?:.*?)/)?(?P<direct_link>play_redirect_hls\?clip_id=)?(?:videos?/)?(?P<id>[0-9]+)/?(?:[?].*)?$'
|
||||||
_NETRC_MACHINE = 'vimeo'
|
_NETRC_MACHINE = 'vimeo'
|
||||||
IE_NAME = u'vimeo'
|
IE_NAME = u'vimeo'
|
||||||
_TESTS = [
|
_TESTS = [
|
||||||
|
@ -51,6 +51,7 @@ class YouPornIE(InfoExtractor):
|
|||||||
req = compat_urllib_request.Request(url)
|
req = compat_urllib_request.Request(url)
|
||||||
req.add_header('Cookie', 'age_verified=1')
|
req.add_header('Cookie', 'age_verified=1')
|
||||||
webpage = self._download_webpage(req, video_id)
|
webpage = self._download_webpage(req, video_id)
|
||||||
|
age_limit = self._rta_search(webpage)
|
||||||
|
|
||||||
# Get JSON parameters
|
# Get JSON parameters
|
||||||
json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, u'JSON parameters')
|
json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, u'JSON parameters')
|
||||||
@ -115,7 +116,8 @@ class YouPornIE(InfoExtractor):
|
|||||||
'ext': extension,
|
'ext': extension,
|
||||||
'format': format,
|
'format': format,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'description': video_description
|
'description': video_description,
|
||||||
|
'age_limit': age_limit,
|
||||||
})
|
})
|
||||||
|
|
||||||
if self._downloader.params.get('listformats', None):
|
if self._downloader.params.get('listformats', None):
|
||||||
|
@ -1250,9 +1250,6 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
|
|||||||
return url_map
|
return url_map
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
if re.match(r'(?:https?://)?[^/]+/watch\?feature=[a-z_]+$', url):
|
|
||||||
self._downloader.report_warning(u'Did you forget to quote the URL? Remember that & is a meta-character in most shells, so you want to put the URL in quotes, like youtube-dl \'http://www.youtube.com/watch?feature=foo&v=BaW_jenozKc\' (or simply youtube-dl BaW_jenozKc ).')
|
|
||||||
|
|
||||||
# Extract original video URL from URL with redirection, like age verification, using next_url parameter
|
# Extract original video URL from URL with redirection, like age verification, using next_url parameter
|
||||||
mobj = re.search(self._NEXT_URL_RE, url)
|
mobj = re.search(self._NEXT_URL_RE, url)
|
||||||
if mobj:
|
if mobj:
|
||||||
@ -1495,7 +1492,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
|
|||||||
'description': video_description,
|
'description': video_description,
|
||||||
'player_url': player_url,
|
'player_url': player_url,
|
||||||
'subtitles': video_subtitles,
|
'subtitles': video_subtitles,
|
||||||
'duration': video_duration
|
'duration': video_duration,
|
||||||
|
'age_limit': 18 if age_gate else 0,
|
||||||
})
|
})
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@ -1636,7 +1634,7 @@ class YoutubeChannelIE(InfoExtractor):
|
|||||||
|
|
||||||
class YoutubeUserIE(InfoExtractor):
|
class YoutubeUserIE(InfoExtractor):
|
||||||
IE_DESC = u'YouTube.com user videos (URL or "ytuser" keyword)'
|
IE_DESC = u'YouTube.com user videos (URL or "ytuser" keyword)'
|
||||||
_VALID_URL = r'(?:(?:(?:https?://)?(?:\w+\.)?youtube\.com/(?:user/)?)|ytuser:)(?!feed/)([A-Za-z0-9_-]+)'
|
_VALID_URL = r'(?:(?:(?:https?://)?(?:\w+\.)?youtube\.com/(?:user/)?(?!watch(?:$|[^a-z_A-Z0-9-])))|ytuser:)(?!feed/)([A-Za-z0-9_-]+)'
|
||||||
_TEMPLATE_URL = 'http://gdata.youtube.com/feeds/api/users/%s'
|
_TEMPLATE_URL = 'http://gdata.youtube.com/feeds/api/users/%s'
|
||||||
_GDATA_PAGE_SIZE = 50
|
_GDATA_PAGE_SIZE = 50
|
||||||
_GDATA_URL = 'http://gdata.youtube.com/feeds/api/users/%s/uploads?max-results=%d&start-index=%d&alt=json'
|
_GDATA_URL = 'http://gdata.youtube.com/feeds/api/users/%s/uploads?max-results=%d&start-index=%d&alt=json'
|
||||||
@ -1829,3 +1827,18 @@ class YoutubeFavouritesIE(YoutubeBaseInfoExtractor):
|
|||||||
webpage = self._download_webpage('https://www.youtube.com/my_favorites', 'Youtube Favourites videos')
|
webpage = self._download_webpage('https://www.youtube.com/my_favorites', 'Youtube Favourites videos')
|
||||||
playlist_id = self._search_regex(r'list=(.+?)["&]', webpage, u'favourites playlist id')
|
playlist_id = self._search_regex(r'list=(.+?)["&]', webpage, u'favourites playlist id')
|
||||||
return self.url_result(playlist_id, 'YoutubePlaylist')
|
return self.url_result(playlist_id, 'YoutubePlaylist')
|
||||||
|
|
||||||
|
|
||||||
|
class YoutubeTruncatedURLIE(InfoExtractor):
|
||||||
|
IE_NAME = 'youtube:truncated_url'
|
||||||
|
IE_DESC = False # Do not list
|
||||||
|
_VALID_URL = r'(?:https?://)?[^/]+/watch\?feature=[a-z_]+$'
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
raise ExtractorError(
|
||||||
|
u'Did you forget to quote the URL? Remember that & is a meta '
|
||||||
|
u'character in most shells, so you want to put the URL in quotes, '
|
||||||
|
u'like youtube-dl '
|
||||||
|
u'\'http://www.youtube.com/watch?feature=foo&v=BaW_jenozKc\''
|
||||||
|
u' (or simply youtube-dl BaW_jenozKc ).',
|
||||||
|
expected=True)
|
||||||
|
@ -175,7 +175,7 @@ def compat_ord(c):
|
|||||||
compiled_regex_type = type(re.compile(''))
|
compiled_regex_type = type(re.compile(''))
|
||||||
|
|
||||||
std_headers = {
|
std_headers = {
|
||||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0',
|
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 (Chrome)',
|
||||||
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
|
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
'Accept-Encoding': 'gzip, deflate',
|
'Accept-Encoding': 'gzip, deflate',
|
||||||
@ -830,3 +830,99 @@ def get_cachedir(params={}):
|
|||||||
cache_root = os.environ.get('XDG_CACHE_HOME',
|
cache_root = os.environ.get('XDG_CACHE_HOME',
|
||||||
os.path.expanduser('~/.cache'))
|
os.path.expanduser('~/.cache'))
|
||||||
return params.get('cachedir', os.path.join(cache_root, 'youtube-dl'))
|
return params.get('cachedir', os.path.join(cache_root, 'youtube-dl'))
|
||||||
|
|
||||||
|
|
||||||
|
# Cross-platform file locking
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
import ctypes.wintypes
|
||||||
|
import msvcrt
|
||||||
|
|
||||||
|
class OVERLAPPED(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
('Internal', ctypes.wintypes.LPVOID),
|
||||||
|
('InternalHigh', ctypes.wintypes.LPVOID),
|
||||||
|
('Offset', ctypes.wintypes.DWORD),
|
||||||
|
('OffsetHigh', ctypes.wintypes.DWORD),
|
||||||
|
('hEvent', ctypes.wintypes.HANDLE),
|
||||||
|
]
|
||||||
|
|
||||||
|
kernel32 = ctypes.windll.kernel32
|
||||||
|
LockFileEx = kernel32.LockFileEx
|
||||||
|
LockFileEx.argtypes = [
|
||||||
|
ctypes.wintypes.HANDLE, # hFile
|
||||||
|
ctypes.wintypes.DWORD, # dwFlags
|
||||||
|
ctypes.wintypes.DWORD, # dwReserved
|
||||||
|
ctypes.wintypes.DWORD, # nNumberOfBytesToLockLow
|
||||||
|
ctypes.wintypes.DWORD, # nNumberOfBytesToLockHigh
|
||||||
|
ctypes.POINTER(OVERLAPPED) # Overlapped
|
||||||
|
]
|
||||||
|
LockFileEx.restype = ctypes.wintypes.BOOL
|
||||||
|
UnlockFileEx = kernel32.UnlockFileEx
|
||||||
|
UnlockFileEx.argtypes = [
|
||||||
|
ctypes.wintypes.HANDLE, # hFile
|
||||||
|
ctypes.wintypes.DWORD, # dwReserved
|
||||||
|
ctypes.wintypes.DWORD, # nNumberOfBytesToLockLow
|
||||||
|
ctypes.wintypes.DWORD, # nNumberOfBytesToLockHigh
|
||||||
|
ctypes.POINTER(OVERLAPPED) # Overlapped
|
||||||
|
]
|
||||||
|
UnlockFileEx.restype = ctypes.wintypes.BOOL
|
||||||
|
whole_low = 0xffffffff
|
||||||
|
whole_high = 0x7fffffff
|
||||||
|
|
||||||
|
def _lock_file(f, exclusive):
|
||||||
|
overlapped = OVERLAPPED()
|
||||||
|
overlapped.Offset = 0
|
||||||
|
overlapped.OffsetHigh = 0
|
||||||
|
overlapped.hEvent = 0
|
||||||
|
f._lock_file_overlapped_p = ctypes.pointer(overlapped)
|
||||||
|
handle = msvcrt.get_osfhandle(f.fileno())
|
||||||
|
if not LockFileEx(handle, 0x2 if exclusive else 0x0, 0,
|
||||||
|
whole_low, whole_high, f._lock_file_overlapped_p):
|
||||||
|
raise OSError('Locking file failed: %r' % ctypes.FormatError())
|
||||||
|
|
||||||
|
def _unlock_file(f):
|
||||||
|
assert f._lock_file_overlapped_p
|
||||||
|
handle = msvcrt.get_osfhandle(f.fileno())
|
||||||
|
if not UnlockFileEx(handle, 0,
|
||||||
|
whole_low, whole_high, f._lock_file_overlapped_p):
|
||||||
|
raise OSError('Unlocking file failed: %r' % ctypes.FormatError())
|
||||||
|
|
||||||
|
else:
|
||||||
|
import fcntl
|
||||||
|
|
||||||
|
def _lock_file(f, exclusive):
|
||||||
|
fcntl.lockf(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
|
||||||
|
|
||||||
|
def _unlock_file(f):
|
||||||
|
fcntl.lockf(f, fcntl.LOCK_UN)
|
||||||
|
|
||||||
|
|
||||||
|
class locked_file(object):
|
||||||
|
def __init__(self, filename, mode, encoding=None):
|
||||||
|
assert mode in ['r', 'a', 'w']
|
||||||
|
self.f = io.open(filename, mode, encoding=encoding)
|
||||||
|
self.mode = mode
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
exclusive = self.mode != 'r'
|
||||||
|
try:
|
||||||
|
_lock_file(self.f, exclusive)
|
||||||
|
except IOError:
|
||||||
|
self.f.close()
|
||||||
|
raise
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, etype, value, traceback):
|
||||||
|
try:
|
||||||
|
_unlock_file(self.f)
|
||||||
|
finally:
|
||||||
|
self.f.close()
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.f)
|
||||||
|
|
||||||
|
def write(self, *args):
|
||||||
|
return self.f.write(*args)
|
||||||
|
|
||||||
|
def read(self, *args):
|
||||||
|
return self.f.read(*args)
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
|
|
||||||
__version__ = '2013.10.04'
|
__version__ = '2013.10.07'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user