Skip to content

Commit

Permalink
PEP8: more applied
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouke Waleson committed Nov 23, 2014
1 parent 5f6a124 commit 8bcc875
Show file tree
Hide file tree
Showing 34 changed files with 124 additions and 133 deletions.
3 changes: 0 additions & 3 deletions devscripts/gh-pages/generate-download.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env python3
import hashlib
import shutil
import subprocess
import tempfile
import urllib.request
import json

Expand Down
2 changes: 1 addition & 1 deletion devscripts/transition_helper_exe/youtube-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def b(x):
signature = signature[2:]
if not b('\x00') in signature:
return False
signature = signature[signature.index(b('\x00'))+1:]
signature = signature[signature.index(b('\x00')) +1:]
if not signature.startswith(b('\x30\x31\x30\x0D\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20')):
return False
signature = signature[19:]
Expand Down
1 change: 0 additions & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
escape_rfc3986,
escape_url,
js_to_json,
get_filesystem_encoding,
intlist_to_bytes,
args_to_str,
)
Expand Down
4 changes: 0 additions & 4 deletions test/test_youtube_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
from youtube_dl.extractor import (
YoutubePlaylistIE,
YoutubeIE,
YoutubeChannelIE,
YoutubeShowIE,
YoutubeTopListIE,
YoutubeSearchURLIE,
)


