nficano commited on
Commit
4c28904
·
2 Parent(s): 9e8212f 83daefe

Merge pull request #1 from lorenzogil/master

Browse files

Evaluate the status code and do nothing upon failure

Files changed (1) hide show
  1. youtube/youtube.py +12 -3
youtube/youtube.py CHANGED
@@ -225,10 +225,19 @@ class YouTube(object):
225
  'video_id': self.video_id
226
  })
227
 
 
 
 
228
  response = urlopen(YT_BASE_URL + '?' + querystring)
229
- #TODO: evaulate the status code.
230
  if response:
231
  content = response.read()
 
 
 
 
 
 
232
  #Use my cool traversing method to extract the specific
233
  #attribute from the response body.
234
  path = ('url_encoded_fmt_stream_map', 'itag')
@@ -295,10 +304,10 @@ def safe_filename(text, max_length=200):
295
  #Tidy up ugly formatted filenames.
296
  text = text.replace('_', ' ')
297
  text = text.replace(':', ' -')
298
-
299
  #NTFS forbids filenames containing characters in range 0-31 (0x00-0x1F)
300
  ntfs = [chr(i) for i in range(0, 31)]
301
-
302
  #Removing these SHOULD make most filename safe for a wide range
303
  #of operating systems.
304
  paranoid = ['\"', '\#', '\$', '\%', '\'', '\*', '\,', '\.', '\/', '\:',
 
225
  'video_id': self.video_id
226
  })
227
 
228
+ self.title = None
229
+ self.videos = []
230
+
231
  response = urlopen(YT_BASE_URL + '?' + querystring)
232
+
233
  if response:
234
  content = response.read()
235
+ data = parse_qs(content)
236
+ if data.get('status', [''])[0] == 'failure':
237
+ print('Error downloading video: %s' %
238
+ data.get('reason', ['Unknown reason'])[0])
239
+ return
240
+
241
  #Use my cool traversing method to extract the specific
242
  #attribute from the response body.
243
  path = ('url_encoded_fmt_stream_map', 'itag')
 
304
  #Tidy up ugly formatted filenames.
305
  text = text.replace('_', ' ')
306
  text = text.replace(':', ' -')
307
+
308
  #NTFS forbids filenames containing characters in range 0-31 (0x00-0x1F)
309
  ntfs = [chr(i) for i in range(0, 31)]
310
+
311
  #Removing these SHOULD make most filename safe for a wide range
312
  #of operating systems.
313
  paranoid = ['\"', '\#', '\$', '\%', '\'', '\*', '\,', '\.', '\/', '\:',