<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<items>
    <items_info> <!-- this is opitonal -->
      <title>Testing XML</title> <!-- a title is required, other elements are optional -->
      <genre>News</genre>
      <description>this is the descripton string</description>
      <thumbnail>http://community-links.googlecode.com/svn/icons/news-icon.png</thumbnail>
      <fanart>http://community-links.googlecode.com/svn/icons/news-fanart.jpg</fanart>
      <date>04.01.2013</date>
      <credits>divingmule, Johnny Cache</credits>
    </items_info>




<item>
<title>***  updated   $doregex[info]  *** </title>
<link>$doregex[refresh]</link>
<regex>
<name>refresh</name>
<expres><![CDATA[#$pyFunction
def GetLSProData(page_data,Cookie_Jar,m):
 import xbmc 
 import xbmcgui 
 from datetime import datetime, timezone, timedelta
 xbmc.executebuiltin('Container.Refresh')
]]></expres>
<page></page>
</regex>
<regex>
<name>info</name>
<expres>$pyFunction: time.strftime('%d/%m/%Y')</expres>
<page></page>
<NOTPlayable>True</NOTPlayable>
</regex>
</item>


<item>
<title> </title>
<thumbnail> </thumbnail>
<link>ignoreme</link>
</item>







<item>
<title>Greek Movies</title>
<link>$doregex[makelist0]</link>
<thumbnail></thumbnail>

<!-- 1. SELECT YEAR -->
<regex>
<name>makelist0</name>
<listrepeat><![CDATA[
<title>[makelist0.param1]</title>
<link>$doregex[makelist]</link>
<thumbnail></thumbnail>
]]></listrepeat>
<expres><![CDATA[<option value="(\d{4})" >(\d{4})</option>]]></expres>
<page>https://greeksubsmovies.me/?filter=movie&amp;sort=recent&amp;f_language=en&amp;page=1</page>
<agent>Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36</agent>
<cookieJar></cookieJar>
</regex>

<!-- 2. MOVIE LIST (MERGES PAGE 1 & PAGE 2 IN PYTHON 3) -->
<regex>
<name>makelist</name>
<listrepeat><![CDATA[
<title>[makelist.param3]</title>
<link>$doregex[play_movie_dialog]</link>
<thumbnail>[makelist.param2]</thumbnail>
<meta>video</meta>
]]></listrepeat>
<expres><![CDATA[#$pyFunction
import urllib.request
import re

def GetLSProData(page_data, Cookie_Jar, m):
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36'}
    year = "[makelist0.param2]"
    pattern = r'<a class="card" href="([^"]+)">\s*<img src="([^"]+)"[^>]*>\s*<div class="card-meta">\s*<div class="card-title">([^<]+)<'
    
    all_movies = []
    
    for page_num in [1, 2]:
        url = "https://greeksubsmovies.me/?filter=greek_movies&sort=recent&f_year=%s&f_language=el&page=%s" % (year, page_num)
        try:
            req = urllib.request.Request(url, headers=headers)
            with urllib.request.urlopen(req, timeout=8) as resp:
                html = resp.read().decode('utf-8', errors='ignore')
            matches = re.findall(pattern, html)
            if matches:
                all_movies.extend(matches)
        except:
            pass
            
    return all_movies
]]></expres>
<page></page>
<agent>Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36</agent>
<cookieJar></cookieJar>
</regex>

