[Python] Python code to get direct download file link from mediafire?

Discussão em 'Python' iniciado por Stack, Julho 30, 2025.

  1. Stack

    Stack Membro Participativo

    I have update my codes to download files from mediafire like https://app.mediafire.com/folder/cdmen9tqtpwxk

    if self.teamName=="BlackHole":
    if boxtype == "dm920":
    key = 'cdmen9tqtpwxk'
    elif boxtype == "dm520":
    key = 'gkhsdcxiikosk'
    elif boxtype == "dm7080":
    key = '5cmni3i0rch9e'
    elif boxtype == "dm820":
    key = '60ptu82mgakx6'
    else:
    return []
    imagesPath='https://www.mediafire.com/api/1.4/folder/get_content.php?r=cfgd&content_type=files&filter=all&order_by=name&order_direction=asc&chunk=1&version=1.5&folder_key=%s&response_format=json' % key
    rimages=get_images_mediafire(imagesPath)
    for item in rimages:
    imageName=item[0]
    imagePath=item[1]
    images.append((imageName,imagePath))


    https://github.com/fairbird/BackUpF...s/backupflashe/tools/flashonline.py#L194-L210

    this is file to import code for python 2 and 3

    https://github.com/fairbird/BackUpF...ugins/Extensions/backupflashe/tools/compat.py

    # Source code from (https://github.com/Taapat/enigma2-plugin-youtube/blob/master/src/compat.py)
    from sys import version_info
    from threading import Thread

    PY3 = version_info[0] == 3

    # Disable certificate verification on python 2.7.9
    if version_info >= (2, 7, 9):
    import ssl
    ssl._create_default_https_context = ssl._create_unverified_context


    if version_info[0] == 2:
    # Python 2
    compat_str, compat_basestring, compat_chr = (unicode, basestring, unichr)
    compat_integer_types = (int, long)
    compat_numeric_types = (int, float, long, complex)

    from re import compile
    from urllib import _hextochr

    from itertools import izip_longest as compat_zip_longest
    from urllib import urlencode as compat_urlencode
    from urllib import quote as compat_quote
    from urllib import urlretrieve as compat_urlretrieve
    from urllib2 import urlopen
    from urllib2 import Request as compat_Request
    from urllib2 import HTTPError as compat_HTTPError
    from urllib2 import URLError as compat_URLError
    from urlparse import urljoin as compat_urljoin
    from urlparse import urlparse as compat_urlparse
    from urlparse import urlunparse as compat_urlunparse
    from httplib import HTTPException as compat_HTTPException


    def _unquote_to_bytes(string):
    if not string:
    return b''
    if isinstance(string, unicode):
    string = string.encode('utf-8')
    bits = string.split(b'%')
    if len(bits) == 1:
    return string
    res = [bits[0]]
    for item in bits[1:]:
    try:
    res.append(_hextochr[item[:2]])
    res.append(item[2:])
    except KeyError:
    res.append(b'%')
    res.append(item)
    return b''.join(res)

    def _unquote(string):
    if '%' not in string:
    string.split
    return string
    bits = compile(r'([\x00-\x7f]+)').split(string)
    res = [bits[0]]
    for i in range(1, len(bits), 2):
    res.append(_unquote_to_bytes(bits).decode('utf-8', 'replace'))
    res.append(bits[i + 1])
    return ''.join(res)

    def _parse_qsl(qs):
    pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
    r = []
    for name_value in pairs:
    if not name_value:
    continue
    nv = name_value.split('=', 1)
    if len(nv) == 2 and len(nv[1]):
    name = unicode(_unquote(nv[0].replace('+', ' ')))
    value = unicode(_unquote(nv[1].replace('+', ' ')))
    r.append((name, value))
    return r

    def compat_parse_qs(qs):
    """
    Correct parse_qs implementation from cpython 3's stdlib.
    Python 2's version is apparently totally broken.
    """
    parsed_result = {}
    pairs = _parse_qsl(qs)
    for name, value in pairs:
    if name in parsed_result:
    parsed_result[name].append(value)
    else:
    parsed_result[name] = [value]
    return parsed_result

    else:
    # Python 3
    compat_str, compat_basestring, compat_chr = (str, (str, bytes), chr)
    compat_integer_types = (int, )
    compat_numeric_types = (int, float, complex)

    from itertools import zip_longest as compat_zip_longest
    from urllib.parse import urlencode as compat_urlencode
    from urllib.parse import quote as compat_quote
    from urllib.request import urlretrieve as compat_urlretrieve
    from urllib.request import urlopen
    from urllib.request import Request as compat_Request
    from urllib.error import HTTPError as compat_HTTPError
    from urllib.error import URLError as compat_URLError
    from urllib.parse import urljoin as compat_urljoin
    from urllib.parse import urlparse as compat_urlparse
    from urllib.parse import parse_qs as compat_parse_qs
    from urllib.parse import urlunparse as compat_urlunparse
    from http.client import HTTPException as compat_HTTPException

    if version_info >= (3, 4):
    from collections import ChainMap as compat_chain_map
    else:
    from collections import MutableMapping

    class compat_chain_map(MutableMapping):
    def __init__(self, *maps):
    self.maps = list(maps) or [{}]

    def __getitem__(self, k):
    for m in self.maps:
    if k in m:
    return m[k]
    raise KeyError(k)

    def __contains__(self, k):
    return any((k in m) for m in self.maps)

    def __delitem__(self, k):
    raise NotImplementedError('Deleting is not supported')

    def __iter__(self):
    d = {}
    for m in reversed(self.maps):
    d.update(dict.fromkeys(m))
    return iter(d)

    def __len__(self):
    return len(set().union(*self.maps))

    def new_child(self, m=None, **kwargs):
    m = m or {}
    m.update(kwargs)
    return self.__class__(m, *self.maps)


    try:
    from future_builtins import map as compat_map
    except ImportError:
    try:
    from itertools import imap as compat_map
    except ImportError:
    compat_map = map


    compat_int = compat_integer_types[-1]

    SUBURI = '&suburi='


    def compat_urlopen(url, timeout=5):
    """
    Urlopen in thread to enforce a timeout on the function call.
    Timeout in urlopen only affects how long Python waits before
    an exception is raised if the server has not issued a response.
    It does not enforce a time limit on the entire function call.
    """
    compat_urlopen.response = None
    compat_urlopen.error = None

    def open_url(url, timeout):
    try:
    compat_urlopen.response = urlopen(url, timeout=timeout)
    except Exception as e:
    compat_urlopen.error = e

    t = Thread(target=open_url, args=(url, timeout))
    t.setDaemon(True)
    t.start()
    t.join(timeout + 1)
    if compat_urlopen.error:
    raise compat_urlopen.error
    return compat_urlopen.response


    Before some weeks my enigma2 plugin work just fine. But before some days I think mediafire team changed some things So I have update my code. The problem is now the direct link to download image (image link) what I have got not correct. It is web page link not direct download link for file

    The values what I have got is :

    IMAGENAME : OpenTSimage-10.0-20241018-dm920_web-Py3.zip
    IMAGEPATH : /media/hdd/backup/OpenTSimage-10.0-20241018-dm920_web-Py3.zip
    image link : https://www.mediafire.com/file/u87j3awe1dxxavt/OpenTSimage-10.0-20241018-dm920_web-Py3.zip/file


    So I need to update/fix get_images_mediafire function to get correct direct download link for files ?! https://github.com/fairbird/BackUpF...sions/backupflashe/tools/bftools.py#L184-L217

    def get_images_mediafire(url):
    images = []
    logdata("images_url", url)

    def readnet(url):
    try:
    req = compat_Request(url, headers=headers) # Add headers to fix HTTP Error 403: Forbidden
    response = compat_urlopen(req, timeout=10)
    data = response.read()
    if PY3:
    data = data.decode('utf-8') # Python 3: decode bytes to str
    else:
    data = data.encode('utf-8') # Python 2: keep as bytes (str)
    return data
    except:
    trace_error()
    return None

    data = readnet(url)
    if data is None:
    return []

    jdata = json.loads(data)
    files_list = jdata['response']['folder_content']['files']

    for item in files_list:
    direct_download_link = item['links']['normal_download']
    file_name = item['filename']
    # Ensure file_name is a byte string (str) in Python 2
    if not PY3 and isinstance(file_name, unicode): # Python 2: convert unicode to str
    file_name = file_name.encode('utf-8')
    images.append((file_name, direct_download_link))

    return images


    update python files ...

    Continue reading...

Compartilhe esta Página