Skip to content

Commit

Permalink
Push v0.5.1 to master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
schemen authored Nov 12, 2018
2 parents 8c56428 + 20645db commit ebae73e
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 41 deletions.
7 changes: 4 additions & 3 deletions bin/Config.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@

"""Config loading Module"""
import configparser
import os

def load_config(location='config.ini'):
"""Function that returns a configuration as dict"""
config = {}
config_reader = configparser.ConfigParser()
config_reader.optionxform = str
config_reader.read(location)

for key, value in config_reader.items("CONFIG"):
if key in os.environ:
config[key] = os.environ[key]
else:
config[key] = value

return config
5 changes: 3 additions & 2 deletions bin/Converter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
""" Converter Module """
import logging
import os
import zipfile
Expand All @@ -8,7 +9,7 @@


class Converter:
""" This Class Converts the result of the Downloader class into Ebooks"""
""" This Class Converts the result of the Downloader class into Ebooks """

def __init__(self):
self.saveloc = None
Expand All @@ -24,7 +25,7 @@ def __init__(self):


def data_collector(self, chapter):
""" Method that collects data"""
""" Method that collects data """

# Load config right at the start
config = None
Expand Down
1 change: 1 addition & 0 deletions bin/ConverterHandler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" Module that handles the workflow of the Converter Class """
import logging
import os
import bin.Helper as helper
Expand Down
27 changes: 20 additions & 7 deletions bin/Downloader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Downloader Module"""
import logging
import os
import requests
from shutil import move
import bin.Config as Config
import bin.Helper as helper
import bin.sourceparser.Mangastream as msparser
Expand All @@ -13,6 +13,7 @@


class Downloader:
"""Class to manage downloads"""

def __init__(self):
self.database = None
Expand All @@ -30,6 +31,8 @@ def __init__(self):


def data_collector(self, chapter):
"""Method to collect and fill data for the class"""

# Load config right at the start
config = None
if not config:
Expand Down Expand Up @@ -63,16 +66,16 @@ def data_collector(self, chapter):


def data_processor(self):
"""Method that starts processing the collected data"""

logging.info("Proccesing data for %s"% self.mangatitle)
logging.info("Proccesing data for %s", self.mangatitle)


# Get image urls!
# Mangastream Parser
if self.origin == "mangastream.com" or self.origin == "readms.net":
urllist = msparser.getPagesUrl(self.mangastarturl,self.mangapages)
urllist = msparser.getPagesUrl(self.mangastarturl, self.mangapages)


# check if we have images to download
if not len(urllist) == 0:

Expand All @@ -90,7 +93,7 @@ def data_processor(self):
# Mangafox Parser
elif self.origin == "mangafox.me" or self.origin == "mangafox.la" or self.origin == "fanfox.net":
urllist = mxparser.getPagesUrl(self.mangastarturl, self.mangapages)

# check if we have images to download
if not len(urllist) == 0:

Expand All @@ -108,7 +111,7 @@ def data_processor(self):
# CDM Parser
elif self.origin == "cdmnet.com.br":
urllist = cdmparser.getPagesUrl(self.mangastarturl, self.mangapages)

# check if we have images to download
if not len(urllist) == 0:

Expand All @@ -124,6 +127,8 @@ def data_processor(self):
logging.info("Finished download of %s!", self.mangatitle)

def downloader(self, url, counter, parser):
"""Method that downloads files"""

# Check if we have the Download folder
helper.createFolder(self.downloadfolder)

Expand All @@ -132,9 +137,17 @@ def downloader(self, url, counter, parser):

# Download the image!
f = open(tempdl, 'wb')
f.write(requests.get(parser(url)).content)
f.write(requests.get(parser(url), headers={'referer': url}).content)
f.close()

# convert img to png
imgtest = Image.open(tempdl)
if imgtest.format != 'PNG':
logging.debug("Image %s is not a PNG... convertig.", tempdl)
imgtest.save(tempdl, "PNG")
else:
imgtest.close()

# If everything is alright, write image to final name
os.rename(tempdl, imagepath)

Expand Down
20 changes: 10 additions & 10 deletions bin/DownloaderHandler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
""" Module to handle the workflow of with the Downloader Class """
import logging
import os
from shutil import move
import bin.Helper as helper
from bin.Downloader import Downloader

'''
downloadHandler
'''

def downloader(args):

""" the downloader function """

# Make the query
chapters = helper.getChapters()

Expand All @@ -29,15 +29,15 @@ def downloader(args):
oldlocation = str(current_chapter.saveloc + current_chapter.mangatitle)
newlocation = str(current_chapter.saveloc + current_chapter.manganame)
if os.path.isdir(oldlocation):
logging.info("Moving %s from old DL location to new one..." % current_chapter.mangatitle)
logging.info("Moving %s from old DL location to new one...", current_chapter.mangatitle)
helper.createFolder(newlocation)
move(oldlocation, newlocation)



# Check if chapter needs to be downloaded
if helper.verifyDownload(chapter):
logging.debug("Manga %s downloaded already!" % current_chapter.mangatitle)
logging.debug("Manga %s downloaded already!", current_chapter.mangatitle)
else:

# Check if Download loop & Download task is selected
Expand All @@ -48,11 +48,11 @@ def downloader(args):
if helper.checkTime(current_chapter.chapterdate):
current_chapter.data_processor()
else:
logging.debug("%s is older than 24h, will not be processed by daemon." % current_chapter.mangatitle)
logging.debug("%s is older than 24h, will not be processed by daemon.", current_chapter.mangatitle)


def directDownloader(chapterids=[]):

""" Function to handle direct download calls """
logging.debug("Following Chapters are directly converted:")
logging.debug(chapterids)

Expand Down Expand Up @@ -81,13 +81,13 @@ def directDownloader(chapterids=[]):
oldlocation = str(current_chapter.saveloc + current_chapter.mangatitle)
newlocation = str(current_chapter.saveloc + current_chapter.manganame)
if os.path.isdir(oldlocation):
logging.info("Moving %s from old DL location to new one..." % current_chapter.mangatitle)
logging.info("Moving %s from old DL location to new one...", current_chapter.mangatitle)
helper.createFolder(newlocation)
move(oldlocation, newlocation)

# Check if chapter needs to be downloaded
if helper.verifyDownload(chapter):
logging.info("Manga %s downloaded already!" % current_chapter.mangatitle)
logging.info("Manga %s downloaded already!", current_chapter.mangatitle)
else:

current_chapter.data_processor()
21 changes: 13 additions & 8 deletions bin/Helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
Helper Unit.
This File provides functions to other classes
'''

# Load config right at the start
Expand Down Expand Up @@ -434,7 +433,7 @@ def getMangaData(url, entry):
# Mangastream Parser
if origin == "mangastream.com" or origin == "readms.net":

logging.debug("Getting Mangadata from Mangastream.com for %s" % url)
logging.debug("Getting Mangadata from Mangastream.com for %s", url)

# Easy Stuff
title = entry.title
Expand All @@ -456,7 +455,7 @@ def getMangaData(url, entry):

# Mangafox Parser
elif origin == "mangafox.me" or origin == "mangafox.la" or origin == "fanfox.net":
logging.debug("Getting Mangadata from Mangafox. for %s" % url)
logging.debug("Getting Mangadata from Mangafox. for %s", url)

# Easy Stuff
title = entry.title
Expand All @@ -478,7 +477,7 @@ def getMangaData(url, entry):

# CDM Parser
elif origin == "cdmnet.com.br":
logging.debug("Getting Mangadata from CDM. for %s" % url)
logging.debug("Getting Mangadata from CDM. for %s", url)

# Easy Stuff
title = entry.title
Expand Down Expand Up @@ -511,9 +510,9 @@ def getMangaData(url, entry):
def createFolder(folder):
if not os.path.exists(folder):
os.makedirs(folder)
logging.debug("Folder %s Created!" % folder)
logging.debug("Folder %s Created!", folder)
else:
logging.debug("Folder %s Exists!" % folder)
logging.debug("Folder %s Exists!", folder)


'''
Expand All @@ -533,8 +532,14 @@ def sanetizeName(name):
Check if time is older than 24h
Returns: true or false
'''
def checkTime(time):
objecttime = datetime.datetime.strptime(time, "%a, %d %b %Y %H:%M:%S %z")
def checkTime(checktime):
# Some feeds don't deliver a timezone value, inject Zulu
try:
objecttime = datetime.datetime.strptime(checktime, "%a, %d %b %Y %H:%M:%S %z")
except ValueError:
checktime = checktime + " +0000"
objecttime = datetime.datetime.strptime(checktime, "%a, %d %b %Y %H:%M:%S %z")

now = datetime.datetime.now(datetime.timezone.utc)

delta = now - objecttime
Expand Down
2 changes: 1 addition & 1 deletion bin/Models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" Models Module """
from peewee import *
import configparser
import bin.Config as Config