Expand Down
1 change: 0 additions & 1 deletion youtube_dl/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
compat_str,
compat_urllib_error,
compat_urllib_request,
shlex_quote,
)
from .utils import (
escape_url,
Expand Down
18 changes: 9 additions & 9 deletions youtube_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def _real_main(argv=None):
if opts.headers is not None:
for h in opts.headers:
if h.find(':', 1) < 0:
parser.error('wrong header formatting, it should be key:value, not "%s"'%h)
parser.error('wrong header formatting, it should be key:value, not "%s"' % h)
key, value = h.split(':', 2)
if opts.verbose:
write_string('[debug] Adding header from command line option %s:%s\n'%(key, value))
write_string('[debug] Adding header from command line option %s:%s\n' % (key, value))
std_headers[key] = value

# Dump user agent
Expand Down Expand Up @@ -197,13 +197,13 @@ def _real_main(argv=None):
if opts.outtmpl is not None:
opts.outtmpl = opts.outtmpl.decode(preferredencoding())
outtmpl = ((opts.outtmpl is not None and opts.outtmpl)
or (opts.format == '-1' and opts.usetitle and '%(title)s-%(id)s-%(format)s.%(ext)s')
or (opts.format == '-1' and '%(id)s-%(format)s.%(ext)s')
or (opts.usetitle and opts.autonumber and '%(autonumber)s-%(title)s-%(id)s.%(ext)s')
or (opts.usetitle and '%(title)s-%(id)s.%(ext)s')
or (opts.useid and '%(id)s.%(ext)s')
or (opts.autonumber and '%(autonumber)s-%(id)s.%(ext)s')
or DEFAULT_OUTTMPL)
or (opts.format == '-1' and opts.usetitle and '%(title)s-%(id)s-%(format)s.%(ext)s')
or (opts.format == '-1' and '%(id)s-%(format)s.%(ext)s')
or (opts.usetitle and opts.autonumber and '%(autonumber)s-%(title)s-%(id)s.%(ext)s')
or (opts.usetitle and '%(title)s-%(id)s.%(ext)s')
or (opts.useid and '%(id)s.%(ext)s')
or (opts.autonumber and '%(autonumber)s-%(id)s.%(ext)s')
or DEFAULT_OUTTMPL)
if not os.path.splitext(outtmpl)[1] and opts.extractaudio:
parser.error('Cannot download a video and extract audio into the same'
' file! Use "{0}.%(ext)s" instead of "{0}" as the output'
Expand Down
30 changes: 15 additions & 15 deletions youtube_dl/aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def aes_ctr_decrypt(data, key, counter):
decrypted_data = []
for i in range(block_count):
counter_block = counter.next_value()
block = data[i*BLOCK_SIZE_BYTES: (i+1)*BLOCK_SIZE_BYTES]
block += [0]*(BLOCK_SIZE_BYTES - len(block))
block = data[i *BLOCK_SIZE_BYTES: (i +1) *BLOCK_SIZE_BYTES]
block += [0] *(BLOCK_SIZE_BYTES - len(block))

cipher_counter_block = aes_encrypt(counter_block, expanded_key)
decrypted_data += xor(block, cipher_counter_block)
Expand All @@ -49,8 +49,8 @@ def aes_cbc_decrypt(data, key, iv):
decrypted_data = []
previous_cipher_block = iv
for i in range(block_count):
block = data[i*BLOCK_SIZE_BYTES: (i+1)*BLOCK_SIZE_BYTES]
block += [0]*(BLOCK_SIZE_BYTES - len(block))
block = data[i *BLOCK_SIZE_BYTES: (i +1) *BLOCK_SIZE_BYTES]
block += [0] *(BLOCK_SIZE_BYTES - len(block))

decrypted_block = aes_decrypt(block, expanded_key)
decrypted_data += xor(decrypted_block, previous_cipher_block)
Expand All @@ -76,20 +76,20 @@ def key_expansion(data):
temp = data[-4:]
temp = key_schedule_core(temp, rcon_iteration)
rcon_iteration += 1
data += xor(temp, data[-key_size_bytes: 4-key_size_bytes])
data += xor(temp, data[-key_size_bytes: 4 -key_size_bytes])

for _ in range(3):
temp = data[-4:]
data += xor(temp, data[-key_size_bytes: 4-key_size_bytes])
data += xor(temp, data[-key_size_bytes: 4 -key_size_bytes])

if key_size_bytes == 32:
temp = data[-4:]
temp = sub_bytes(temp)
data += xor(temp, data[-key_size_bytes: 4-key_size_bytes])
data += xor(temp, data[-key_size_bytes: 4 -key_size_bytes])

for _ in range(3 if key_size_bytes == 32 else 2 if key_size_bytes == 24 else 0):
temp = data[-4:]
data += xor(temp, data[-key_size_bytes: 4-key_size_bytes])
data += xor(temp, data[-key_size_bytes: 4 -key_size_bytes])
data = data[:expanded_key_size_bytes]

return data
Expand All @@ -106,12 +106,12 @@ def aes_encrypt(data, expanded_key):
rounds = len(expanded_key) // BLOCK_SIZE_BYTES - 1

data = xor(data, expanded_key[:BLOCK_SIZE_BYTES])
for i in range(1, rounds+1):
for i in range(1, rounds +1):
data = sub_bytes(data)
data = shift_rows(data)
if i != rounds:
data = mix_columns(data)
data = xor(data, expanded_key[i*BLOCK_SIZE_BYTES: (i+1)*BLOCK_SIZE_BYTES])
data = xor(data, expanded_key[i *BLOCK_SIZE_BYTES: (i +1) *BLOCK_SIZE_BYTES])

return data

Expand All @@ -127,7 +127,7 @@ def aes_decrypt(data, expanded_key):
rounds = len(expanded_key) // BLOCK_SIZE_BYTES - 1

for i in range(rounds, 0, -1):
data = xor(data, expanded_key[i*BLOCK_SIZE_BYTES: (i+1)*BLOCK_SIZE_BYTES])
data = xor(data, expanded_key[i *BLOCK_SIZE_BYTES: (i +1) *BLOCK_SIZE_BYTES])
if i != rounds:
data = mix_columns_inv(data)
data = shift_rows_inv(data)
Expand Down Expand Up @@ -155,14 +155,14 @@ def aes_decrypt_text(data, password, key_size_bytes):
data = bytes_to_intlist(base64.b64decode(data))
password = bytes_to_intlist(password.encode('utf-8'))

key = password[:key_size_bytes] + [0]*(key_size_bytes - len(password))
key = password[:key_size_bytes] + [0] *(key_size_bytes - len(password))
key = aes_encrypt(key[:BLOCK_SIZE_BYTES], key_expansion(key)) * (key_size_bytes // BLOCK_SIZE_BYTES)

nonce = data[:NONCE_LENGTH_BYTES]
cipher = data[NONCE_LENGTH_BYTES:]

class Counter:
__value = nonce + [0]*(BLOCK_SIZE_BYTES - NONCE_LENGTH_BYTES)
__value = nonce + [0] *(BLOCK_SIZE_BYTES - NONCE_LENGTH_BYTES)

def next_value(self):
temp = self.__value
Expand Down Expand Up @@ -293,7 +293,7 @@ def mix_column(data, matrix):
def mix_columns(data, matrix=MIX_COLUMN_MATRIX):
data_mixed = []
for i in range(4):
column = data[i*4: (i+1)*4]
column = data[i *4: (i +1) *4]
data_mixed += mix_column(column, matrix)
return data_mixed

Expand All @@ -320,7 +320,7 @@ def shift_rows_inv(data):

def inc(data):
data = data[:] # copy
for i in range(len(data)-1, -1, -1):
for i in range(len(data) -1, -1, -1):
if data[i] == 255:
data[i] = 0
else:
Expand Down
4 changes: 2 additions & 2 deletions youtube_dl/downloader/f4m.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def read_box_info(self):
if size == 1:
real_size = self.read_unsigned_long_long()
header_end = 16
return real_size, box_type, self.read(real_size-header_end)
return real_size, box_type, self.read(real_size -header_end)

def read_asrt(self):
# version
Expand Down Expand Up @@ -180,7 +180,7 @@ def build_fragments_list(boot_info):
n_frags = segment_run_entry[1]
fragment_run_entry_table = boot_info['fragments'][0]['fragments']
first_frag_number = fragment_run_entry_table[0]['first']
for (i, frag_number) in zip(range(1, n_frags+1), itertools.count(first_frag_number)):
for (i, frag_number) in zip(range(1, n_frags +1), itertools.count(first_frag_number)):
res.append((1, frag_number))
return res

Expand Down
10 changes: 5 additions & 5 deletions youtube_dl/downloader/rtmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def run_rtmpdump(args):
continue
mobj = re.search(r'([0-9]+\.[0-9]{3}) kB / [0-9]+\.[0-9]{2} sec \(([0-9]{1,2}\.[0-9])%\)', line)
if mobj:
downloaded_data_len = int(float(mobj.group(1))*1024)
downloaded_data_len = int(float(mobj.group(1)) *1024)
percent = float(mobj.group(2))
if not resume_percent:
resume_percent = percent
resume_downloaded_data_len = downloaded_data_len
eta = self.calc_eta(start, time.time(), 100-resume_percent, percent-resume_percent)
speed = self.calc_speed(start, time.time(), downloaded_data_len-resume_downloaded_data_len)
eta = self.calc_eta(start, time.time(), 100 -resume_percent, percent -resume_percent)
speed = self.calc_speed(start, time.time(), downloaded_data_len -resume_downloaded_data_len)
data_len = None
if percent > 0:
data_len = int(downloaded_data_len * 100 / percent)
Expand All @@ -72,7 +72,7 @@ def run_rtmpdump(args):
# no percent for live streams
mobj = re.search(r'([0-9]+\.[0-9]{3}) kB / [0-9]+\.[0-9]{2} sec', line)
if mobj:
downloaded_data_len = int(float(mobj.group(1))*1024)
downloaded_data_len = int(float(mobj.group(1)) *1024)
time_now = time.time()
speed = self.calc_speed(start, time_now, downloaded_data_len)
self.report_progress_live_stream(downloaded_data_len, speed, time_now - start)
Expand All @@ -88,7 +88,7 @@ def run_rtmpdump(args):
if not cursor_in_new_line:
self.to_screen('')
cursor_in_new_line = True
self.to_screen('[rtmpdump] '+line)
self.to_screen('[rtmpdump] ' +line)
proc.wait()
if not cursor_in_new_line:
self.to_screen('')
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,4 @@ def gen_extractors():

def get_info_extractor(ie_name):
"""Returns the info extractor class with the given ie_name"""
return globals()[ie_name+'IE']
return globals()[ie_name + 'IE']
2 changes: 1 addition & 1 deletion youtube_dl/extractor/bbccouk.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _real_extract(self, url):
duration = int(item.get('duration'))

media_selection = self._download_xml(
'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/pc/vpid/%s' % programme_id,
'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/pc/vpid/%s' % programme_id,
programme_id, 'Downloading media selection XML')

for media in self._extract_medias(media_selection):
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/cinemassacre.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _real_extract(self, url):
if videolist_url:
videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
formats = []
baseurl = vidurl[:vidurl.rfind('/')+1]
baseurl = vidurl[:vidurl.rfind('/') +1]
for video in videolist.findall('.//video'):
src = video.get('src')
if not src:
Expand Down
20 changes: 10 additions & 10 deletions youtube_dl/extractor/crunchyroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ def _real_extract(self, url):
formats = []
for fmt in re.findall(r'\?p([0-9]{3,4})=1', webpage):
stream_quality, stream_format = self._FORMAT_IDS[fmt]
video_format = fmt+'p'
video_format = fmt +'p'
streamdata_req = compat_urllib_request.Request('http://www.crunchyroll.com/xml/')
# urlencode doesn't work!
streamdata_req.data = 'req=RpcApiVideoEncode%5FGetStreamInfo&video%5Fencode%5Fquality='+stream_quality+'&media%5Fid='+stream_id+'&video%5Fformat='+stream_format
streamdata_req.data = 'req=RpcApiVideoEncode%5FGetStreamInfo&video%5Fencode%5Fquality=' +stream_quality +'&media%5Fid=' +stream_id +'&video%5Fformat=' +stream_format
streamdata_req.add_header('Content-Type', 'application/x-www-form-urlencoded')
streamdata_req.add_header('Content-Length', str(len(streamdata_req.data)))
streamdata = self._download_xml(
Expand All @@ -248,8 +248,8 @@ def _real_extract(self, url):
subtitles = {}
sub_format = self._downloader.params.get('subtitlesformat', 'srt')
for sub_id, sub_name in re.findall(r'\?ssid=([0-9]+)" title="([^"]+)', webpage):
sub_page = self._download_webpage('http://www.crunchyroll.com/xml/?req=RpcApiSubtitle_GetXml&subtitle_script_id='+sub_id,\
video_id, note='Downloading subtitles for '+sub_name)
sub_page = self._download_webpage('http://www.crunchyroll.com/xml/?req=RpcApiSubtitle_GetXml&subtitle_script_id=' +sub_id,\
video_id, note='Downloading subtitles for ' +sub_name)
id = self._search_regex(r'id=\'([0-9]+)', sub_page, 'subtitle_id', fatal=False)
iv = self._search_regex(r'<iv>([^<]+)', sub_page, 'subtitle_iv', fatal=False)
data = self._search_regex(r'<data>([^<]+)', sub_page, 'subtitle_data', fatal=False)
Expand All @@ -274,14 +274,14 @@ def _real_extract(self, url):
return

return {
'id': video_id,
'title': video_title,
'id': video_id,
'title': video_title,
'description': video_description,
'thumbnail': video_thumbnail,
'uploader': video_uploader,
'thumbnail': video_thumbnail,
'uploader': video_uploader,
'upload_date': video_upload_date,
'subtitles': subtitles,
'formats': formats,
'subtitles': subtitles,
'formats': formats,
}


Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/dotsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _real_extract(self, url):
video_id = mobj.group('id')
info_url = "https://dotsub.com/api/media/%s/metadata" % video_id
info = self._download_json(info_url, video_id)
date = time.gmtime(info['dateCreated']/1000) # The timestamp is in miliseconds
date = time.gmtime(info['dateCreated'] /1000) # The timestamp is in miliseconds

return {
'id': video_id,
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def _playlist_from_matches(matches, getter, ie=None):
# Look for embedded blip.tv player
mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
if mobj:
return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
return self.url_result('http://blip.tv/a/a-' +mobj.group(1), 'BlipTV')
mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9_]+)', webpage)
if mobj:
return self.url_result(mobj.group(1), 'BlipTV')
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/iprima.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _real_extract(self, url):

player_url = (
'http://embed.livebox.cz/iprimaplay/player-embed-v2.js?__tok%s__=%s' %
(floor(random()*1073741824), floor(random()*1073741824))
(floor(random() *1073741824), floor(random() *1073741824))
)

req = compat_urllib_request.Request(player_url)
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/lifenews.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def make_entry(video_id, media, video_number=None):
if len(videos) == 1:
return make_entry(video_id, videos[0])
else:
return [make_entry(video_id, media, video_number+1) for video_number, media in enumerate(videos)]
return [make_entry(video_id, media, video_number +1) for video_number, media in enumerate(videos)]
6 changes: 2 additions & 4 deletions youtube_dl/extractor/liveleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class LiveLeakIE(InfoExtractor):
'uploader': 'ljfriel2',
'title': 'Most unlucky car accident'
}
},
{
}, {
'url': 'http://www.liveleak.com/view?i=f93_1390833151',
'md5': 'd3f1367d14cc3c15bf24fbfbe04b9abf',
'info_dict': {
Expand All @@ -30,8 +29,7 @@ class LiveLeakIE(InfoExtractor):
'uploader': 'ARD_Stinkt',
'title': 'German Television does first Edward Snowden Interview (ENGLISH)',
}
},
{
}, {
'url': 'http://www.liveleak.com/view?i=4f7_1392687779',
'md5': '42c6d97d54f1db107958760788c5f48f',
'info_dict': {
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/metacafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MetacafeIE(InfoExtractor):
# Youtube video
{
'add_ie': ['Youtube'],
'url': 'http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/',
'url': 'http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/',
'info_dict': {
'id': '_aUehQsCQtM',
'ext': 'mp4',
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/mtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _real_extract(self, url):
m_vevo = re.search(r'isVevoVideo = true;.*?vevoVideoId = "(.*?)";',
webpage, re.DOTALL)
if m_vevo:
vevo_id = m_vevo.group(1);
vevo_id = m_vevo.group(1)
self.to_screen('Vevo video detected: %s' % vevo_id)
return self.url_result('vevo:%s' % vevo_id, ie='Vevo')

Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/sohu.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _fetch_data(vid_id, mytv=False):
(allot, prot, clipsURL[i], su[i]))
part_str = self._download_webpage(
part_url, video_id,
note=u'Downloading part %d of %d' % (i+1, part_count))
note=u'Downloading part %d of %d' % (i +1, part_count))

part_info = part_str.split('|')
video_url = '%s%s?key=%s' % (part_info[0], su[i], part_info[3])
Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/extractor/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _real_extract(self, url):
# extract uploader (which is in the url)
uploader = mobj.group('uploader')
# extract simple title (uploader + slug of song title)
slug_title = mobj.group('title')
slug_title = mobj.group('title')
token = mobj.group('token')
full_title = resolve_title = '%s/%s' % (uploader, slug_title)
if token:
Expand Down
Loading

0 comments on commit 8bcc875

Please sign in to comment.