Skip to content

Commit

Permalink
PEP8: applied even more rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouke Waleson committed Nov 23, 2014
1 parent 2514d26 commit 9e1a5b8
Show file tree
Hide file tree
Showing 77 changed files with 227 additions and 223 deletions.
2 changes: 1 addition & 1 deletion devscripts/buildserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def win_service_set_status(handle, status_code):

def win_service_main(service_name, real_main, argc, argv_raw):
try:
#args = [argv_raw[i].value for i in range(argc)]
# args = [argv_raw[i].value for i in range(argc)]
stop_event = threading.Event()
handler = HandlerEx(functools.partial(stop_event, win_service_handler))
h = advapi32.RegisterServiceCtrlHandlerExW(service_name, handler, None)
Expand Down
2 changes: 1 addition & 1 deletion devscripts/fish-completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def build_completion(opt_parser):
for group in opt_parser.option_groups:
for option in group.option_list:
long_option = option.get_opt_string().strip('-')
help_msg = shell_quote([option.help])
shell_quote([option.help])
complete_cmd = ['complete', '--command', 'youtube-dl', '--long-option', long_option]
if option._short_opts:
complete_cmd += ['--short-option', option._short_opts[0].strip('-')]
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import print_function

import os.path
import pkg_resources
import warnings
import sys

Expand Down
8 changes: 4 additions & 4 deletions test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ def expect_info_dict(self, expected_dict, got_dict):
elif isinstance(expected, type):
got = got_dict.get(info_field)
self.assertTrue(isinstance(got, expected),
'Expected type %r for field %s, but got value %r of type %r' % (expected, info_field, got, type(got)))
'Expected type %r for field %s, but got value %r of type %r' % (expected, info_field, got, type(got)))
else:
if isinstance(expected, compat_str) and expected.startswith('md5:'):
got = 'md5:' + md5(got_dict.get(info_field))
else:
got = got_dict.get(info_field)
self.assertEqual(expected, got,
'invalid value for field %s, expected %r, got %r' % (info_field, expected, got))
'invalid value for field %s, expected %r, got %r' % (info_field, expected, got))

# Check for the presence of mandatory fields
if got_dict.get('_type') != 'playlist':
Expand All @@ -135,8 +135,8 @@ def expect_info_dict(self, expected_dict, got_dict):

# Are checkable fields missing from the test case definition?
test_info_dict = dict((key, value if not isinstance(value, compat_str) or len(value) < 250 else 'md5:' + md5(value))
for key, value in got_dict.items()
if value and key in ('title', 'description', 'uploader', 'upload_date', 'timestamp', 'uploader_id', 'location'))
for key, value in got_dict.items()
if value and key in ('title', 'description', 'uploader', 'upload_date', 'timestamp', 'uploader_id', 'location'))
missing_keys = set(test_info_dict.keys()) - set(expected_dict.keys())
if missing_keys:
def _repr(v):
Expand Down
22 changes: 12 additions & 10 deletions youtube_dl/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _bidi_workaround(self, message):
self._output_process.stdin.write((message + '\n').encode('utf-8'))
self._output_process.stdin.flush()
res = ''.join(self._output_channel.readline().decode('utf-8')
for _ in range(line_count))
for _ in range(line_count))
return res[:-len('\n')]

def to_screen(self, message, skip_eol=False):
Expand Down Expand Up @@ -701,13 +701,15 @@ def make_result(embedded_info):
'It needs to be updated.' % ie_result.get('extractor'))

