Beispiel #1
0
def identify_dvd(job):
    """ Calculates CRC64 for the DVD and calls Windows Media
        Metaservices and returns the Title and year of DVD """
    logging.debug(str(job))

    try:
        crc64 = pydvdid.compute(str(job.mountpoint))
    except pydvdid.exceptions.PydvdidException as e:
        logging.error("Pydvdid failed with the error: " + str(e))
        return False

    logging.info("DVD CRC64 hash is: " + str(crc64))
    job.crc_id = str(crc64)
    urlstring = "http://metaservices.windowsmedia.com/pas_dvd_B/template/GetMDRDVDByCRC.xml?CRC={0}".format(
        str(crc64))
    logging.debug(urlstring)

    try:
        dvd_info_xml = urllib.request.urlopen(
            "http://metaservices.windowsmedia.com/pas_dvd_B/template/GetMDRDVDByCRC.xml?CRC={0}"
            .format(crc64)).read()
    except OSError as e:
        dvd_info_xml = False
        dvd_title = "not_identified"
        dvd_release_date = "0000"
        logging.error(
            "Failed to reach windowsmedia web service.  Error number is: " +
            str(e.errno))
        # return False

    try:
        if not dvd_info_xml:
            pass
        else:
            doc = xmltodict.parse(dvd_info_xml)
            dvd_title = doc['METADATA']['MDR-DVD']['dvdTitle']
            dvd_release_date = doc['METADATA']['MDR-DVD']['releaseDate']
            dvd_title = dvd_title.strip()
            dvd_title = clean_for_filename(dvd_title)
            if dvd_release_date is not None:
                dvd_release_date = dvd_release_date.split()[0]
            else:
                dvd_release_date = ""
    except KeyError:
        dvd_title = "not_identified"
        dvd_release_date = "0000"
        logging.error(
            "Windows Media request returned no result.  Likely the DVD is not in their database."
        )
        # return False

    job.title = job.title_auto = dvd_title
    job.year = job.year_auto = dvd_release_date
    db.session.commit()

    return True
def identify_dvd(job):
    """ Manipulates the DVD title and calls OMDB to try and 	
    lookup the title """

    logging.debug("\n\r" + job.pretty_table())
    # Added from #338
    # Some older DVDs aren't actually labelled
    if not job.label or job.label == "":
        job.label = "not identified"

    dvd_info_xml = False
    dvd_release_date = ""

    # TODO: remove this because its pointless keeping when it can never work
    try:
        crc64 = pydvdid.compute(str(job.mountpoint))
        fallback_title = "{0}_{1}".format(str(job.label), str(crc64))
        dvd_title = str(fallback_title)
        logging.info("DVD CRC64 hash is: " + str(crc64))
        job.crc_id = str(crc64)
        # Dead needs removing
        urlstring = "http://metaservices.windowsmedia.com/pas_dvd_B/template/GetMDRDVDByCRC.xml?CRC={0}".format(
            str(crc64))
        logging.debug(urlstring)
    except pydvdid.exceptions.PydvdidException as e:
        logging.error("Pydvdid failed with the error: " + str(e))
        dvd_title = fallback_title = str(job.label)

    dvd_title = job.label
    logging.debug("dvd_title_label= " + str(dvd_title))
    # strip all non-numeric chars and use that for year
    year = re.sub("[^0-9]", "", str(job.year))
    # next line is not really needed, but we dont want to leave an x somewhere
    dvd_title = job.label.replace("16x9", "")
    # Rip out any not alpha chars replace with
    dvd_title = re.sub("[^a-zA-Z ]", " ", dvd_title)
    logging.debug("dvd_title ^a-z= " + str(dvd_title))
    # rip out any SKU's at the end of the line
    dvd_title = re.sub("SKU$", "", dvd_title)
    logging.debug("dvd_title SKU$= " + str(dvd_title))

    # try to contact omdb
    try:
        dvd_info_xml = callwebservice(job, job.config.OMDB_API_KEY, dvd_title,
                                      year)
        logging.debug("DVD_INFO_XML: " + str(dvd_info_xml))
    except OSError as e:
        # we couldn't reach OMdb
        logging.error("Failed to reach OMdb")
        return False
    # Not sure this is needed anymore because of CWS()
    job.year = year
    job.title = dvd_title
    db.session.commit()
    return True
def getdvdtitle():
    """ Calculates CRC64 for the DVD and calls Windows Media
        Metaservices and returns the Title and year of DVD """
    crc64 = pydvdid.compute(args.path)
    # print (crc64)
    dvd_info_xml = urllib.request.urlopen(
        "http://metaservices.windowsmedia.com/pas_dvd_B/template/GetMDRDVDByCRC.xml?CRC={0}".
        format(crc64)).read()

    doc = xmltodict.parse(dvd_info_xml)
    dvd_title = doc['METADATA']['MDR-DVD']['dvdTitle']
    dvd_release_date = doc['METADATA']['MDR-DVD']['releaseDate']

    # title + release year
    return dvd_title + " (" + dvd_release_date.split()[0] + ")"
Beispiel #4
0
def getdvdtitle():
    """ Calculates CRC64 for the DVD and calls Windows Media
        Metaservices and returns the Title and year of DVD """
    crc64 = pydvdid.compute(args.path)
    # print (crc64)
    dvd_info_xml = urllib.request.urlopen(
        "http://metaservices.windowsmedia.com/pas_dvd_B/template/GetMDRDVDByCRC.xml?CRC={0}"
        .format(crc64)).read()

    doc = xmltodict.parse(dvd_info_xml)
    dvd_title = doc['METADATA']['MDR-DVD']['dvdTitle']
    dvd_release_date = doc['METADATA']['MDR-DVD']['releaseDate']

    # title + release year
    return dvd_title + " (" + dvd_release_date.split()[0] + ")"
