Prechádzať zdrojové kódy

corrected errors in youtubeAPI and made it pep8 clean, fixed the dictionary iteration in subscription

Helmut Pozimski 10 rokov pred
rodič
commit
019d004b47
3 zmenil súbory, kde vykonal 40 pridanie a 23 odobranie
  1. 1 1
      lib_stov/configuration.py
  2. 20 12
      lib_stov/youtube.py
  3. 19 10
      lib_stov/youtubeAPI.py

+ 1 - 1
lib_stov/configuration.py

@@ -96,7 +96,7 @@ class conf(object):
         except IOError:
             raise stov_exceptions.ConfigFileWriteErrorException()
         else:
-            for key in self.values.items():
+            for key, value in self.values.items():
                 configfile.write(key.upper() + "=" + self.values[key] +
                                  "\n")
             configfile.close()

+ 20 - 12
lib_stov/youtube.py

@@ -27,7 +27,7 @@ from lib_stov import stov_exceptions
 
 class video(object):
     def __init__(self, title, description, ytid, conf, downloaded, failcount=0,
-            id=0):
+                 id=0):
         self.__ID = id
         self.title = title
         self.description = description
@@ -38,28 +38,36 @@ class video(object):
 
     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:
+        targetdir = self.__conf.values["downloaddir"] + "/" + directory
+        if os.access(targetdir, os.F_OK) is False:
             try:
-                os.makedirs(self.__targetdir, 0o750)
+                os.makedirs(targetdir, 0o750)
             except os.error:
                 raise stov_exceptions.DirectoryCreationFailedException()
 
-        os.chdir(self.__targetdir)
+        os.chdir(targetdir)
         if self.downloaded == 0:
             try:
                 if self.__conf.outputlevel == "default":
                     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"))
+                                          % itag_value, "-t",
+                                           "http://www.youtube.com/watch?v=%s"
+                                           % self.ytid],
+                                          stderr=sys.stderr,
+                                          stdout=open("/dev/null", "w"))
                 elif self.__conf.outputlevel == "verbose":
                     subprocess.check_call(["youtube-dl", "--max-quality=%s"
-                    % itag_value, "-t", "http://www.youtube.com/watch?v=%s" % self.ytid],
-                    stderr=sys.stderr, stdout=sys.stdout)
+                                          % itag_value, "-t",
+                                          "http://www.youtube.com/watch?v=%s"
+                                           % self.ytid],
+                                          stderr=sys.stderr, stdout=sys.stdout)
                 elif self.__conf.outputlevel == "quiet":
                     subprocess.check_call(["youtube-dl", "--max-quality=%s"
-                    % itag_value, "-t", "http://www.youtube.com/watch?v=%s" % self.ytid],
-                    stderr=open("/dev/null", "w"), stdout=open("/dev/null", "w"))
+                                          % itag_value, "-t",
+                                          "http://www.youtube.com/watch?v=%s"
+                                          % self.ytid],
+                                          stderr=open("/dev/null", "w"),
+                                          stdout=open("/dev/null", "w"))
             except subprocess.CalledProcessError:
                 self.failcnt = int(self.failcnt) + 1
                 return False
@@ -71,4 +79,4 @@ class video(object):
         self.__ID = id
 
     def GetID(self):
-        return self.__ID
+        return self.__ID

+ 19 - 10
lib_stov/youtubeAPI.py

@@ -33,21 +33,30 @@ class Parser(object):
         for title in dom.getElementsByTagName('title'):
             xmlTag = title.toxml()
             if i == 0:
-                channel.title = xmlTag.replace('<title>', '').replace('</title>', '')
-                channel.title = channel.title.replace('&amp;', '&').replace('&quot;', '"')
+                channel.title = xmlTag.replace('<title>', '')
+                channel.title = channel.title.replace('</title>', '')
+                channel.title = channel.title.replace('&amp;', '&')
+                channel.title = channel.title.replace('&quot;', '"')
             else:
-                video_title = xmlTag.replace('<title>', '').replace('</title>', '')
-                video_title = video_title.replace('&amp;', '&').replace('&quot;', '"')
+                video_title = xmlTag.replace('<title>', '')
+                video_title = video_title.replace('</title>', '')
+                video_title = video_title.replace('&amp;', '&')
+                video_title = video_title.replace('&quot;', '"')
                 try:
-                    xmlTag = dom.getElementsByTagName('media:description')[i-1].toxml()
-                    video_description = xmlTag.replace('<media:description type="plain">',
-                    '').replace('</media:description>', '')
+                    xmlTag = dom.getElementsByTagName('media:\
+                    description')[i-1].toxml()
+                    video_description = xmlTag.replace('<media:description '
+                                                       'type="plain">',
+                                                       '')
+                    video_description = video_description.replace('</media:\
+                    description>', '')
                 except IndexError:
                     video_description = ""
                 video_id = dom.getElementsByTagName('yt:videoid')[i-1].toxml()
-                video_id = video_id.replace('<yt:videoid>', '').replace('</yt:videoid>',
-                    '')
-                channel.videos.append(YtVideo(video_title, video_description, video_id))
+                video_id = video_id.replace('<yt:videoid>', '').replace(
+                    '</yt:videoid>', '')
+                channel.videos.append(YtVideo(video_title, video_description,
+                                              video_id))
             i = i + 1
         return channel