Browse Source

corrected error in the subscription class and made it pep8 clean

Helmut Pozimski 10 years ago
parent
commit
5e7f6bbdf0
1 changed files with 29 additions and 24 deletions
  1. 29 24
      lib_stov/subscription.py

+ 29 - 24
lib_stov/subscription.py

@@ -31,10 +31,9 @@ from lib_stov import youtube
 from lib_stov import stov_exceptions
 
 
-
 class sub(object):
-    def __init__(self, type, name, conf, search="", id=0, title="", directory="",
-                 disabled=0):
+    def __init__(self, type, name, conf, search="", id=0, title="",
+                 directory="", disabled=0):
         self.__ID = id
         self.__title = title
         self.__type = type
@@ -70,7 +69,8 @@ class sub(object):
         """Checks if the subscription is enabled and the video matches the
         search string defined for the subscription"""
         if self.__disabled is False:
-            if self.__search != "" and self.__conf.values["check_title"] == "yes":
+            if self.__search != "" and self.__conf.values["check_title"]\
+                    == "yes":
                 if self.__search in video.title:
                     return True
                 else:
@@ -80,16 +80,18 @@ class sub(object):
         else:
                 return False
 
-
     def GatherVideos(self, video_data):
         """Gathers all videos in the subscription and saves
         them in an the internal list so they can be accessed by the object
 
         """
         for i in video_data:
-            self.__video_list.append(youtube.video(id=i[0],
-                                               title=i[1], description=i[2], ytid=i[3],
-                                               downloaded=i[4], failcount=i[5], conf=self.__conf))
+            self.__video_list.append(youtube.video(id=i[0], title=i[1],
+                                                   description=i[2],
+                                                   ytid=i[3],
+                                                   downloaded=i[4],
+                                                   failcount=i[5],
+                                                   conf=self.__conf))
 
     def DownloadVideos(self, itag_value):
         """Uses the DownloadVideo method of the video object to download all
@@ -100,22 +102,22 @@ class sub(object):
         if self.__disabled is False:
             for video in self.__video_list:
                 if video.downloaded == 0:
-                    if video.DownloadVideo(self.__directory, itag_value) is True:
+                    if video.DownloadVideo(self.__directory, itag_value) is\
+                            True:
                         self.DownloadedVideos.append(video)
                     else:
-                        self.FailedVideosCount = self.FailedVideosCount + 1
+                        self.FailedVideosCount += 1
                         self.FailedVideos.append(video)
         else:
             raise stov_exceptions.SubscriptionDisabledException(self.__title)
 
-
     def PrintVideos(self):
         """Prepares a human readable list of all videos contained
         in the subscription.
 
         """
+        video_list = []
         for i in self.__video_list:
-            video_list = []
             if i.downloaded == 0:
                 video_list.append(i.title + _("   (pending)"))
             elif i.downloaded == 1:
@@ -139,38 +141,41 @@ class sub(object):
 
         """
         try:
-            self.__ConnectAPI = urllib2.urlopen(self.__APIURL, timeout=30)
-            self.__APIResponse = self.__ConnectAPI.read()
-            self.__ConnectAPI.close()
+            ConnectAPI = urllib2.urlopen(self.__APIURL, timeout=30)
+            APIResponse = ConnectAPI.read()
+            ConnectAPI.close()
         except urllib2.HTTPError:
                 raise stov_exceptions.NoDataFromYoutubeAPIException()
         except ssl.SSLError:
                 raise stov_exceptions.YoutubeAPITimeoutException(self.__title)
         else:
-            parser = youtubeAPI.Parser(self.__APIResponse)
+            parser = youtubeAPI.Parser(APIResponse)
             self.parsed_response = 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/" + "?v=2" \
-                            + "&max-results=%s" % self.__conf.values["maxvideos"]
+                            + urllib2.quote(self.__name) + "/uploads/" \
+                            "?v=2&max-results=%s" \
+                            % self.__conf.values["maxvideos"]
             if self.__search != "":
                 self.__APIURL = self.__APIURL + "&q=" + "%22" \
-                                + urllib2.quote(self.__search) + "%22"
+                    + urllib2.quote(self.__search) + "%22"
         elif self.__type == "search":
             self.__APIURL = "http://gdata.youtube.com/feeds/api/videos?q=" \
                             + urllib2.quote(self.__search) + "&v=2" \
-                            + "&max-results=%s" % self.__conf.values["maxvideos"]
+                            + "&max-results=%s" \
+                              % self.__conf.values["maxvideos"]
         elif self.__type == "playlist":
             self.__APIURL = "https://gdata.youtube.com/feeds/api/playlists/" \
-                            + "%20" + urllib2.quote(self.__name) + "%20" + "?v=2" \
-                            + "&max-results=%s" % self.__conf.values["maxvideos"]
+                            + "%20" + urllib2.quote(self.__name) + "%20?v=2" \
+                            + "&max-results=%s" \
+                            % self.__conf.values["maxvideos"]
 
     def CheckAndDelete(self, videos):
-        """Checks if a video still exists in the current API response and deletes
-        it if it doesn't
+        """Checks if a video still exists in the current API response and
+        deletes it if it doesn't
 
         """
         self.ParseAPIData()