Browse Source

project-wide: reformat code

Helmut Pozimski 3 years ago
parent
commit
901d50a3c3

+ 6 - 6
lib_stov/configuration.py

@@ -20,9 +20,9 @@ stov, the configuration file is expected to be in json format and reside in
 ~/.stov/stov.json.
 ~/.stov/stov.json.
 """
 """
 
 
-import os
 import json
 import json
 import logging
 import logging
+import os
 
 
 from lib_stov import stov_exceptions
 from lib_stov import stov_exceptions
 
 
@@ -84,7 +84,7 @@ class Conf(object):
             "notify": _("if you want to be notified via e-mail about new "
             "notify": _("if you want to be notified via e-mail about new "
                         "videos"),
                         "videos"),
             "video_codec": _("which video codec you prefer (h264, webm or "
             "video_codec": _("which video codec you prefer (h264, webm or "
-                            "flv)"),
+                             "flv)"),
             "video_height": _("sets the height of the video to download (e.g."
             "video_height": _("sets the height of the video to download (e.g."
                               " 1080 for 1920x180)"),
                               " 1080 for 1920x180)"),
             "audio_quality": _("sets the requested audio quality "
             "audio_quality": _("sets the requested audio quality "
@@ -93,7 +93,7 @@ class Conf(object):
                              "with the subscription search string")
                              "with the subscription search string")
         }
         }
         self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
         self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
-            self.values["database"]
+                      self.values["database"]
         self.outputlevel = "default"
         self.outputlevel = "default"
 
 
     def __new__(cls, *args, **kwargs):
     def __new__(cls, *args, **kwargs):
@@ -160,7 +160,7 @@ class Conf(object):
             self.values[tmplist[0].lower()] = tmplist[1]
             self.values[tmplist[0].lower()] = tmplist[1]
         configfile.close()
         configfile.close()
         self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
         self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
-            self.values["database"]
+                      self.values["database"]
 
 
     def read_config(self):
     def read_config(self):
         """Reads the existing json configuration files and loads the values in
         """Reads the existing json configuration files and loads the values in
@@ -207,7 +207,7 @@ class Conf(object):
         self.values["db_version"] = "0"
         self.values["db_version"] = "0"
         self.read_config()
         self.read_config()
         if self.values["db_version"] == "0" or \
         if self.values["db_version"] == "0" or \
-                int(self.values["db_version"]) <\
+                int(self.values["db_version"]) < \
                 int(currentdbversion):
                 int(currentdbversion):
             self.values["db_version"] = str(currentdbversion)
             self.values["db_version"] = str(currentdbversion)
             return False
             return False
@@ -230,7 +230,7 @@ class Conf(object):
             if user_input != "":
             if user_input != "":
                 self.values[value] = user_input
                 self.values[value] = user_input
         self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
         self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
-            self.values["database"]
+                      self.values["database"]
 
 
     def migrate_config(self):
     def migrate_config(self):
         """Migrates the configuration from the old plain text config to
         """Migrates the configuration from the old plain text config to

+ 2 - 2
lib_stov/database.py

@@ -17,11 +17,11 @@
 
 
 """This module is responsible for all database related operations."""
 """This module is responsible for all database related operations."""
 
 
-import sqlite3
 import logging
 import logging
+import sqlite3
 
 
-from lib_stov import stov_exceptions
 from lib_stov import generic_video
 from lib_stov import generic_video
+from lib_stov import stov_exceptions
 from lib_stov import subscription
 from lib_stov import subscription
 
 
 LOGGER = logging.getLogger("stov")
 LOGGER = logging.getLogger("stov")

+ 3 - 2
lib_stov/generic_video.py

@@ -18,12 +18,12 @@
 
 
 """This module takes care of managing and downloading single videos."""
 """This module takes care of managing and downloading single videos."""
 
 
-import os
 import logging
 import logging
+import os
 
 
+from lib_stov import configuration
 from lib_stov import stov_exceptions
 from lib_stov import stov_exceptions
 from lib_stov import youtubedl_wrapper
 from lib_stov import youtubedl_wrapper
-from lib_stov import configuration
 
 
 LOGGER = logging.getLogger("stov")
 LOGGER = logging.getLogger("stov")
 
 
@@ -32,6 +32,7 @@ class Video(object):
     """This class stores all the attributes of a single video and is
     """This class stores all the attributes of a single video and is
     also able to download it using youtube-dl.
     also able to download it using youtube-dl.
     """
     """
+
     def __init__(self, title, site_id, downloaded, failcount=0, video_id=0):
     def __init__(self, title, site_id, downloaded, failcount=0, video_id=0):
         self._id = video_id
         self._id = video_id
         self.title = title
         self.title = title