<!-- 3. DIALOG SOURCE SELECTION & PLAYBACK (PYTHON 3) -->
<regex>
<name>play_movie_dialog</name>
<expres><![CDATA[#$pyFunction
def GetLSProData(page_data, Cookie_Jar, m):
    import urllib.request
    import re
    import xbmcgui
    
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36'}
    base = "https://greeksubsmovies.me"
    
    try:
        # Extract sources from movie page HTML (passed via <page>)
        links = re.findall(r'<a class="btn" href="(.*?)"', page_data)
        if not links:
            xbmcgui.Dialog().notification('Notice', 'No sources found', xbmcgui.NOTIFICATION_INFO, 3000)
            return ""
            
        # Kodi GUI selection dialog
        labels = [f"Play Source {i + 1}" for i in range(len(links))]
        dialog = xbmcgui.Dialog()
        selected = dialog.select("Select Source", labels)
        
        if selected == -1:
            return "" # User canceled
            
        # Fetch player page and extract tokens
        player_url = base + links[selected]
        req_player = urllib.request.Request(player_url, headers=headers)
        with urllib.request.urlopen(req_player, timeout=10) as p_resp:
            p_html = p_resp.read().decode('utf-8', errors='ignore')
        
        tok = re.search(r'const _tok = "(.*?)"', p_html)
        vid = re.search(r'const _vid = (.*?);', p_html)
        if not tok or not vid:
            return ""
            
        # Request stream from API
        api_url = f"{base}/api/video-src.php?t={tok.group(1)}&v={vid.group(1)}"
        api_headers = dict(headers)
        api_headers['Referer'] = player_url
        
        req_api = urllib.request.Request(api_url, headers=api_headers)
        with urllib.request.urlopen(req_api, timeout=10) as res_api:
            res = res_api.read().decode('utf-8', errors='ignore')
        
        stream = re.search(r'"(http.*?)"', res)
        if stream:
            return stream.group(1).replace('\\/', '/') + '|User-Agent=' + headers['User-Agent']
            
    except Exception as e:
        xbmcgui.Dialog().notification('Error', str(e), xbmcgui.NOTIFICATION_INFO, 3000)
        
    return ""
]]></expres>
<page>https://greeksubsmovies.me[makelist.param1]</page>
<agent>Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36</agent>
<cookieJar>greekjar</cookieJar>
</regex>

</item>



<item>
<title>Greek Movies Youtube  </title>
<link>ignorme</link>
<jsonrpc>plugin://plugin.video.youtube/kodion/search/query/?q=Greek%20Movies</jsonrpc>
<thumbnail>https://pbs.twimg.com/profile_images/1368540629/GreekTV_logo.png</thumbnail>
</item>


<item1>
<title>Greek Movies Test 01</title>
<link>$doregex[makelist0]</link>
<thumbnail></thumbnail>

<!-- 1. SELECT YEAR -->
<regex>
<name>makelist0</name>
<listrepeat><![CDATA[
<title>[makelist0.param1]</title>
<link>$doregex[makelist]</link>
<thumbnail></thumbnail>
]]></listrepeat>
<expres><![CDATA[<option value="(\d{4})" >(\d{4})</option>]]></expres>
<page>https://greeksubsmovies.net/?filter=movie&amp;sort=recent&amp;f_language=en&amp;page=1</page>
<agent>Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36</agent>
<cookieJar></cookieJar>
</regex>

