rg3 / youtube-dl (http://bitbucket.org/rg3/youtube-dl/wiki/)

youtube-dl is a small command-line program for downloading videos from YouTube.com.

Clone this repository (size: 218.9 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/rg3/youtube-dl/
commit 93: 0313da25b23b
parent 92: 534b53584d3a
branch: default
Replase self._downloader.to_stderr() with self._downloader.trouble()
rg3
10 months ago

Changed (Δ48 bytes):

raw changeset »

youtube-dl (24 lines added, 24 lines removed)

Up to file-list youtube-dl:

@@ -508,7 +508,7 @@ class YoutubeIE(InfoExtractor):
508
508
				else:
509
509
					raise netrc.NetrcParseError('No authenticators for %s' % self._NETRC_MACHINE)
510
510
			except (IOError, netrc.NetrcParseError), err:
511
				self._downloader.to_stderr(u'WARNING: parsing .netrc: %s' % str(err))
511
				self._downloader.trouble(u'WARNING: parsing .netrc: %s' % str(err))
512
512
				return
513
513
514
514
		# Set language
@@ -517,7 +517,7 @@ class YoutubeIE(InfoExtractor):
517
517
			self.report_lang()
518
518
			urllib2.urlopen(request).read()
519
519
		except (urllib2.URLError, httplib.HTTPException, socket.error), err:
520
			self._downloader.to_stderr(u'WARNING: unable to set language: %s' % str(err))
520
			self._downloader.trouble(u'WARNING: unable to set language: %s' % str(err))
521
521
			return
522
522
523
523
		# No authentication to be performed
@@ -537,10 +537,10 @@ class YoutubeIE(InfoExtractor):
537
537
			self.report_login()
538
538
			login_results = urllib2.urlopen(request).read()
539
539
			if re.search(r'(?i)<form[^>]* name="loginForm"', login_results) is not None:
540
				self._downloader.to_stderr(u'WARNING: unable to log in: bad username or password')
540
				self._downloader.trouble(u'WARNING: unable to log in: bad username or password')
541
541
				return
542
542
		except (urllib2.URLError, httplib.HTTPException, socket.error), err:
543
			self._downloader.to_stderr(u'WARNING: unable to log in: %s' % str(err))
543
			self._downloader.trouble(u'WARNING: unable to log in: %s' % str(err))
544
544
			return
545
545
	
546
546
		# Confirm age
@@ -553,14 +553,14 @@ class YoutubeIE(InfoExtractor):
553
553
			self.report_age_confirmation()
554
554
			age_results = urllib2.urlopen(request).read()
555
555
		except (urllib2.URLError, httplib.HTTPException, socket.error), err:
556
			self._downloader.to_stderr(u'ERROR: unable to confirm age: %s' % str(err))
556
			self._downloader.trouble(u'ERROR: unable to confirm age: %s' % str(err))
557
557
			return
558
558
559
559
	def _real_extract(self, url):
560
560
		# Extract video id from URL
561
561
		mobj = re.match(self._VALID_URL, url)
562
562
		if mobj is None:
563
			self._downloader.to_stderr(u'ERROR: invalid URL: %s' % url)
563
			self._downloader.trouble(u'ERROR: invalid URL: %s' % url)
564
564
			return [None]
565
565
		video_id = mobj.group(2)
566
566
@@ -586,14 +586,14 @@ class YoutubeIE(InfoExtractor):
586
586
			self.report_webpage_download(video_id)
587
587
			video_webpage = urllib2.urlopen(request).read()
588
588
		except (urllib2.URLError, httplib.HTTPException, socket.error), err:
589
			self._downloader.to_stderr(u'ERROR: unable to download video webpage: %s' % str(err))
589
			self._downloader.trouble(u'ERROR: unable to download video webpage: %s' % str(err))
590
590
			return [None]
591
591
		self.report_information_extraction(video_id)
592
592
		
593
593
		# "t" param
594
594
		mobj = re.search(r', "t": "([^"]+)"', video_webpage)
595
595
		if mobj is None:
596
			self._downloader.to_stderr(u'ERROR: unable to extract "t" parameter')
596
			self._downloader.trouble(u'ERROR: unable to extract "t" parameter')
597
597
			return [None]
598
598
		video_real_url = 'http://www.youtube.com/get_video?video_id=%s&t=%s&el=detailpage&ps=' % (video_id, mobj.group(1))
599
599
		if format_param is not None:
@@ -603,14 +603,14 @@ class YoutubeIE(InfoExtractor):
603
603
		# uploader
604
604
		mobj = re.search(r"var watchUsername = '([^']+)';", video_webpage)
605
605
		if mobj is None:
606
			self._downloader.to_stderr(u'ERROR: unable to extract uploader nickname')
606
			self._downloader.trouble(u'ERROR: unable to extract uploader nickname')
607
607
			return [None]
608
608
		video_uploader = mobj.group(1)
609
609
610
610
		# title
611
611
		mobj = re.search(r'(?im)<title>YouTube - ([^<]*)</title>', video_webpage)
612
612
		if mobj is None:
613
			self._downloader.to_stderr(u'ERROR: unable to extract video title')
613
			self._downloader.trouble(u'ERROR: unable to extract video title')
614
614
			return [None]
615
615
		video_title = mobj.group(1).decode('utf-8')
616
616
		video_title = re.sub(ur'(?u)&(.+?);', self.htmlentity_transform, video_title)
@@ -668,7 +668,7 @@ class MetacafeIE(InfoExtractor):
668
668
			self.report_disclaimer()
669
669
			disclaimer = urllib2.urlopen(request).read()
670
670
		except (urllib2.URLError, httplib.HTTPException, socket.error), err:
671
			self._downloader.to_stderr(u'ERROR: unable to retrieve disclaimer: %s' % str(err))
671
			self._downloader.trouble(u'ERROR: unable to retrieve disclaimer: %s' % str(err))
672
672
			return
673
673
674
674
		# Confirm age
@@ -681,14 +681,14 @@ class MetacafeIE(InfoExtractor):
681
681
			self.report_age_confirmation()
682
682
			disclaimer = urllib2.urlopen(request).read()
683
683
		except (urllib2.URLError, httplib.HTTPException, socket.error), err:
684
			self._downloader.to_stderr(u'ERROR: unable to confirm age: %s' % str(err))
684
			self._downloader.trouble(u'ERROR: unable to confirm age: %s' % str(err))
685
685
			return
686
686
	
687
687
	def _real_extract(self, url):
688
688
		# Extract id and simplified title from URL
689
689
		mobj = re.match(self._VALID_URL, url)
690
690
		if mobj is None:
691
			self._downloader.to_stderr(u'ERROR: invalid URL: %s' % url)
691
			self._downloader.trouble(u'ERROR: invalid URL: %s' % url)
692
692
			return [None]
693
693
694
694
		video_id = mobj.group(1)
@@ -707,20 +707,20 @@ class MetacafeIE(InfoExtractor):
707
707
			self.report_download_webpage(video_id)
708
708
			webpage = urllib2.urlopen(request).read()
709
709
		except (urllib2.URLError, httplib.HTTPException, socket.error), err:
710
			self._downloader.to_stderr(u'ERROR: unable retrieve video webpage: %s' % str(err))
710
			self._downloader.trouble(u'ERROR: unable retrieve video webpage: %s' % str(err))
711
711
			return [None]
712
712
713
713
		# Extract URL, uploader and title from webpage
714
714
		self.report_extraction(video_id)
715
715
		mobj = re.search(r'(?m)"mediaURL":"(http.*?\.flv)"', webpage)
716
716
		if mobj is None:
717
			self._downloader.to_stderr(u'ERROR: unable to extract media URL')
717
			self._downloader.trouble(u'ERROR: unable to extract media URL')
718
718
			return [None]
719
719
		mediaURL = mobj.group(1).replace('\\', '')
720
720
721
721
		mobj = re.search(r'(?m)"gdaKey":"(.*?)"', webpage)
722
722
		if mobj is None:
723
			self._downloader.to_stderr(u'ERROR: unable to extract gdaKey')
723
			self._downloader.trouble(u'ERROR: unable to extract gdaKey')
724
724
			return [None]
725
725
		gdaKey = mobj.group(1)
726
726
@@ -728,13 +728,13 @@ class MetacafeIE(InfoExtractor):
728
728
729
729
		mobj = re.search(r'(?im)<title>(.*) - Video</title>', webpage)
730
730
		if mobj is None:
731
			self._downloader.to_stderr(u'ERROR: unable to extract title')
731
			self._downloader.trouble(u'ERROR: unable to extract title')
732
732
			return [None]
733
733
		video_title = mobj.group(1).decode('utf-8')
734
734
735
735
		mobj = re.search(r'(?m)<li id="ChnlUsr">.*?Submitter:<br />(.*?)</li>', webpage)
736
736
		if mobj is None:
737
			self._downloader.to_stderr(u'ERROR: unable to extract uploader nickname')
737
			self._downloader.trouble(u'ERROR: unable to extract uploader nickname')
738
738
			return [None]
739
739
		video_uploader = re.sub(r'<.*?>', '', mobj.group(1))
740
740
@@ -776,7 +776,7 @@ class YoutubeSearchIE(InfoExtractor):
776
776
	def _real_extract(self, query):
777
777
		mobj = re.match(self._VALID_QUERY, query)
778
778
		if mobj is None:
779
			self._downloader.to_stderr(u'ERROR: invalid search query "%s"' % query)
779
			self._downloader.trouble(u'ERROR: invalid search query "%s"' % query)
780
780
			return [None]
781
781
782
782
		prefix, query = query.split(':')
@@ -789,10 +789,10 @@ class YoutubeSearchIE(InfoExtractor):
789
789
			try:
790
790
				n = int(prefix)
791
791
				if n <= 0:
792
					self._downloader.to_stderr(u'ERROR: invalid download number %s for query "%s"' % (n, query))
792
					self._downloader.trouble(u'ERROR: invalid download number %s for query "%s"' % (n, query))
793
793
					return [None]
794
794
				elif n > self._max_youtube_results:
795
					self._downloader.to_stderr(u'WARNING: ytsearch returns max %i results (you requested %i)'  % (self._max_youtube_results, n))
795
					self._downloader.trouble(u'WARNING: ytsearch returns max %i results (you requested %i)'  % (self._max_youtube_results, n))
796
796
					n = self._max_youtube_results
797
797
				return self._download_n_results(query, n)
798
798
			except ValueError: # parsing prefix as int fails
@@ -812,7 +812,7 @@ class YoutubeSearchIE(InfoExtractor):
812
812
			try:
813
813
				page = urllib2.urlopen(request).read()
814
814
			except (urllib2.URLError, httplib.HTTPException, socket.error), err:
815
				self._downloader.to_stderr(u'ERROR: unable to download webpage: %s' % str(err))
815
				self._downloader.trouble(u'ERROR: unable to download webpage: %s' % str(err))
816
816
				return [None]
817
817
818
818
			# Extract video identifiers
@@ -864,7 +864,7 @@ class YoutubePlaylistIE(InfoExtractor):
864
864
		# Extract playlist id
865
865
		mobj = re.match(self._VALID_URL, url)
866
866
		if mobj is None:
867
			self._downloader.to_stderr(u'ERROR: invalid url: %s' % url)
867
			self._downloader.trouble(u'ERROR: invalid url: %s' % url)
868
868
			return [None]
869
869
870
870
		# Download playlist pages
@@ -878,7 +878,7 @@ class YoutubePlaylistIE(InfoExtractor):
878
878
			try:
879
879
				page = urllib2.urlopen(request).read()
880
880
			except (urllib2.URLError, httplib.HTTPException, socket.error), err:
881
				self._downloader.to_stderr(u'ERROR: unable to download webpage: %s' % str(err))
881
				self._downloader.trouble(u'ERROR: unable to download webpage: %s' % str(err))
882
882
				return [None]
883
883
884
884
			# Extract video identifiers