+ 4 - 5
lib_stov/helpers.py

@@ -18,18 +18,17 @@
 """ This module contains several functions that are necessary to set up
 """ This module contains several functions that are necessary to set up
 the application. """
 the application. """
 
 
+import argparse
 import gettext
 import gettext
+import logging
 import os
 import os
-import sys
 import signal
 import signal
-import argparse
-import logging
-
+import sys
 from distutils.spawn import find_executable
 from distutils.spawn import find_executable
 
 
-from lib_stov import stov_exceptions
 from lib_stov import configuration
 from lib_stov import configuration
 from lib_stov import database
 from lib_stov import database
+from lib_stov import stov_exceptions
 
 
 LOGGER = logging.getLogger("stov")
 LOGGER = logging.getLogger("stov")
 
 

+ 4 - 5
lib_stov/program.py

@@ -20,17 +20,16 @@ application.
 """
 """
 
 
 import logging
 import logging
-import sys
 import smtplib
 import smtplib
 import socket
 import socket
-
-from email.mime.text import MIMEText
+import sys
 from email.mime.multipart import MIMEMultipart
 from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
 
 
-from lib_stov import subscription
 from lib_stov import stov_exceptions
 from lib_stov import stov_exceptions
-from lib_stov.database import Db
+from lib_stov import subscription
 from lib_stov.configuration import Conf
 from lib_stov.configuration import Conf
+from lib_stov.database import Db
 
 
 LOGGER = logging.getLogger("stov")
 LOGGER = logging.getLogger("stov")
 
 

+ 11 - 0
lib_stov/stov_exceptions.py

