Prechádzať zdrojové kódy

Use youtube API version 2, remove dependency to feedparser module

Helmut Pozimski 11 rokov pred
rodič
commit
73dc600c5b
6 zmenil súbory, kde vykonal 20 pridanie a 27 odobranie
  1. 5 1
      CHANGELOG
  2. 1 3
      README
  3. 0 1
      TODO
  4. 0 9
      install.py
  5. 13 13
      subscription.py
  6. 1 0
      youtubeAPI.py

+ 5 - 1
CHANGELOG

@@ -4,7 +4,11 @@
 * Added notify option
 * Changed --lsvids to print the download status
 * Fixed error message printed when youtube-dl fails
-
+* Made the youtube-dl output shown to the user depend on the defined output level
+* Now uses youtube API version 2
+* Fixed situation when all videos fail and the output would have suggested there were no videos to be downloaded
+* Improved output behaviour so strings will be properly encoded
+* Added "verbose" and "quiet" output modes
 
 0.2
 ----

+ 1 - 3
README

@@ -11,7 +11,6 @@ see ./stov.py --help
 stov depends on the following software to be installed:
 
 	* 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 ===
@@ -41,8 +40,7 @@ MAXRESOLUTION: Maximum resolution to use for downloaded videos, please note that
 
 === KNOWN ISSUES ===
 
-stov still uses Youtube API version 1 which is deprecated by Google.
-Version 2 (the current version) will be implemented later
+In some situations, adding a channel with a search parameter or a playlist will lead to two subscriptions being created
 
 === INSTALLATION ===
 

+ 0 - 1
TODO

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

+ 0 - 9
install.py

@@ -65,15 +65,6 @@ you can write to it."""
 					"be able to run the program but use it at your own risk!")
 	else:
 		print "Checking running python version: OK"
-	try:
-		import feedparser
-	except ImportError:
-		print >> sys.stderr, ("The feedparser module could not be loaded, "
-					"it either isn't installed or not properly installed, "
-					"please install python-feedparser via your package manager")
-		sys.exit(1)
-	else:
-		print "Checking feedparser module: OK"
 	try:
 		subprocess.check_call(["youtube-dl", "-h"], stdout=subprocess.PIPE)
 	except subprocess.CalledProcessError:

+ 13 - 13
subscription.py

@@ -21,8 +21,7 @@ import gettext
 import urllib2
 import sqlite3
 
-import feedparser
-
+import youtubeAPI
 import youtube
 
 from outputhelper import printf
@@ -85,10 +84,8 @@ class sub(object):
 				"new video was NOT added! Please check permissions and try again."),
 				outputlevel="default", level=self.__conf.outputlevel, descriptor="stderr")
 
-		for i in self.__ParsedResponse.entries:
-			self.__ytid = i.link.partition("=")
-			self.__ytid = self.__ytid[2].partition("&")
-			self.__ytid = self.__ytid[0]
+		for i in self.__ParsedResponse.videos:
+			self.__ytid = i.ytid
 			self.__videoquery = "SELECT id FROM videos WHERE ytid=?"
 			self.__cursor.execute(self.__videoquery, (self.__ytid,))
 			self.__tmpid = self.__cursor.fetchall()
@@ -162,7 +159,7 @@ class sub(object):
 				outputlevel="default", level=self.__conf.outputlevel, descriptor="stderr")
 		else:
 			self.__cursor = self.__connection.cursor()
-			self.__title = self.__ParsedResponse.feed.title
+			self.__title = self.__ParsedResponse.title
 			self.__directory = self.__name + "_" + self.__search.replace(" ", "_")
 			self.__query = "INSERT INTO subscriptions (title, type, searchstring, \
 			directory, name) VALUES (?, ?, ?, ?, ?)"
@@ -184,7 +181,9 @@ class sub(object):
 
 		"""
 		try:
-			self.__APIResponse = urllib2.urlopen(self.__APIURL)
+			self.__ConnectAPI = urllib2.urlopen(self.__APIURL)
+			self.__APIResponse = self.__ConnectAPI.read()
+			self.__ConnectAPI.close()
 		except IOError:
 			printf(_("Could not get API data, maybe the API "
 						"is down or you have given wrong parameters"
@@ -192,22 +191,23 @@ class sub(object):
 				outputlevel="default", level=self.__conf.outputlevel, descriptor="stderr")
 			sys.exit(1)
 		else:
-			self.__ParsedResponse = feedparser.parse(self.__APIResponse)
+			parser = youtubeAPI.Parser(self.__APIResponse)
+			self.__ParsedResponse = parser.parse()
 
 	def __ConstructAPIURL(self):
 		"""Constructs the API URL which is used to retrieve API data"""
 		if self.__type == "channel":
 			self.__APIURL = "https://gdata.youtube.com/feeds/api/users/"\
-			+ urllib2.quote(self.__name) + "/uploads/"
+			+ urllib2.quote(self.__name) + "/uploads/" + "?v=2"
 			if self.__search != "":
-				self.__APIURL = self.__APIURL + "?q=" + "%22"\
+				self.__APIURL = self.__APIURL + "&q=" + "%22"\
 				+ urllib2.quote(self.__search) + "%22"
 		elif self.__type == "search":
 			self.__APIURL = "http://gdata.youtube.com/feeds/api/videos?q="\
-			+ urllib2.quote(self.__search) + "&max-results=10"
+			+ urllib2.quote(self.__search) + "&max-results=10" + "&v=2"
 		elif self.__type == "playlist":
 			self.__APIURL = "https://gdata.youtube.com/feeds/api/playlists/"\
-			+ "%20" + urllib2.quote(self.__name) + "%20"
+			+ "%20" + urllib2.quote(self.__name) + "%20" + "?v=2"
 		else:
 			printf(_("None or invalid subscription type given, "
 						"please check the type option and try again"),

+ 1 - 0
youtubeAPI.py

@@ -34,6 +34,7 @@ class Parser(object):
 				channel.title = xmlTag.replace('<title>','').replace('</title>','')
 			else:
 				video_title = xmlTag.replace('<title>','').replace('</title>','')
+				video_title = video_title.replace('&amp;','&').replace('&quot;','"')
 				xmlTag = dom.getElementsByTagName('media:description')[i-1].toxml()
 				video_description = xmlTag.replace('<media:description type="plain">'
 				,'').replace('</media:description>','')