def _fixup(r):
self.add_extra_info(r,
self.add_extra_info(
r,
{
'extractor': ie_result['extractor'],
'webpage_url': ie_result['webpage_url'],
'webpage_url_basename': url_basename(ie_result['webpage_url']),
'extractor_key': ie_result['extractor_key'],
})
}
)
return r
ie_result['entries'] = [
self.process_ie_result(_fixup(r), download, extra_info)
Expand Down Expand Up @@ -857,14 +859,14 @@ def process_video_result(self, info_dict, download=True):
# Two formats have been requested like '137+139'
format_1, format_2 = rf.split('+')
formats_info = (self.select_format(format_1, formats),
self.select_format(format_2, formats))
self.select_format(format_2, formats))
if all(formats_info):
# The first format must contain the video and the
# second the audio
if formats_info[0].get('vcodec') == 'none':
self.report_error('The first format must '
'contain the video, try using '
'"-f %s+%s"' % (format_2, format_1))
'contain the video, try using '
'"-f %s+%s"' % (format_2, format_1))
return
selected_format = {
'requested_formats': formats_info,
Expand Down Expand Up @@ -1042,10 +1044,10 @@ def process_info(self, info_dict):
with open(thumb_filename, 'wb') as thumbf:
shutil.copyfileobj(uf, thumbf)
self.to_screen('[%s] %s: Writing thumbnail to: %s' %
(info_dict['extractor'], info_dict['id'], thumb_filename))
(info_dict['extractor'], info_dict['id'], thumb_filename))
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
self.report_warning('Unable to download thumbnail "%s": %s' %
(info_dict['thumbnail'], compat_str(err)))
(info_dict['thumbnail'], compat_str(err)))

if not self.params.get('skip_download', False):
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(filename)):
Expand All @@ -1066,8 +1068,8 @@ def dl(name, info):
if not merger._executable:
postprocessors = []
self.report_warning('You have requested multiple '
'formats but ffmpeg or avconv are not installed.'
' The formats won\'t be merged')
'formats but ffmpeg or avconv are not installed.'
' The formats won\'t be merged')
else:
postprocessors = [merger]
for f in info_dict['requested_formats']:
Expand Down
6 changes: 3 additions & 3 deletions youtube_dl/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def compat_urllib_parse_unquote(string, encoding='utf-8', errors='replace'):
# Python 2's version is apparently totally broken

def _parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
encoding='utf-8', errors='replace'):
encoding='utf-8', errors='replace'):
qs, _coerce_result = qs, unicode
pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
r = []
Expand Down Expand Up @@ -145,10 +145,10 @@ def _parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
return r

def compat_parse_qs(qs, keep_blank_values=False, strict_parsing=False,
encoding='utf-8', errors='replace'):
encoding='utf-8', errors='replace'):
parsed_result = {}
pairs = _parse_qsl(qs, keep_blank_values, strict_parsing,
encoding=encoding, errors=errors)
encoding=encoding, errors=errors)
for name, value in pairs:
if name in parsed_result:
parsed_result[name].append(value)
Expand Down
12 changes: 7 additions & 5 deletions youtube_dl/downloader/f4m.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,15 @@ def real_download(self, filename, info_dict):
self.to_screen('[download] Downloading f4m manifest')
manifest = self.ydl.urlopen(man_url).read()
self.report_destination(filename)
http_dl = HttpQuietDownloader(self.ydl,
http_dl = HttpQuietDownloader(
self.ydl,
{
'continuedl': True,
'quiet': True,
'noprogress': True,
'test': self.params.get('test', False),
})
}
)

doc = etree.fromstring(manifest)
formats = [(int(f.attrib.get('bitrate', -1)), f) for f in doc.findall(_add_ns('media'))]
Expand Down Expand Up @@ -277,7 +279,7 @@ def real_download(self, filename, info_dict):
def frag_progress_hook(status):
frag_total_bytes = status.get('total_bytes', 0)
estimated_size = (state['downloaded_bytes'] +
(total_frags - state['frag_counter']) * frag_total_bytes)
(total_frags - state['frag_counter']) * frag_total_bytes)
if status['status'] == 'finished':
state['downloaded_bytes'] += frag_total_bytes
state['frag_counter'] += 1
Expand All @@ -287,13 +289,13 @@ def frag_progress_hook(status):
frag_downloaded_bytes = status['downloaded_bytes']
byte_counter = state['downloaded_bytes'] + frag_downloaded_bytes
frag_progress = self.calc_percent(frag_downloaded_bytes,
frag_total_bytes)
frag_total_bytes)
progress = self.calc_percent(state['frag_counter'], total_frags)
progress += frag_progress / float(total_frags)

eta = self.calc_eta(start, time.time(), estimated_size, byte_counter)
self.report_progress(progress, format_bytes(estimated_size),
status.get('speed'), eta)
status.get('speed'), eta)
http_dl.add_progress_hook(frag_progress_hook)