@@ -96,6 +96,7 @@ class ConfigFileWriteErrorException(Exception):
     file fails.
     file fails.
 
 
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(ConfigFileWriteErrorException, self).__init__()
         super(ConfigFileWriteErrorException, self).__init__()
         self.__message = _("The configuration could not be written, please"
         self.__message = _("The configuration could not be written, please"
@@ -110,6 +111,7 @@ class DirectoryCreationFailedException(Exception):
     """This exception will be raised when the creation of a directory failed.
     """This exception will be raised when the creation of a directory failed.
 
 
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(DirectoryCreationFailedException, self).__init__()
         super(DirectoryCreationFailedException, self).__init__()
         self.__message = _("The directory could not be created, "
         self.__message = _("The directory could not be created, "
@@ -125,6 +127,7 @@ class ConfigFileReadErrorException(Exception):
     opened for reading
     opened for reading
 
 
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(ConfigFileReadErrorException, self).__init__()
         super(ConfigFileReadErrorException, self).__init__()
         self.__message = _("The configuration could not be read, please check "
         self.__message = _("The configuration could not be read, please check "
@@ -140,6 +143,7 @@ class InvalidConfigurationVersionException(Exception):
     is detected.
     is detected.
 
 
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(InvalidConfigurationVersionException, self).__init__()
         super(InvalidConfigurationVersionException, self).__init__()
         self.__message = _("Invalid config version read.")
         self.__message = _("Invalid config version read.")
@@ -153,6 +157,7 @@ class SubscriptionDisabledException(Exception):
     a requested action is not taken because of this fact.
     a requested action is not taken because of this fact.
 
 
     """
     """
+
     def __init__(self, subscription):
     def __init__(self, subscription):
         super(SubscriptionDisabledException, self).__init__()
         super(SubscriptionDisabledException, self).__init__()
         self.__message = _("The subscription %s is disabled, videos will"
         self.__message = _("The subscription %s is disabled, videos will"
@@ -167,6 +172,7 @@ class DownloadDirectoryCreationFailedException(Exception):
     directory to download a video failed.
     directory to download a video failed.
 
 
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(DownloadDirectoryCreationFailedException, self).__init__()
         super(DownloadDirectoryCreationFailedException, self).__init__()
         self.__message = _("The download directory does not exist and can't "
         self.__message = _("The download directory does not exist and can't "
@@ -181,6 +187,7 @@ class ConfigurationMigrationFailed(Exception):
     """This exception will be raised when the migration of the configuration
     """This exception will be raised when the migration of the configuration
     to the json format fails.
     to the json format fails.
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(ConfigurationMigrationFailed, self).__init__()
         super(ConfigurationMigrationFailed, self).__init__()
         self._message = _("The migration of the configuration to the json "
         self._message = _("The migration of the configuration to the json "
@@ -194,6 +201,7 @@ class YoutubeDlCallFailed(Exception):
     """This exception will be raised when a call to youtube-dl fails because
     """This exception will be raised when a call to youtube-dl fails because
         of an error returned by youtube-dl.
         of an error returned by youtube-dl.
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(YoutubeDlCallFailed, self).__init__()
         super(YoutubeDlCallFailed, self).__init__()
         self._message = _("Execution of youtube-dl failed.")
         self._message = _("Execution of youtube-dl failed.")
@@ -206,6 +214,7 @@ class ChannelNotFound(Exception):
     """ Will be raised when a specific user or channel cannot be found on
     """ Will be raised when a specific user or channel cannot be found on
     the site.
     the site.
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(ChannelNotFound, self).__init__()
         super(ChannelNotFound, self).__init__()
         self._message = _("Channel not found on video site")
         self._message = _("Channel not found on video site")
@@ -217,6 +226,7 @@ class ChannelNotFound(Exception):
 class SiteUnsupported(Exception):
 class SiteUnsupported(Exception):
     """ Will be raised when stov is called for an unsupported site
     """ Will be raised when stov is called for an unsupported site
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(SiteUnsupported, self).__init__()
         super(SiteUnsupported, self).__init__()
         self._message = _("Error: This site is not (yet) supported by stov!")
         self._message = _("Error: This site is not (yet) supported by stov!")
@@ -229,6 +239,7 @@ class TypeNotSupported(Exception):
     """ Will be raised when a video site does not support a specific
     """ Will be raised when a video site does not support a specific
     subscription type
     subscription type
     """
     """
+
     def __init__(self):
     def __init__(self):
         super(TypeNotSupported, self).__init__()
         super(TypeNotSupported, self).__init__()
         self._message = _("Error: This subscription type is not supported by "
         self._message = _("Error: This subscription type is not supported by "

+ 4 - 3
lib_stov/subscription.py

@@ -20,11 +20,11 @@
 
 
 import logging
 import logging
 
 
+from lib_stov import configuration
 from lib_stov import stov_exceptions
 from lib_stov import stov_exceptions
+from lib_stov import twitch
 from lib_stov import yt_noapi
 from lib_stov import yt_noapi
 from lib_stov import zdf_mediathek
 from lib_stov import zdf_mediathek
-from lib_stov import twitch
-from lib_stov import configuration
 
 
 LOGGER = logging.getLogger("stov")
 LOGGER = logging.getLogger("stov")
 
 
@@ -33,6 +33,7 @@ class Sub(object):
     """This class constructs a object that stores all the attributes that define
     """This class constructs a object that stores all the attributes that define
     a subscription and performs the necessary operations on it.
     a subscription and performs the necessary operations on it.
     """
     """
+
     def __init__(self, subscription_type, name, site, search="",
     def __init__(self, subscription_type, name, site, search="",
                  subscription_id=0, title="", directory="", disabled=0):
                  subscription_id=0, title="", directory="", disabled=0):
         self._id = subscription_id
         self._id = subscription_id
@@ -86,7 +87,7 @@ class Sub(object):
         if not self.disabled:
         if not self.disabled:
             LOGGER.debug(_("Matching parameter %s with title %s"),
             LOGGER.debug(_("Matching parameter %s with title %s"),
                          self._search, video.title)
                          self._search, video.title)
-            if self._search != "" and self._conf.values["check_title"]\
+            if self._search != "" and self._conf.values["check_title"] \
                     == "yes":
                     == "yes":
                 return self._search in video.title
                 return self._search in video.title
             else:
             else:

+ 3 - 2
lib_stov/twitch.py

@@ -18,10 +18,10 @@
 
 
 """ This module implements support for subscriptions from twitch.tv"""
 """ This module implements support for subscriptions from twitch.tv"""
 
 
+import logging
+import urllib.error
 import urllib.parse
 import urllib.parse
 import urllib.request
 import urllib.request
-import urllib.error
-import logging
 
 
 from lib_stov import stov_exceptions
 from lib_stov import stov_exceptions
 from lib_stov import yt_noapi
 from lib_stov import yt_noapi
@@ -33,6 +33,7 @@ class Connector(yt_noapi.Connector):
     """ Connector class, performing calls to youtube-dl to retrieve
     """ Connector class, performing calls to youtube-dl to retrieve
         information about videos from twitch.tv
         information about videos from twitch.tv
     """
     """
+
     def __init__(self, subscription_type, name, search=""):
     def __init__(self, subscription_type, name, search=""):
         """Populates the object with all necessary data."""
         """Populates the object with all necessary data."""
         yt_noapi.Connector.__init__(self, subscription_type, name, search)
         yt_noapi.Connector.__init__(self, subscription_type, name, search)

+ 8 - 4
lib_stov/yt_noapi.py

@@ -19,22 +19,24 @@
 """This module provides all classes and methods that were provided by the
 """This module provides all classes and methods that were provided by the
 youtubeAPI module earlier."""
 youtubeAPI module earlier."""
 
 
+import logging
 import subprocess
 import subprocess
+import urllib.error
 import urllib.parse
 import urllib.parse
 import urllib.request
 import urllib.request
-import urllib.error
-import logging
 
 
 import lxml.html
 import lxml.html
+
+from lib_stov import configuration
 from lib_stov import stov_exceptions
 from lib_stov import stov_exceptions
 from lib_stov import youtubedl_wrapper
 from lib_stov import youtubedl_wrapper
-from lib_stov import configuration
 
 
 LOGGER = logging.getLogger("stov")
 LOGGER = logging.getLogger("stov")
 
 
 
 
 class YtChannel(object):
 class YtChannel(object):
     """Stores the relevant attributes of a youtube channel."""
     """Stores the relevant attributes of a youtube channel."""
+
     def __init__(self, _type, title, videos=None):
     def __init__(self, _type, title, videos=None):
         if videos is None:
         if videos is None:
             videos = []
             videos = []
@@ -45,6 +47,7 @@ class YtChannel(object):
 
 
 class YtVideo(object):
 class YtVideo(object):
     """Stores the relevant attributes of a single youtube video."""
     """Stores the relevant attributes of a single youtube video."""
+
     def __init__(self, title, ytid):
     def __init__(self, title, ytid):
         self.title = title
         self.title = title
         self.video_id = ytid
         self.video_id = ytid
@@ -54,6 +57,7 @@ class Connector(object):
     """This class will retrieve all the necessary data from youtube using
     """This class will retrieve all the necessary data from youtube using
     youtube-dl, thus bypassing the API.
     youtube-dl, thus bypassing the API.
     """
     """
+
     def __init__(self, subscription_type, name, search=""):
     def __init__(self, subscription_type, name, search=""):
         """Populates the object with all necessary data."""
         """Populates the object with all necessary data."""
         self._type = subscription_type
         self._type = subscription_type
@@ -75,7 +79,7 @@ class Connector(object):
             self._url = "https://www.youtube.com/channel/%s" \
             self._url = "https://www.youtube.com/channel/%s" \
                         % urllib.parse.quote(self._name)
                         % urllib.parse.quote(self._name)
         elif self._type == "search":
         elif self._type == "search":
-            self._url = "https://www.youtube.com/results?search_query=%s"\
+            self._url = "https://www.youtube.com/results?search_query=%s" \
                         % urllib.parse.quote(self._search)
                         % urllib.parse.quote(self._search)
         elif self._type == "playlist":
         elif self._type == "playlist":
             self._url = "https://www.youtube.com/playlist?list=%s" \
             self._url = "https://www.youtube.com/playlist?list=%s" \

+ 6 - 3
lib_stov/zdf_mediathek.py

@@ -20,19 +20,20 @@
 
 
 import json
 import json
 import logging
 import logging
-import urllib.request
-import urllib.error
 import socket
 import socket
+import urllib.error
+import urllib.request
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
 
 
-from lib_stov import stov_exceptions
 from lib_stov import configuration
 from lib_stov import configuration
+from lib_stov import stov_exceptions
 
 
 LOGGER = logging.getLogger("stov")
 LOGGER = logging.getLogger("stov")
 
 
 
 
 class ZDFChannel(object):
 class ZDFChannel(object):
     """Stores the relevant attributes of a ZDF Mediathek channel"""
     """Stores the relevant attributes of a ZDF Mediathek channel"""
+
     def __init__(self, title, videos=None):
     def __init__(self, title, videos=None):
         if videos is None:
         if videos is None:
             videos = []
             videos = []
@@ -45,6 +46,7 @@ class ZDFVideo(object):
     """Stores the relevant attributes of a single video in the ZDF
     """Stores the relevant attributes of a single video in the ZDF
     Mediathek
     Mediathek
     """
     """
+
     def __init__(self, title, url):
     def __init__(self, title, url):
         self.title = title
         self.title = title
         self.video_id = url
         self.video_id = url
@@ -52,6 +54,7 @@ class ZDFVideo(object):
 
 
 class Connector(object):
 class Connector(object):
     """Connector class performing operations against the API"""
     """Connector class performing operations against the API"""
+
     def __init__(self, subscription_type, name, search=""):
     def __init__(self, subscription_type, name, search=""):
         if subscription_type == "user":
         if subscription_type == "user":
             self._type = "channel"
             self._type = "channel"

+ 1 - 1
setup.py

@@ -43,4 +43,4 @@ setup(
                 ("share/locale/en/LC_MESSAGES",
                 ("share/locale/en/LC_MESSAGES",
                  ["locale/en/LC_MESSAGES/stov.mo"])],
                  ["locale/en/LC_MESSAGES/stov.mo"])],
     requires=['lxml']
     requires=['lxml']
-    )
+)