From f332ec77e05d053aced4295ec757515bb77a1f07 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Fri, 15 Jan 2016 10:23:31 +0100 Subject: [PATCH] smooth-dl.py: fix some pylint issues C: 59, 0: Unnecessary parens after 'assert' keyword (superfluous-parens) W: 67, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation) C:232, 0: Exactly one space required after comma chunk_file = os.path.join(dest_dir, chunks_quality, chunk_name) ^ (bad-whitespace) W:341, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) W:342, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation) W:344, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) W:345, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation) W:347, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation) W:350, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) W:351, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) W:353, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) W:355, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) W:360, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) W:365, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) W:370, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation) C:396, 0: Exactly one space required after comma parser.add_option("-v", "--video-stream", metavar="", ^ (bad-whitespace) C: 43, 0: Invalid constant name "__description" (invalid-name) C: 44, 0: Invalid constant name "__version" (invalid-name) C: 45, 0: Invalid constant name "__author_info" (invalid-name) W:100,32: Unused variable 'e' (unused-variable) W:112,17: Redefining name 'url' from outer scope (line 421) (redefined-outer-name) W:130, 4: Redefining name 'manifest' from outer scope (line 422) (redefined-outer-name) C:115, 7: Comparison to False should be 'not expr' or 'expr is False' (singleton-comparison) W:150,24: Redefining name 'manifest' from outer scope (line 422) (redefined-outer-name) W:156, 8: Redefining name 'url' from outer scope (line 421) (redefined-outer-name) W:156, 8: Unused variable 'url' (unused-variable) W:194, 4: Redefining name 'url' from outer scope (line 421) (redefined-outer-name) W:205, 4: Redefining name 'url' from outer scope (line 421) (redefined-outer-name) W:211,30: Redefining name 'manifest' from outer scope (line 422) (redefined-outer-name) C:213, 7: Comparison to False should be 'not expr' or 'expr is False' (singleton-comparison) C:221, 7: Comparison to False should be 'not expr' or 'expr is False' (singleton-comparison) C:234,11: Comparison to False should be 'not expr' or 'expr is False' (singleton-comparison) W:248,19: Redefining name 'manifest' from outer scope (line 422) (redefined-outer-name) W:306,22: Redefining name 'manifest' from outer scope (line 422) (redefined-outer-name) W:328,22: Redefining name 'manifest' from outer scope (line 422) (redefined-outer-name) W:335,20: Redefining name 'url' from outer scope (line 421) (redefined-outer-name) W:335,25: Redefining name 'manifest' from outer scope (line 422) (redefined-outer-name) W:376, 4: Redefining name 'parser' from outer scope (line 414) (redefined-outer-name) C:414, 4: Invalid constant name "parser" (invalid-name) C:415, 5: Invalid constant name "options" (invalid-name) C:415,14: Invalid constant name "args" (invalid-name) C:421, 4: Invalid constant name "url" (invalid-name) C:422, 4: Invalid constant name "manifest" (invalid-name) C:422,14: Invalid constant name "url" (invalid-name) --- smooth-dl.py | 82 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/smooth-dl.py b/smooth-dl.py index aa57c6e..41dfc4c 100755 --- a/smooth-dl.py +++ b/smooth-dl.py @@ -40,9 +40,9 @@ import tempfile from optparse import OptionParser from urlparse import urlparse, urlunparse -__description = "Download videos served using Smooth Streaming technology" -__version = "0.x" -__author_info = "Written by Antonio Ospite http://ao2.it" +__description__ = "Download videos served using Smooth Streaming technology" +__version__ = "0.x" +__author_info__ = "Written by Antonio Ospite http://ao2.it" def get_chunk_data(data): @@ -56,7 +56,7 @@ def get_chunk_data(data): # print len(data[data_start:]), \ # len(data[data_start:data_start + data_size]), data_size - assert(len(data[data_start:]) == data_size) + assert len(data[data_start:]) == data_size return data[data_start:data_start + data_size] @@ -64,7 +64,7 @@ def get_chunk_data(data): def hexstring_to_bytes(hex_string): res = "" for i in range(0, len(hex_string), 2): - res += chr(int(hex_string[i:i + 2], 16)) + res += chr(int(hex_string[i:i + 2], 16)) return res @@ -97,7 +97,7 @@ def download_file(src_url, dest_file, mode): try: response = urllib2.urlopen(src_url) data = response.read() - except urllib2.HTTPError as e: + except urllib2.HTTPError: sys.stderr.write("Error while dowloading URL: %s" % src_url) raise @@ -112,7 +112,7 @@ def download_file(src_url, dest_file, mode): def get_manifest(url, dest_dir=tempfile.gettempdir()): """Returns the manifest and the new URL if this is changed""" - if os.path.exists(dest_dir) == False: + if not os.path.exists(dest_dir): os.mkdir(dest_dir, 0755) # Remove the querystring if present @@ -153,7 +153,6 @@ def print_manifest_info(manifest): for i, s in enumerate(streams): stream_type = s.attrib["Type"] - url = s.attrib["Url"] print "Stream: %s Type: %s" % (i, stream_type) @@ -210,7 +209,7 @@ def get_chunk_name_string(stream, chunk): def download_chunks(base_url, manifest, stream_index, quality_level, dest_dir): - if os.path.exists(dest_dir) == False: + if not os.path.exists(dest_dir): os.mkdir(dest_dir, 0755) stream = manifest.findall('.//StreamIndex')[stream_index] @@ -218,7 +217,7 @@ def download_chunks(base_url, manifest, stream_index, quality_level, dest_dir): chunks_quality = get_chunk_quality_string(stream, quality_level) chunks_dest_dir = os.path.join(dest_dir, chunks_quality) - if os.path.exists(chunks_dest_dir) == False: + if not os.path.exists(chunks_dest_dir): os.mkdir(chunks_dest_dir, 0755) chunks = stream.findall("c") @@ -229,9 +228,9 @@ def download_chunks(base_url, manifest, stream_index, quality_level, dest_dir): for i, c in enumerate(chunks): chunk_name = get_chunk_name_string(stream, c) - chunk_file = os.path.join(dest_dir, chunks_quality, chunk_name) + chunk_file = os.path.join(dest_dir, chunks_quality, chunk_name) - if os.path.exists(chunk_file) == False: + if not os.path.exists(chunk_file): chunk_url = base_url + '/' + chunks_quality + '/' + chunk_name data = download_file(chunk_url, chunk_file, "wb") else: @@ -338,43 +337,43 @@ def smooth_download(url, manifest, dest_dir=tempfile.gettempdir(), chunks_dir=None, download=True, out_video_file='_video.vc1', out_audio_file='_audio.raw'): - if chunks_dir is None: - chunks_dir = dest_dir + if chunks_dir is None: + chunks_dir = dest_dir - if download: - download_chunks(url, manifest, video_stream_index, - video_quality_level, chunks_dir) - download_chunks(url, manifest, audio_stream_index, - audio_quality_level, chunks_dir) + if download: + download_chunks(url, manifest, video_stream_index, + video_quality_level, chunks_dir) + download_chunks(url, manifest, audio_stream_index, + audio_quality_level, chunks_dir) - dest_video = os.path.join(dest_dir, out_video_file) - dest_audio = os.path.join(dest_dir, out_audio_file) + dest_video = os.path.join(dest_dir, out_video_file) + dest_audio = os.path.join(dest_dir, out_audio_file) - rebuild_stream(manifest, video_stream_index, video_quality_level, - chunks_dir, dest_video) - rebuild_stream(manifest, audio_stream_index, audio_quality_level, - chunks_dir, dest_audio, dest_audio + '.wav') + rebuild_stream(manifest, video_stream_index, video_quality_level, + chunks_dir, dest_video) + rebuild_stream(manifest, audio_stream_index, audio_quality_level, + chunks_dir, dest_audio, dest_audio + '.wav') - # duration = get_clip_duration(manifest) + # duration = get_clip_duration(manifest) - delay = calc_tracks_delay(manifest, video_stream_index, - audio_stream_index) + delay = calc_tracks_delay(manifest, video_stream_index, + audio_stream_index) - # optionally encode audio to vorbis: - # ffmpeg -i _audio.raw.wav -acodec libvorbis -aq 60 audio.ogg - mux_command = ("ffmpeg -i %s \\\n" + - " -itsoffset %f -async 1 -i %s \\\n" + - " -vcodec copy -acodec copy ffout.mkv") % \ - (dest_video, delay, dest_audio + '.wav') + # optionally encode audio to vorbis: + # ffmpeg -i _audio.raw.wav -acodec libvorbis -aq 60 audio.ogg + mux_command = ("ffmpeg -i %s \\\n" + + " -itsoffset %f -async 1 -i %s \\\n" + + " -vcodec copy -acodec copy ffout.mkv") % \ + (dest_video, delay, dest_audio + '.wav') - print mux_command + print mux_command def options_parser(): - version = "%%prog %s" % __version + version = "%%prog %s" % __version__ usage = "usage: %prog [options] " parser = OptionParser(usage=usage, version=version, - description=__description, epilog=__author_info) + description=__description__, epilog=__author_info__) parser.add_option("-i", "--info", action="store_true", dest="info_only", default=False, help="print Manifest info and exit") @@ -393,7 +392,7 @@ def options_parser(): parser.add_option("-c", "--chunks-dir", metavar="", dest="chunks_dir", default=None, help="directory containing chunks, if different from destination dir") - parser.add_option("-v", "--video-stream", metavar="", + parser.add_option("-v", "--video-stream", metavar="", type="int", dest="video_stream_index", default=0, help="index of the video stream") parser.add_option("-a", "--audio-stream", metavar="", @@ -409,8 +408,7 @@ def options_parser(): return parser -if __name__ == "__main__": - +def main(): parser = options_parser() (options, args) = parser.parse_args() @@ -440,3 +438,7 @@ if __name__ == "__main__": options.video_stream_index, options.audio_stream_index, options.video_quality_level, options.audio_quality_level, options.chunks_dir, options.download) + + +if __name__ == "__main__": + main() -- 2.1.4