<!-- 2. MOVIE LIST (DYNAMIC PAGINATION PARSER IN PYTHON 3) -->
<regex>
<name>makelist</name>
<listrepeat><![CDATA[
<title>[makelist.param3]</title>
<link>$doregex[play_movie_dialog]</link>
<thumbnail>[makelist.param2]</thumbnail>
<meta>video</meta>
]]></listrepeat>
<expres><![CDATA[#$pyFunction
import urllib.request
import re

def GetLSProData(page_data, Cookie_Jar, m):
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36'}
    year = "[makelist0.param2]"
    pattern = r'<a class="card" href="([^"]+)">\s*<img src="([^"]+)"[^>]*>\s*<div class="card-meta">\s*<div class="card-title">([^<]+)<'
    
    all_movies = []
    max_pages = 1
    
    try:
        # 1. Fetch Page 1 to inspect pagination container
        first_url = "https://greeksubsmovies.net/?filter=greek_movies&sort=recent&f_year=%s&f_language=el&page=1" % year
        req = urllib.request.Request(first_url, headers=headers)
        with urllib.request.urlopen(req, timeout=8) as resp:
            html = resp.read().decode('utf-8', errors='ignore')
            
        # Extract movies from page 1
        matches = re.findall(pattern, html)
        if matches:
            all_movies.extend(matches)
            
        # 2. Parse pagination block to find the total page count dynamically
        pager_match = re.search(r'<nav class="pager"[^>]*>(.*?)</nav>', html, re.DOTALL)
        if pager_match:
            pager_html = pager_match.group(1)
            # Find all page numbers inside the pager links/spans
            page_numbers = re.findall(r'>(\d+)<', pager_html)
            if page_numbers:
                max_pages = int(page_numbers[-1])
                
        # 3. Loop through remaining pages if more than 1 page exists
        for page_num in range(2, max_pages + 1):
            url = "https://greeksubsmovies.net/?filter=greek_movies&sort=recent&f_year=%s&f_language=el&page=%s" % (year, page_num)
            try:
                req = urllib.request.Request(url, headers=headers)
                with urllib.request.urlopen(req, timeout=8) as resp:
                    html = resp.read().decode('utf-8', errors='ignore')
                matches = re.findall(pattern, html)
                if matches:
                    all_movies.extend(matches)
            except Exception:
                pass
    except Exception:
        pass
        
    return all_movies
]]></expres>
<page></page>
<agent>Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36</agent>
<cookieJar></cookieJar>
</regex>

<!-- 3. DIALOG SOURCE SELECTION & PLAYBACK (PYTHON 3) -->
<regex>
<name>play_movie_dialog</name>
<expres><![CDATA[#$pyFunction
def GetLSProData(page_data, Cookie_Jar, m):
    import urllib.request
    import re
    import xbmcgui
    
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36'}
    base = "https://greeksubsmovies.net"
    
    try:
        # Extract sources from movie page HTML (passed via <page>)
        links = re.findall(r'<a class="btn" href="(.*?)"', page_data)
        if not links:
            xbmcgui.Dialog().notification('Notice', 'No sources found', xbmcgui.NOTIFICATION_INFO, 3000)
            return ""
            
        # Kodi GUI selection dialog
        labels = [f"Play Source {i + 1}" for i in range(len(links))]
        dialog = xbmcgui.Dialog()
        selected = dialog.select("Select Source", labels)
        
        if selected == -1:
            return "" # User canceled
            
        # Fetch player page and extract tokens
        player_url = base + links[selected]
        req_player = urllib.request.Request(player_url, headers=headers)
        with urllib.request.urlopen(req_player, timeout=10) as p_resp:
            p_html = p_resp.read().decode('utf-8', errors='ignore')
        
        tok = re.search(r'const _tok = "(.*?)"', p_html)
        vid = re.search(r'const _vid = (.*?);', p_html)
        if not tok or not vid:
            return ""
            
        # Request stream from API
        api_url = f"{base}/api/video-src.php?t={tok.group(1)}&v={vid.group(1)}"
        api_headers = dict(headers)
        api_headers['Referer'] = player_url
        
        req_api = urllib.request.Request(api_url, headers=api_headers)
        with urllib.request.urlopen(req_api, timeout=10) as res_api:
            res = res_api.read().decode('utf-8', errors='ignore')
        
        stream = re.search(r'"(http.*?)"', res)
        if stream:
            return stream.group(1).replace('\\/', '/') + '|User-Agent=' + headers['User-Agent']
            
    except Exception as e:
        xbmcgui.Dialog().notification('Error', str(e), xbmcgui.NOTIFICATION_INFO, 3000)
        
    return ""
]]></expres>
<page>https://greeksubsmovies.net[makelist.param1]</page>
<agent>Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/143.0.0.0 Safari/537.36</agent>
<cookieJar>greekjar</cookieJar>
</regex>

</item1>



















</items>