# Path: resources/lib/model/apiresponse.py
# class ApiResponse:
#     def __init__(self, name=None, year=None, genre=None, plot=None, posters=None, fanarts=None):
#         if genre is None:
#             genre = []
#         if posters is None:
#             posters = []
#         if fanarts is None:
#             fanarts = {}
# 
#         self.name = name
#         self.year = year
#         self.genre = genre
#         self.plot = plot
#         self.posters = posters
#         self.fanarts = fanarts
# 
#     @classmethod
#     def from_dict(cls, name=None, year=None, genre=None, plot=None, posters=None, fanarts=None, **kwargs):
#         return cls(name, year, genre, plot, posters, fanarts)
# 
# Path: resources/lib/scraper/abcscraper.py
# class AbstractScraper:
#     __metaclass__ = ABCMeta
# 
#     def __init__(self, core):
#         self.core = core
#         self.base_path = self.core.storage_path
# 
#     @abstractproperty
#     def name(self):
#         """
#         Returns human readable name of scraper
#         :rtype: str
#         :return: name
#         """
#         pass
# 
#     @abstractmethod
#     def get_game_information(self, nvapp):
#         """
#         Queries game information from API and returns it as a dict
#         :type nvapp: NvApp
#         :rtype: dict
#         """
#         pass
# 
#     @abstractmethod
#     def return_paths(self):
#         """
#         Returns a list of used cache paths by this scraper
#         :rtype: list
#         """
#         pass
# 
#     @abstractmethod
#     def is_enabled(self):
#         pass
# 
#     @staticmethod
#     def _set_up_path(path):
#         if not os.path.exists(path):
#             os.makedirs(path)
# 
#         return path
# 
#     @staticmethod
#     def _dump_image(base_path, url):
#         if url != 'N/A':
#             file_path = os.path.join(base_path, os.path.basename(url))
#             if not os.path.exists(file_path):
#                 if not os.path.exists(os.path.dirname(file_path)):
#                     os.makedirs(os.path.dirname(file_path))
#                 with open(file_path, 'wb') as img:
#                     curl = subprocess.Popen(['curl', '-XGET', url], stdout=subprocess.PIPE)
#                     img.write(curl.stdout.read())
#                     img.close()
# 
#             return file_path
#         else:
# 
#             return None


import os
from resources.lib.model.apiresponse import ApiResponse
from resources.lib.scraper.abcscraper import AbstractScraper



class NvHTTPScraper(AbstractScraper):
    def __init__(self, core, request_service):
        AbstractScraper.__init__(self, core)
        self.cover_cache = self._set_up_path(os.path.join(self.base_path, 'art/poster/'))
        self.request_service = request_service

    def name(self):
        return 'NvHTTP'

    def return_paths(self):
        return [self.cover_cache]

    def is_enabled(self):
        return True

    def get_game_information(self, nvapp):
        game_cover_path = self._set_up_path(os.path.join(self.cover_cache, nvapp.id))

# Path: resources/lib/model/apiresponse.py
# class ApiResponse:
#     def __init__(self, name=None, year=None, genre=None, plot=None, posters=None, fanarts=None):
#         if genre is None:
#             genre = []
#         if posters is None:
#             posters = []
#         if fanarts is None:
#             fanarts = {}
# 
#         self.name = name
#         self.year = year
#         self.genre = genre
#         self.plot = plot
#         self.posters = posters
#         self.fanarts = fanarts
# 
#     @classmethod
#     def from_dict(cls, name=None, year=None, genre=None, plot=None, posters=None, fanarts=None, **kwargs):
#         return cls(name, year, genre, plot, posters, fanarts)
# 
# Path: resources/lib/scraper/abcscraper.py
# class AbstractScraper:
#     __metaclass__ = ABCMeta
# 
#     def __init__(self, core):
#         self.core = core
#         self.base_path = self.core.storage_path
# 
#     @abstractproperty
#     def name(self):
#         """
#         Returns human readable name of scraper
#         :rtype: str
#         :return: name
#         """
#         pass
# 
#     @abstractmethod
#     def get_game_information(self, nvapp):
#         """
#         Queries game information from API and returns it as a dict
#         :type nvapp: NvApp
#         :rtype: dict
#         """
#         pass
# 
#     @abstractmethod
#     def return_paths(self):
#         """
#         Returns a list of used cache paths by this scraper
#         :rtype: list
#         """
#         pass
# 
#     @abstractmethod
#     def is_enabled(self):
#         pass
# 
#     @staticmethod
#     def _set_up_path(path):
#         if not os.path.exists(path):
#             os.makedirs(path)
# 
#         return path
# 
#     @staticmethod
#     def _dump_image(base_path, url):
#         if url != 'N/A':
#             file_path = os.path.join(base_path, os.path.basename(url))
#             if not os.path.exists(file_path):
#                 if not os.path.exists(os.path.dirname(file_path)):
#                     os.makedirs(os.path.dirname(file_path))
#                 with open(file_path, 'wb') as img:
#                     curl = subprocess.Popen(['curl', '-XGET', url], stdout=subprocess.PIPE)
#                     img.write(curl.stdout.read())
#                     img.close()
# 
#             return file_path
#         else:
# 
#             return None


# Path: resources/lib/scraper/nvhttpscraper.py
import os
from resources.lib.model.apiresponse import ApiResponse
from resources.lib.scraper.abcscraper import AbstractScraper




class NvHTTPScraper(AbstractScraper):
    def __init__(self, core, request_service):
        AbstractScraper.__init__(self, core)
        self.cover_cache = self._set_up_path(os.path.join(self.base_path, 'art/poster/'))
        self.request_service = request_service

    def name(self):
        return 'NvHTTP'

    def return_paths(self):
        return [self.cover_cache]

    def is_enabled(self):
        return True

    def get_game_information(self, nvapp):
        game_cover_path = self._set_up_path(os.path.join(self.cover_cache, nvapp.id))

        response = ApiResponse()