Expand Down
2 changes: 1 addition & 1 deletion bin/RssParser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" RSS Parsing Module """
import logging
import ssl
import feedparser
import bin.Helper as helper
from bin.models.Manga import Manga
from bin.Models import *

Expand Down
1 change: 1 addition & 0 deletions bin/Sender.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" Sending Module """
import logging
import os
import smtplib
Expand Down
5 changes: 1 addition & 4 deletions bin/SenderHandler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
""" Module to handle the sending workflow """
import logging
import os
import bin.Helper as helper
from bin.Sender import Sender

try:
from StringIO import StringIO
except ImportError:
from io import StringIO

def SenderHandler(args):
""" Function that handles the sending of ebooks when a loop is called """
Expand Down
2 changes: 1 addition & 1 deletion bin/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "v0.5.0"
__version__ = "v0.5.1"
3 changes: 2 additions & 1 deletion bin/sourceparser/Cdmnet.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python
""" Cdmnet Parsing Module """
import logging
import re
import requests
from urllib.parse import urlparse
import requests
from bs4 import BeautifulSoup

'''
Expand Down
3 changes: 2 additions & 1 deletion bin/sourceparser/Mangafox.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python
""" Mangafox Parsing Module """
import logging
import re
import requests
from urllib.parse import urlparse
import requests
from bs4 import BeautifulSoup

'''
Expand Down
1 change: 1 addition & 0 deletions bin/sourceparser/Mangastream.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" Mangastream Parser Module """
#!/usr/bin/env python
import logging
import re
Expand Down
5 changes: 3 additions & 2 deletions m2em.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
""" Main Wrapper Module """
import os
import sys
import logging
Expand Down Expand Up @@ -77,9 +78,9 @@ def read_arguments(self):
parser.add_argument("--download",
help="Downloads Chapter directly by chapter ID. Multiple IDs can be given",
default=[], nargs='*',)
parser.add_argument("-p","--process",
parser.add_argument("-p", "--process",
help="Processes chapter(s) by chapter ID, Download, convert, send. Multiple IDs can be given",
default=[], nargs='*',)
default=[], nargs='*',)
parser.add_argument("-a", "--action",
help="Start action. Options are: rssparser (collecting feed data), downloader, converter or sender ")
parser.add_argument("-ss", "--switch-send",
Expand Down

0 comments on commit ebae73e

Please sign in to comment.