frags_filenames = []
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/appletrailers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _clean_json(m):
for li in doc.findall('./div/ul/li'):
on_click = li.find('.//a').attrib['onClick']
trailer_info_json = self._search_regex(self._JSON_RE,
on_click, 'trailer info')
on_click, 'trailer info')
trailer_info = json.loads(trailer_info_json)
title = trailer_info['title']
video_id = movie + '-' + re.sub(r'[^a-zA-Z0-9]', '', title).lower()
Expand Down
6 changes: 3 additions & 3 deletions youtube_dl/extractor/bambuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
info_url = ('http://player-c.api.bambuser.com/getVideo.json?'
'&api_key=%s&vid=%s' % (self._API_KEY, video_id))
'&api_key=%s&vid=%s' % (self._API_KEY, video_id))
info_json = self._download_webpage(info_url, video_id)
info = json.loads(info_json)['result']

Expand Down Expand Up @@ -74,8 +74,8 @@ def _real_extract(self, url):
last_id = ''
for i in itertools.count(1):
req_url = ('http://bambuser.com/xhr-api/index.php?username={user}'
'&sort=created&access_mode=0%2C1%2C2&limit={count}'
'&method=broadcast&format=json&vid_older_than={last}'
'&sort=created&access_mode=0%2C1%2C2&limit={count}'
'&method=broadcast&format=json&vid_older_than={last}'
).format(user=user, count=self._STEP, last=last_id)
req = compat_urllib_request.Request(req_url)
# Without setting this header, we wouldn't get any result
Expand Down
4 changes: 2 additions & 2 deletions youtube_dl/extractor/bbccouk.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def _real_extract(self, url):
webpage = self._download_webpage(url, group_id, 'Downloading video page')
if re.search(r'id="emp-error" class="notinuk">', webpage):
raise ExtractorError('Currently BBC iPlayer TV programmes are available to play in the UK only',
expected=True)
expected=True)

playlist = self._download_xml('http://www.bbc.co.uk/iplayer/playlist/%s' % group_id, group_id,
'Downloading playlist XML')
'Downloading playlist XML')

