소스 검색

Add configuration options to configure maximum video resolution and video codecs to be used by youtube-dl for downloading videos

Helmut Pozimski 11 년 전
부모
커밋
4a0b367401
6개의 변경된 파일66개의 추가작업 그리고 17개의 파일을 삭제
  1. 16 8
      README
  2. 0 1
      TODO
  3. 39 2
      configuration.py
  4. 7 2
      stov.py
  5. 2 2
      subscription.py
  6. 2 2
      youtube.py

+ 16 - 8
README

@@ -1,20 +1,24 @@
-ABOUT
+=== ABOUT ===
+
 stov is a program which allows you to subscribe to channels, playlists and search results on youtube. (More platforms may be implemented later) You don't need a youtube account for the program to work since it uses read-only access to the youtube API. You can for example run it as a cron job to automatically download your favourite videos.
 
-USAGE
+=== USAGE ===
+
 see ./stov.py --help
 
-DEPENDENCIES
+=== DEPENDENCIES ===
+
 stov depends on the following software to be installed:
 
-	* Python 2.6 or greater (it might also work with earlier versions, but hasn't been tested, python 3 is not supported yet)
+	* Python 2.6 or higher (it might also work with earlier versions, but hasn't been tested, python 3 is not supported yet)
 	* The feedparser module for python
 	* youtube-dl (get it from http://rg3.github.com/youtube-dl/ if you don't have it yet
 
-COPYING
+=== COPYING ===
+
 see LICENSE
 
-CONFIGURATION
+=== CONFIGURATION ===
 By default, the configuration is defined in ~/stov/stov.config. A default config file is created for you when you run the program for the first time. The following parameters are currently available which you can alter manually:
 
 MAILTO: Recipient address used for notitifications
@@ -32,12 +36,16 @@ NOTIFY: Define if you want to be notified via email about new episodes of your s
 	valid values: yes or no
 DB_VERSION: Database version (Do not change!)
 CONFIG_VERSION: Configuration version (Do not change!)
+VIDEOCODEC: Video codec used for downloaded videos (valid values: h264, webm or flv)
+MAXRESOLUTION: Maximum resolution to use for downloaded videos, please note that not all codecs and resolutions might be available so a lower resolution or other codec might be used in these cases
+
+=== KNOWN ISSUES ===
 
-KNOWN ISSUES
 stov still uses Youtube API version 1 which is deprecated by Google.
 Version 2 (the current version) will be implemented later
 
-INSTALLATION
+=== INSTALLATION ===
+
 You can just run the main file "stov.py" directly from this directory by calling
 it from the shell or with the python interpreter ("./stov.py" or "python stov.py").
 A simple install script is also provided which can be used to install stov to a

+ 0 - 1
TODO

@@ -2,7 +2,6 @@ Long term goals:
 
 * Rethink video and subscription class to cover several video sites
 * Update the code to work with youtube API version 2
-* Make youtube-dl parameters tweakable via configuration
 * Add full german translation
 * Add interactive configuration option
 * Add additional video sites

+ 39 - 2
configuration.py

@@ -44,8 +44,10 @@ class conf(object):
 				"password": "",
 				"youtube-dl": "",
 				"notify": "yes",
-				"config_version": "4",
-				"db_version": "1"
+				"config_version": "5",
+				"db_version": "1",
+				"videocodec": "h264",
+				"maxresolution": "1080p"
 				}
 		self.dbpath = str(os.environ['HOME']) + "/.stov/" + self.values["database"]
 		self.outputlevel = "default"
@@ -179,3 +181,38 @@ class conf(object):
 		"""Performs database changes that need to be done"""
 		if int(self.values["db_version"]) == 1:
 			pass
+
+	def GetYoutubeParameter(self):
+		"""Determines which itag value results from codec and resolution settings
+		and returns it
+
+		"""
+		itag_value = 0
+		if self.values["videocodec"] == "flv":
+			if self.values["maxresolution"] == "240p":
+				itag_value = 5
+			elif self.values["maxresolution"] == "270p":
+				itag_value = 6
+			elif self.values["maxresolution"] == "360p":
+				itag_value = 34
+			elif self.values["maxresolution"] == "480p":
+				itag_value = 35
+		elif self.values["videocodec"] == "webm":
+			if self.values["maxresolution"] == "360p":
+				itag_value = 43
+			elif self.values["maxresolution"] == "480p":
+				itag_value = 44
+			elif self.values["maxresolution"] == "720p":
+				itag_value = 45
+			elif self.values["maxresolution"] == "1080p":
+				itag_value = 46
+		elif self.values["videocodec"] == "h264":
+			if self.values["maxresolution"] == "360p":
+				itag_value = 18
+			elif self.values["maxresolution"] == "720p":
+				itag_value = 22
+			elif self.values["maxresolution"] == "1080p":
+				itag_value = 37
+			elif self.values["maxresolution"] == "3072p":
+				itag_value = 38
+		return itag_value

+ 7 - 2
stov.py

@@ -353,7 +353,12 @@ elif options.download is True:
 		cursor.execute("SELECT id,title,type,name,searchstring,directory \
 FROM subscriptions")
 		subscriptions = cursor.fetchall()
-
+	itag_value = conf.GetYoutubeParameter()
+	if itag_value == 0:
+		printf(_("Codec and resolution could not be determined, using maximum"
+			"possible value"), outputlevel="verbose",
+			level=conf.outputlevel, descriptor="stderr")
+		itag_value = 38
 	for element in subscriptions:
 		listofsubscriptions.append(subscription.sub(id=element[0],
 		title=element[1], type=element[2], name=element[3],
@@ -362,7 +367,7 @@ FROM subscriptions")
 	videosfailed = 0
 	for element in listofsubscriptions:
 		element.GetVideos()
-		element.DownloadVideos()
+		element.DownloadVideos(itag_value)
 		for entry in element.DownloadedVideos:
 			mailcontent.append(entry)
 		videosdownloaded = len(mailcontent)

+ 2 - 2
subscription.py

@@ -126,7 +126,7 @@ class sub(object):
 
 		self.__connection.close()
 
-	def DownloadVideos(self):
+	def DownloadVideos(self, itag_value):
 		"""Uses the DownloadVideo method of the video object to download all
 		videos contained in the subscription and adds them to the list of
 		downloaded videos if the download succeeds.
@@ -134,7 +134,7 @@ class sub(object):
 		"""
 		for video in self.__videos:
 			if video.downloaded == 0:
-				if video.DownloadVideo(self.__directory) is True:
+				if video.DownloadVideo(self.__directory, itag_value) is True:
 					self.DownloadedVideos.append(video.title)
 				else:
 					self.FailedVideos = self.FailedVideos + 1

+ 2 - 2
youtube.py

@@ -33,7 +33,7 @@ class video(object):
 		self.__conf = conf
 		self.downloaded = downloaded
 
-	def DownloadVideo(self, directory):
+	def DownloadVideo(self, directory, itag_value):
 		"""Downloads the video by calling youtube-dl as an external process"""
 		self.__targetdir = self.__conf.values["downloaddir"] + "/" + directory
 		if os.access(self.__targetdir, os.F_OK) is False:
@@ -47,7 +47,7 @@ and can't be created. Please check your configuration and try again"),
 		os.chdir(self.__targetdir)
 		if self.downloaded == 0:
 			try:
-				subprocess.check_call(["youtube-dl", "--max-quality=22", "-t",
+				subprocess.check_call(["youtube-dl", "--max-quality=%s" % itag_value, "-t",
 				"http://www.youtube.com/watch?v=%s" % self.ytid],
 				stderr=sys.stderr, stdout=open("/dev/null", "w"))
 				try: