# -*- coding: utf-8 -*-
"""
Catálogo de aplicaciones a actualizar: lista DESCARGAS.

Cada entrada define url, nombre, pattern de versión, extensión, archivos HTML
a actualizar y opcionalmente custom_fn, github_repo/github_asset o github (OBS).
"""

import re

from . import enlaces

# Referencias a funciones custom para obtener el enlace de descarga
obtener_enlace_7zip = enlaces.obtener_enlace_7zip
obtener_enlace_blender = enlaces.obtener_enlace_blender
obtener_enlace_inkscape = enlaces.obtener_enlace_inkscape
obtener_enlace_libreoffice = enlaces.obtener_enlace_libreoffice
obtener_enlace_linphone = enlaces.obtener_enlace_linphone
obtener_enlace_notepadpp = enlaces.obtener_enlace_notepadpp
obtener_enlace_octave = enlaces.obtener_enlace_octave
obtener_enlace_pdfcreator = enlaces.obtener_enlace_pdfcreator
obtener_enlace_qgis = enlaces.obtener_enlace_qgis
obtener_enlace_r = enlaces.obtener_enlace_r
obtener_enlace_rstudio = enlaces.obtener_enlace_rstudio
obtener_enlace_virtualbox = enlaces.obtener_enlace_virtualbox

# vuze no lo actualizamos porque se abandono no han habido mas actualizaciones desde 2017

DESCARGAS = [
    {
        "url": "https://download.mozilla.org/?product=thunderbird-latest-ssl&os=win64&lang=es-ES",
        "nombre": "Thunderbird",
        "filtro": "",
        "pattern": r"(\d+\.\d+(?:\.\d+)?)",
        "extension": ".exe",
        "html": ["thunderbird.html", "internet.html"],
    },
    {
        "url": "https://download.mozilla.org/?product=firefox-latest-ssl&os=win64&lang=es-ES",
        "nombre": "Firefox",
        "filtro": "",
        "pattern": r"(\d+\.\d+(?:\.\d+)?)",
        "extension": ".exe",
        "html": ["firefox.html", "internet.html"],
    },
    {
        "url": "https://sourceforge.net/projects/filezilla/files/latest/download",
        "nombre": "FileZilla",
        "filtro": "",
        "pattern": r"FileZilla_([\d._]+)_win64-setup\.exe",
        "extension": ".exe",
        "html": ["filezilla.html", "internet.html"],
    },
    {
        "url": "https://www.gimp.org/downloads/",
        "nombre": "gimp",
        "filtro": {"id": "win-download-link"},
        "pattern": r"(\d+\.\d+\.\d+)",
        "extension": ".exe",
        "html": ["gimp.html", "multimedia.html"],
    },
    {
        "url": "https://www.videolan.org/",
        "nombre": "vlc",
        "filtro": {"href": lambda href: href and re.search(r"win64.exe", href)},
        "pattern": r"(\d+\.\d+\.\d+)",
        "extension": ".exe",
        "html": ["vlc.html", "multimedia.html"],
    },
    {
        "url": "https://obsproject.com/es",
        "nombre": "OBSStudio",
        "filtro": {"href": lambda href: href and re.search(r".exe", href)},
        "pattern": r"(\d+\.\d+\.\d+)",
        "extension": ".exe",
        "html": ["obsstudio.html", "multimedia.html"],
        "github": True,
    },
    {
        "url": "https://files.kde.org/digikam/",
        "nombre": "digiKam",
        "filtro": "",
        "pattern": r"digiKam-(\d+\.\d+\.\d+)-Qt6-Win64\.exe",
        "extension": ".exe",
        "html": ["digikam.html", "multimedia.html"],
    },
    {
        "url": "https://sourceforge.net/projects/pidgin/files/latest/download",
        "nombre": "pidgin",
        "filtro": "",
        "pattern": r"pidgin-(\d+\.\d+\.\d+)",
        "extension": ".exe",
        "html": ["pidgin.html", "utilidades.html"],
    },
    {
        "url": "https://boinc.berkeley.edu/download_all.php",
        "nombre": "boinc",
        "filtro": {"href": lambda href: href and re.search(r"64.exe", href)},
        "pattern": r"(\d+\.\d+\.\d+)",
        "extension": ".exe",
        "html": ["boinc.html", "cientifico.html"],
    },
    {
        "url": "https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html",
        "nombre": "putty",
        "filtro": {"href": lambda href: href and re.search(r"w64/putty-64bit", href)},
        "pattern": r"(\d+\.\d+)",
        "extension": ".msi",
        "html": ["putty.html", "internet.html"],
    },
    {
        "url": "https://www.7-zip.org/download.html",
        "nombre": "7zip",
        "filtro": "",
        "pattern": r"7z(\d+)-x64\.exe",
        "extension": ".exe",
        "html": ["7zip.html", "utilidades.html"],
        "custom_fn": obtener_enlace_7zip,
    },
    {
        "url": "https://www.audacityteam.org/download/windows",
        "nombre": "audacity",
        "filtro": "",
        "pattern": r"audacity-win-([\d.]+)-64bit\.exe",
        "extension": ".exe",
        "html": ["audacity.html", "multimedia.html"],
        "github_repo": "audacity/audacity",
        "github_asset": r"audacity-win-[\d.]+-64bit\.exe$",
    },
    {
        "url": "https://www.blender.org/download/",
        "nombre": "blender",
        "filtro": "",
        "pattern": r"blender-([\d.]+)-windows-x64\.msi",
        "extension": ".msi",
        "html": ["blender.html", "multimedia.html"],
        "custom_fn": obtener_enlace_blender,
    },
    {
        "url": "https://sourceforge.net/projects/clamwin/files/latest/download",
        "nombre": "clamwin",
        "filtro": "",
        "pattern": r"clamwin-([\d.]+)",
        "extension": ".exe",
        "html": ["clamwin.html", "utilidades.html"],
    },
    {
        "url": "https://sourceforge.net/projects/dia-installer/files/latest/download",
        "nombre": "dia",
        "filtro": "",
        "pattern": r"dia[-_](?:setup[-_])?(\d+(?:\.\d+)+)",
        "extension": ".exe",
        "html": ["dia.html", "cientifico.html"],
    },
    #{
    #    "url": "https://updates.duplicati.com/stable/",
    #    "nombre": "duplicati",
    #    "filtro": "",
    #    "pattern": r"duplicati-([\d.]+)",
    #    "extension": ".msi",
    #    "html": ["duplicati.html", "utilidades.html"],
    #    "github_repo": "duplicati/duplicati",
    #    "github_asset": r"win-x64-gui\.msi$",
    #},
    {
        "url": "https://www.ganttproject.biz/download/free",
        "nombre": "ganttproject",
        "filtro": "",
        "pattern": r"ganttproject-([\d.]+)\.exe",
        "extension": ".exe",
        "html": ["ganttproject.html", "cientifico.html"],
        "github_repo": "bardsoftware/ganttproject",
        "github_asset": r"ganttproject-[\d.]+\.exe$",
    },
    {
        "url": "https://inkscape.org/release/",
        "nombre": "inkscape",
        "filtro": "",
        "pattern": r"inkscape-(\d+(?:\.\d+)+)",
        "extension": ".exe",
        "html": ["inkscape.html", "multimedia.html"],
        "custom_fn": obtener_enlace_inkscape,
        "usar_wget": True,
    },
    {
        "url": "https://www.libreoffice.org/download/download-libreoffice/",
        "nombre": "libreoffice",
        "filtro": "",
        "pattern": r"LibreOffice_([\d.]+)_Win",
        "extension": ".msi",
        "html": ["libreoffice.html", "oficina.html"],
        "custom_fn": obtener_enlace_libreoffice,
    },
    {
        "url": "https://www.linphone.org/releases/windows/app/",
        "nombre": "linphone",
        "filtro": "",
        "pattern": r"Linphone-([\d.]+)-win64\.exe",
        "extension": ".exe",
        "html": ["linphone.html", "internet.html"],
        "custom_fn": obtener_enlace_linphone,
        "usar_wget": True,
    },
    {
        "url": "https://sourceforge.net/projects/maxima/files/latest/download",
        "nombre": "maxima",
        "filtro": "",
        "pattern": r"maxima-([\d.]+)",
        "extension": ".exe",
        "html": ["maxima.html", "cientifico.html"],
    },
    {
        "url": "https://www.mirc.com/get.php",
        "nombre": "mirc",
        "filtro": "",
        "pattern": r"mirc(\d+)\.exe",
        "extension": ".exe",
        "html": ["mirc.html", "internet.html"],
    },
    {
        "url": "https://notepad-plus-plus.org/downloads/",
        "nombre": "notepad",
        "filtro": "",
        "pattern": r"npp\.([\d.]+)\.",
        "extension": ".exe",
        "html": ["notepad.html", "utilidades.html"],
        "custom_fn": obtener_enlace_notepadpp,
    },
    {
        "url": "https://ftpmirror.gnu.org/gnu/octave/windows/",
        "nombre": "octave",
        "filtro": "",
        "pattern": r"octave-([\d.]+)-w64",
        "extension": ".exe",
        "html": ["octave.html", "cientifico.html"],
        "custom_fn": obtener_enlace_octave,
    },
    {
        "url": "https://www.openshot.org/download/",
        "nombre": "openshot",
        "filtro": "",
        "pattern": r"OpenShot-v([\d.]+)-x86_64\.exe",
        "extension": ".exe",
        "html": ["openshot.html", "multimedia.html"],
        "github_repo": "OpenShot/openshot-qt",
        "github_asset": r"OpenShot-v[\d.]+-x86_64\.exe$",
    },
    {
        "url": "https://download.pdfforge.org/",
        "nombre": "pdfcreator",
        "filtro": "",
        "pattern": r"PDFCreator[-_](\d+(?:[._]\d+)+)",
        "extension": ".exe",
        "html": ["pdfcreator.html", "oficina.html"],
        "custom_fn": obtener_enlace_pdfcreator,
    },
    {
        "url": "https://sourceforge.net/projects/pspp4windows/files/latest/download",
        "nombre": "pspp",
        "filtro": "",
        "pattern": r"pspp-(\d{8})",
        "extension": ".exe",
        "html": ["pspp.html", "cientifico.html"],
    },
    {
        "url": "https://qgis.org/downloads/",
        "nombre": "qgis",
        "filtro": "",
        "pattern": r"QGIS-OSGeo4W-([\d.]+)",
        "extension": ".msi",
        "html": ["qgis.html", "cientifico.html"],
        "custom_fn": obtener_enlace_qgis,
    },
    {
        "url": "https://cran.r-project.org/bin/windows/base/",
        "nombre": "r",
        "filtro": "",
        "pattern": r"R-([\d.]+)-win\.exe",
        "extension": ".exe",
        "html": ["r.html", "cientifico.html"],
        "custom_fn": obtener_enlace_r,
    },
    {
        "url": "https://posit.co/download/rstudio-desktop/",
        "nombre": "rstudio",
        "filtro": "",
        "pattern": r"RStudio-([\d.]+(?:-\d+)?)",
        "extension": ".exe",
        "html": ["rstudio.html", "cientifico.html"],
        "custom_fn": obtener_enlace_rstudio,
    },
    {
        "url": "https://shotcut.org/download/",
        "nombre": "shotcut",
        "filtro": "",
        "pattern": r"shotcut-win64-([\d.]+)\.exe",
        "extension": ".exe",
        "html": ["shotcut.html", "multimedia.html"],
        "github_repo": "mltframework/shotcut",
        "github_asset": r"shotcut-win64-[\d.]+\.exe$",
    },
    {
        "url": "https://www.virtualbox.org/wiki/Downloads",
        "nombre": "virtualbox",
        "filtro": "",
        "pattern": r"VirtualBox-([\d.]+)",
        "extension": ".exe",
        "html": ["virtualbox.html", "utilidades.html"],
        "custom_fn": obtener_enlace_virtualbox,
    },
    {
        "url": "http://infrarecorder.org/?page_id=5",
        "nombre": "infrarecorder",
        "filtro": {"href": lambda href: href and re.search(r"ir\d+.*\.exe$", href)},
        "pattern": r"ir(\d+)\.exe",
        "extension": ".exe",
        "html": ["infrarecorder.html", "utilidades.html"],
    },
    {
        "url": "https://sourceforge.net/projects/atunes/files/latest/download",
        "nombre": "atunes",
        "filtro": "",
        "pattern": r"(?i)atunes[-_](\d+\.\d+(?:\.\d+)?)",
        "extension": ".exe",
        "html": ["atunes.html", "multimedia.html"],
    },
    {
        "url": "https://sourceforge.net/projects/scribus/files/latest/download",
        "nombre": "scribus",
        "filtro": "",
        "pattern": r"scribus-([\d.]+)-windows(?:-x64)?\.exe",
        "extension": ".exe",
        "html": ["scribus.html", "oficina.html"],
    },
    {
        "url": "https://www.sumatrapdfreader.org/downloadafter",
        "nombre": "sumatra",
        "filtro": {"href": lambda href: href and href.endswith("-64-install.exe")},
        "pattern": r"SumatraPDF-([\d.]+)-64-install\.exe",
        "extension": ".exe",
        "html": ["sumatra.html", "oficina.html"],
    },
    {
        "url": "https://www.zotero.org/download/client/dl?channel=release&platform=win-x64",
        "nombre": "zotero",
        "filtro": "",
        "pattern": r"Zotero-([\d.]+)_x64_setup\.exe",
        "extension": ".exe",
        "html": ["zotero.html", "utilidades.html"],
    }
]
