# Path: modules/mylib_get_data.py
# def games_info(data_dir):
# def get_info(games_list, mylib_dir):
# 
# Path: modules/goglib_get_data.py
# def games_info(data_dir):
# 
# Path: modules/get_banner.py
# def get_banner(game_name, url, banner_path, lib):
# 
#     banner_req = urllib_request(url)
# 
#     try:
# 
#         if not os.path.exists(banner_path):
#             os.makedirs(banner_path)
# 
#         banner_data = urllib_urlopen(banner_req).read()
#         banner_file = open(banner_path + '/' + game_name + '.jpg', 'wb')
#         banner_file.write(banner_data)
#         banner_file.close()
# 
#         pic_src = Image.open(banner_path + '/' + game_name + '.jpg')
#         pic = pic_src.resize((518, 240), PIL.Image.ANTIALIAS)
#         pic.save(banner_path + '/' + game_name + '.jpg')
# 
#         if lib == 'goglib':
# 
#             if not os.path.exists(banner_path + '/unavailable/'):
#                 os.makedirs(banner_path + '/unavailable/')
# 
#             new_pic = Image.open(banner_path + '/' + game_name + '.jpg')
#             pic_grey = new_pic.convert('L')
#             pic_grey.save(banner_path + '/unavailable/' + game_name + '.jpg')
# 
#     except urllib_urlerror as e:
#         print(e.reason)
#     except urllib_httperror as e:
#         print(e.code)
#         print(e.read())


import os, sys, subprocess, shutil
import gi
import gettext
    import sys
from gi.repository import Gtk, Gdk
    from urllib2 import Request as urllib_request
    from urllib2 import urlopen as urllib_urlopen
    from urllib2 import URLError as urllib_urlerror
    from urllib2 import HTTPError as urllib_httperror
    from urllib.request import Request as urllib_request
    from urllib.request import urlopen as urllib_urlopen
    from urllib.request import URLError as urllib_urlerror
    from urllib.request import HTTPError as urllib_httperror
    from ConfigParser import ConfigParser as ConfigParser
    from configparser import ConfigParser as ConfigParser
from modules import mylib_get_data, goglib_get_data, get_banner
            goglib_data = goglib_get_data.games_info(data_dir)

            goglib_names =  goglib_data[1]
            goglib_titles = goglib_data[2]

            name_to_title = {}

            for i in range(len(goglib_names)):
                name_to_title[goglib_names[i]] = goglib_titles[i]

            new_own_scripts = []
            for game in new_scripts:
                if game in goglib_names:
                    new_own_scripts.append(game)

        elif self.lib == 'mylib':

            mylib_data = mylib_get_data.games_info(data_dir)

            mylib_names = mylib_data[1]
            mylib_titles = mylib_data[2]

            name_to_title = {}

            for i in range(len(mylib_names)):
                name_to_title[mylib_names[i]] = mylib_titles[i]

            for game_name in new_scripts:
                image_url = images_url +  game_name + '.jpg'
                banners_dir = data_dir + '/images/mylib/'

# Path: modules/mylib_get_data.py
# def games_info(data_dir):
# def get_info(games_list, mylib_dir):
# 
# Path: modules/goglib_get_data.py
# def games_info(data_dir):
# 
# Path: modules/get_banner.py
# def get_banner(game_name, url, banner_path, lib):
# 
#     banner_req = urllib_request(url)
# 
#     try:
# 
#         if not os.path.exists(banner_path):
#             os.makedirs(banner_path)
# 
#         banner_data = urllib_urlopen(banner_req).read()
#         banner_file = open(banner_path + '/' + game_name + '.jpg', 'wb')
#         banner_file.write(banner_data)
#         banner_file.close()
# 
#         pic_src = Image.open(banner_path + '/' + game_name + '.jpg')
#         pic = pic_src.resize((518, 240), PIL.Image.ANTIALIAS)
#         pic.save(banner_path + '/' + game_name + '.jpg')
# 
#         if lib == 'goglib':
# 
#             if not os.path.exists(banner_path + '/unavailable/'):
#                 os.makedirs(banner_path + '/unavailable/')
# 
#             new_pic = Image.open(banner_path + '/' + game_name + '.jpg')
#             pic_grey = new_pic.convert('L')
#             pic_grey.save(banner_path + '/unavailable/' + game_name + '.jpg')
# 
#     except urllib_urlerror as e:
#         print(e.reason)
#     except urllib_httperror as e:
#         print(e.code)
#         print(e.read())


# Path: get_scripts.py
import os, sys, subprocess, shutil
import gi
import gettext
    import sys
from gi.repository import Gtk, Gdk
    from urllib2 import Request as urllib_request
    from urllib2 import urlopen as urllib_urlopen
    from urllib2 import URLError as urllib_urlerror
    from urllib2 import HTTPError as urllib_httperror
    from urllib.request import Request as urllib_request
    from urllib.request import urlopen as urllib_urlopen
    from urllib.request import URLError as urllib_urlerror
    from urllib.request import HTTPError as urllib_httperror
    from ConfigParser import ConfigParser as ConfigParser
    from configparser import ConfigParser as ConfigParser
from modules import mylib_get_data, goglib_get_data, get_banner

            goglib_data = goglib_get_data.games_info(data_dir)

            goglib_names =  goglib_data[1]
            goglib_titles = goglib_data[2]

            name_to_title = {}

            for i in range(len(goglib_names)):
                name_to_title[goglib_names[i]] = goglib_titles[i]

            new_own_scripts = []
            for game in new_scripts:
                if game in goglib_names:
                    new_own_scripts.append(game)

        elif self.lib == 'mylib':

            mylib_data = mylib_get_data.games_info(data_dir)

            mylib_names = mylib_data[1]
            mylib_titles = mylib_data[2]

            name_to_title = {}

            for i in range(len(mylib_names)):
                name_to_title[mylib_names[i]] = mylib_titles[i]

            for game_name in new_scripts:
                image_url = images_url +  game_name + '.jpg'
                banners_dir = data_dir + '/images/mylib/'

                get_banner.get_banner(game_name, image_url, banners_dir, self.lib)