Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions youtube/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,19 @@ def _get_video_info(self):
'video_id': self.video_id
})

self.title = None
self.videos = []

response = urlopen(YT_BASE_URL + '?' + querystring)
#TODO: evaulate the status code.

if response:
content = response.read()
data = parse_qs(content)
if data.get('status', [''])[0] == 'failure':
print('Error downloading video: %s' %
data.get('reason', ['Unknown reason'])[0])
return

#Use my cool traversing method to extract the specific
#attribute from the response body.
path = ('url_encoded_fmt_stream_map', 'itag')
Expand Down Expand Up @@ -295,10 +304,10 @@ def safe_filename(text, max_length=200):
#Tidy up ugly formatted filenames.
text = text.replace('_', ' ')
text = text.replace(':', ' -')

#NTFS forbids filenames containing characters in range 0-31 (0x00-0x1F)
ntfs = [chr(i) for i in range(0, 31)]

#Removing these SHOULD make most filename safe for a wide range
#of operating systems.
paranoid = ['\"', '\#', '\$', '\%', '\'', '\*', '\,', '\.', '\/', '\:',
Expand Down