Beispiel #5
0
def identify_dvd(job):
    """ Calculates CRC64 for the DVD and calls Windows Media
        Metaservices and returns the Title and year of DVD """
    """ Manipulates the DVD title and calls OMDB to try and 
        lookup the title """
    logging.debug(str(job))

    try:
        crc64 = pydvdid.compute(str(job.mountpoint))
    except pydvdid.exceptions.PydvdidException as e:
        logging.error("Pydvdid failed with the error: " + str(e))
        return False

    logging.info("DVD CRC64 hash is: " + str(crc64))
    job.crc_id = str(crc64)
    fallback_title = "{0}_{1}".format(str(job.label), str(crc64))
    logging.info("Fallback title is: " + str(fallback_title))
    urlstring = "http://metaservices.windowsmedia.com/pas_dvd_B/template/GetMDRDVDByCRC.xml?CRC={0}".format(
        str(crc64))
    logging.debug(urlstring)

    try:
        dvd_info_xml = urllib.request.urlopen(urlstring).read()
    except OSError as e:
        dvd_info_xml = False
        dvd_title = str(fallback_title)
        dvd_release_date = ""
        logging.error(
            "Failed to reach windowsmedia web service.  Error number is: " +
            str(e.errno))
        # return False

    # Some older DVDs aren't actually labelled
    if not job.label:
        job.label = "not identified"

    try:
        if not dvd_info_xml:
            pass
        else:
            doc = xmltodict.parse(dvd_info_xml)
            dvd_title = doc['METADATA']['MDR-DVD']['dvdTitle']
            dvd_release_date = doc['METADATA']['MDR-DVD']['releaseDate']
            dvd_title = dvd_title.strip()
            dvd_title = clean_for_filename(dvd_title)
            if dvd_release_date is not None:
                dvd_release_date = dvd_release_date.split()[0]
            else:
                dvd_release_date = ""
    except KeyError:
        dvd_title = str(fallback_title)
        dvd_release_date = ""
        logging.error(
            "Windows Media request returned no result.Probably because the service is discontinued."
        )
        # return False

    # TODO: split this out to another file/function and loop depending how many replacements
    # need to be done
    dvd_title = job.label.replace("_", " ").replace("16x9", "")
    dvd_release_date = ""

    job.title = job.title_auto = dvd_title
    job.year = job.year_auto = dvd_release_date
    db.session.commit()

    return True
def identify_dvd(job):
    """ Manipulates the DVD title and calls OMDB to try and 	
    lookup the title """

    logging.debug("\n\r" + job.pretty_table())
    # Added from #338
    # Some older DVDs aren't actually labelled
    if not job.label or job.label == "":
        job.label = "not identified"

    dvd_info_xml = False
    dvd_release_date = ""
    try:
        crc64 = pydvdid.compute(str(job.mountpoint))
        fallback_title = f"{job.label}_{crc64}"
        dvd_title = fallback_title
        logging.info("DVD CRC64 hash is: " + str(crc64))
        job.crc_id = str(crc64)
        urlstring = f"http://1337server.pythonanywhere.com/api/v1/?mode=s&crc64={crc64}"
        logging.debug(urlstring)
        dvd_info_xml = urllib.request.urlopen(urlstring).read()
        x = json.loads(dvd_info_xml)
        logging.debug("dvd xml - " + str(x))
        logging.debug(f"results = {x['results']}")
        if bool(x['success']):
            job.title = x['results']['0']['title']
            job.year = x['results']['0']['year']
            job.imdb_id = x['results']['0']['imdb_id']
            job.video_type = x['results']['0']['video_type']
            db.session.commit()
            return True
    except pydvdid.exceptions.PydvdidException as e:
        logging.error("Pydvdid failed with the error: " + str(e))
        dvd_title = fallback_title = str(job.label)
    # TODO: make use of dvd_info_xml again if found

    logging.debug("dvd_title_label= " + str(dvd_title))
    # strip all non-numeric chars and use that for year
    year = re.sub(r"[^0-9]", "", str(job.year))
    # next line is not really needed, but we dont want to leave an x somewhere
    dvd_title = job.label.replace("16x9", "")
    # Rip out any not alpha chars replace with
    dvd_title = re.sub(r"[^a-zA-Z ]", " ", dvd_title)
    logging.debug("dvd_title ^a-z= " + str(dvd_title))
    # rip out any SKU's at the end of the line
    dvd_title = re.sub(r"SKU\b", "", dvd_title)
    logging.debug("dvd_title SKU$= " + str(dvd_title))

    # try to contact omdb/tmdb
    from arm.config.config import cfg
    if cfg['METADATA_PROVIDER'].lower() == "tmdb":
        logging.debug("using tmdb")
        tmdb_api_key = cfg['TMDB_API_KEY']
        dvd_info_xml = call_tmdb_service(job, tmdb_api_key, dvd_title, year)
    elif cfg['METADATA_PROVIDER'].lower() == "omdb":
        logging.debug("using omdb")
        dvd_info_xml = callwebservice(job, job.config.OMDB_API_KEY, dvd_title,
                                      year)
    else:
        raise InputError("Error with metadata provider - Not supported")
    logging.debug("DVD_INFO_XML: " + str(dvd_info_xml))
    # Not sure this is needed anymore because of CWS()
    job.year = year
    job.title = dvd_title
    db.session.commit()
    return True