no_items = playlist.find('./{http://bbc.co.uk/2008/emp/playlist}noItems')
if no_items is not None:
Expand Down
3 changes: 1 addition & 2 deletions youtube_dl/extractor/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class CNNIE(InfoExtractor):
'duration': 135,
'upload_date': '20130609',
},
},
{
}, {
"url": "http://edition.cnn.com/video/?/video/us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+rss%2Fcnn_topstories+%28RSS%3A+Top+Stories%29",
"md5": "b5cc60c60a3477d185af8f19a2a26f4e",
"info_dict": {
Expand Down
79 changes: 39 additions & 40 deletions youtube_dl/extractor/collegehumor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,46 @@
class CollegeHumorIE(InfoExtractor):
_VALID_URL = r'^(?:https?://)?(?:www\.)?collegehumor\.com/(video|embed|e)/(?P<videoid>[0-9]+)/?(?P<shorttitle>.*)$'

_TESTS = [{
'url': 'http://www.collegehumor.com/video/6902724/comic-con-cosplay-catastrophe',
'md5': 'dcc0f5c1c8be98dc33889a191f4c26bd',
'info_dict': {
'id': '6902724',
'ext': 'mp4',
'title': 'Comic-Con Cosplay Catastrophe',
'description': "Fans get creative this year at San Diego. Too creative. And yes, that's really Joss Whedon.",
'age_limit': 13,
'duration': 187,
_TESTS = [
{
'url': 'http://www.collegehumor.com/video/6902724/comic-con-cosplay-catastrophe',
'md5': 'dcc0f5c1c8be98dc33889a191f4c26bd',
'info_dict': {
'id': '6902724',
'ext': 'mp4',
'title': 'Comic-Con Cosplay Catastrophe',
'description': "Fans get creative this year at San Diego. Too creative. And yes, that's really Joss Whedon.",
'age_limit': 13,
'duration': 187,
},
}, {
'url': 'http://www.collegehumor.com/video/3505939/font-conference',
'md5': '72fa701d8ef38664a4dbb9e2ab721816',
'info_dict': {
'id': '3505939',
'ext': 'mp4',
'title': 'Font Conference',
'description': "This video wasn't long enough, so we made it double-spaced.",
'age_limit': 10,
'duration': 179,
},
}, {
# embedded youtube video
'url': 'http://www.collegehumor.com/embed/6950306',
'info_dict': {
'id': 'Z-bao9fg6Yc',
'ext': 'mp4',
'title': 'Young Americans Think President John F. Kennedy Died THIS MORNING IN A CAR ACCIDENT!!!',
'uploader': 'Mark Dice',
'uploader_id': 'MarkDice',
'description': 'md5:62c3dab9351fac7bb44b53b69511d87f',
'upload_date': '20140127',
},
'params': {
'skip_download': True,
},
'add_ie': ['Youtube'],
},
},
{
'url': 'http://www.collegehumor.com/video/3505939/font-conference',
'md5': '72fa701d8ef38664a4dbb9e2ab721816',
'info_dict': {
'id': '3505939',
'ext': 'mp4',
'title': 'Font Conference',
'description': "This video wasn't long enough, so we made it double-spaced.",
'age_limit': 10,
'duration': 179,
},
},
# embedded youtube video
{
'url': 'http://www.collegehumor.com/embed/6950306',
'info_dict': {
'id': 'Z-bao9fg6Yc',
'ext': 'mp4',
'title': 'Young Americans Think President John F. Kennedy Died THIS MORNING IN A CAR ACCIDENT!!!',
'uploader': 'Mark Dice',
'uploader_id': 'MarkDice',
'description': 'md5:62c3dab9351fac7bb44b53b69511d87f',
'upload_date': '20140127',
},
'params': {
'skip_download': True,
},
'add_ie': ['Youtube'],
},
]

def _real_extract(self, url):
Expand Down
4 changes: 2 additions & 2 deletions youtube_dl/extractor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def _search_regex(self, pattern, string, name, default=_NO_DEFAULT, fatal=True,
raise RegexNotFoundError('Unable to extract %s' % _name)
else:
self._downloader.report_warning('unable to extract %s; '
'please report this issue on http://yt-dl.org/bug' % _name)
'please report this issue on http://yt-dl.org/bug' % _name)
return None

def _html_search_regex(self, pattern, string, name, default=_NO_DEFAULT, fatal=True, flags=0, group=None):
Expand Down Expand Up @@ -612,7 +612,7 @@ def _media_rating_search(self, html):

def _twitter_search_player(self, html):
return self._html_search_meta('twitter:player', html,
'twitter card player')
'twitter card player')

def _sort_formats(self, formats):
if not formats:
Expand Down
4 changes: 2 additions & 2 deletions youtube_dl/extractor/dailymotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _real_extract(self, url):
embed_page = self._download_webpage(embed_url, video_id,
'Downloading embed page')
info = self._search_regex(r'var info = ({.*?}),$', embed_page,
'video info', flags=re.MULTILINE)
'video info', flags=re.MULTILINE)
info = json.loads(info)
if info.get('error') is not None:
msg = 'Couldn\'t get video, Dailymotion says: %s' % info['error']['title']
Expand Down Expand Up @@ -208,7 +208,7 @@ def _extract_entries(self, id):
if re.search(self._MORE_PAGES_INDICATOR, webpage) is None:
break
return [self.url_result('http://www.dailymotion.com/video/%s' % video_id, 'Dailymotion')
for video_id in orderedSet(video_ids)]
for video_id in orderedSet(video_ids)]

def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
Expand Down
6 changes: 3 additions & 3 deletions youtube_dl/extractor/defense.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class DefenseGouvFrIE(InfoExtractor):
IE_NAME = 'defense.gouv.fr'
_VALID_URL = (r'http://.*?\.defense\.gouv\.fr/layout/set/'
r'ligthboxvideo/base-de-medias/webtv/(.*)')
r'ligthboxvideo/base-de-medias/webtv/(.*)')

_TEST = {
'url': 'http://www.defense.gouv.fr/layout/set/ligthboxvideo/base-de-medias/webtv/attaque-chimique-syrienne-du-21-aout-2013-1',
Expand All @@ -28,9 +28,9 @@ def _real_extract(self, url):
webpage, 'ID')

json_url = ('http://static.videos.gouv.fr/brightcovehub/export/json/'
+ video_id)
+ video_id)
info = self._download_webpage(json_url, title,
'Downloading JSON config')
'Downloading JSON config')
video_url = json.loads(info)['renditions'][0]['url']

return {'id': video_id,
Expand Down
Loading

0 comments on commit 9e1a5b8

Please sign in to comment.