# Path: dunyadesktop_app/cultures/dunya/makam.py
# def get_makams():
#     """ Get a list of makam makams in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing makam information::
# 
#         {"uuid": makam uuid,
#          "name": Name of the makam
#         }
# 
#     For additional information about each makam use :func:`get_makam`
# 
#     """
#     return conn._get_paged_json("api/makam/makam")
# 
# def get_forms():
#     """ Get a list of makam forms in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing form information::
# 
#         {"uuid": form uuid,
#          "name": Name of the form
#         }
# 
#     For additional information about each form use :func:`get_form`
# 
#     """
#     return conn._get_paged_json("api/makam/form")
# 
# def get_usuls():
#     """ Get a list of makam usuls in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing usul information::
# 
#         {"uuid": usul uuid,
#          "name": Name of the usul
#         }
# 
#     For additional information about each usul use :func:`get_usul`
# 
#     """
#     return conn._get_paged_json("api/makam/usul")
# 
# def get_composers():
#     """ Get a list of makam composers in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing composers information::
# 
#         {"mbid": Musicbrainz composer id,
#         "name": Name of the composer}
# 
#     For additional information about each composer use :func:`get_composer`
# 
#     """
#     return conn._get_paged_json("api/makam/composer")
# 
# def get_artists():
#     """ Get a list of makam artists in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing artist information::
# 
#         {"mbid": Musicbrainz artist id,
#         "name": Name of the artist}
# 
#     For additional information about each artist use :func:`get_artist`
# 
#     """
#     return conn._get_paged_json("api/makam/artist")
# 
# def get_instruments():
#     """ Get a list of makam instruments in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing instrument information::
# 
#         {"id": instrument id,
#          "name": Name of the instrument
#         }
# 
#     For additional information about each instrument use :func:`get_instrument`
# 
#     """
#     return conn._get_paged_json("api/makam/instrument")
# 
# Path: dunyadesktop_app/cultures/dunya/docserver.py
# def document(recordingid):
#     """Get the available source filetypes for a Musicbrainz recording.
# 
#     :param recordingid: Musicbrainz recording ID
#     :returns: a list of filetypes in the database for this recording
# 
#     """
#     path = "document/by-id/%s" % recordingid
#     recording = conn._dunya_query_json(path)
#     return recording
# 
# def get_document_as_json(recordingid, thetype, subtype=None, part=None, version=None):
#     """ Get a derived filetype and load it as json.
# 
#     :param recordingid: Musicbrainz recording ID
#     :param derivedtype: the computed filetype
#     :param subtype: a subtype if the module has one
#     :param part: the file part if the module has one
#     :param version: a specific version, otherwise the most recent one will be used
# 
#     """
# 
#     doc = file_for_document(recordingid, thetype, subtype, part, version)
#     try:
#         return json.loads(doc)
#     except ValueError:
#         return doc
# 
# def get_mp3(recordingid):
#     return file_for_document(recordingid, "mp3")
# 
# Path: dunyadesktop_app/cultures/dunya/conn.py
# class HTTPError(Exception):
#     pass


import sys
import os
import os.path
import json
import fnmatch
    import urllib
    import urllib.request as urllib
import numpy as np
from ..dunya.makam import (get_makams, get_forms, get_usuls,
                                   get_composers, get_artists, get_instruments)
from ..dunya.docserver import (document, get_document_as_json, get_mp3)
from ..dunya.conn import HTTPError
from PyQt5.QtCore import QObject, QThread, pyqtSignal
            if 'audioanalysis' in features:
                num_f += len(features['audioanalysis'])
                download_list.append('audioanalysis')
            if 'jointanalysis' in features:
                num_f += len(features['jointanalysis'])
                self.download_score(docid)
                download_list.append('jointanalysis')

            count = 0
            for thetype in download_list:
                for subtype in features[thetype]:
                    f_path = os.path.join(doc_folder,
                                          thetype + '--' + subtype + '.json')
                    if not os.path.exists(f_path):
                        try:
                            feature = get_document_as_json(docid, thetype,
                                                           subtype)
                            if feature:
                                json.dump(feature, open(f_path, 'w'))
                        except:
                            pass
                    count += 1
                    self.step_completed.emit(ResultObj(docid, count, num_f))

    def download_score(self, docid):
        SCORE_FOLDER = os.path.join(FOLDER, '..', 'scores')

        if not os.path.exists(SCORE_FOLDER):
            os.makedirs(SCORE_FOLDER)


# Path: dunyadesktop_app/cultures/dunya/makam.py
# def get_makams():
#     """ Get a list of makam makams in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing makam information::
# 
#         {"uuid": makam uuid,
#          "name": Name of the makam
#         }
# 
#     For additional information about each makam use :func:`get_makam`
# 
#     """
#     return conn._get_paged_json("api/makam/makam")
# 
# def get_forms():
#     """ Get a list of makam forms in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing form information::
# 
#         {"uuid": form uuid,
#          "name": Name of the form
#         }
# 
#     For additional information about each form use :func:`get_form`
# 
#     """
#     return conn._get_paged_json("api/makam/form")
# 
# def get_usuls():
#     """ Get a list of makam usuls in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing usul information::
# 
#         {"uuid": usul uuid,
#          "name": Name of the usul
#         }
# 
#     For additional information about each usul use :func:`get_usul`
# 
#     """
#     return conn._get_paged_json("api/makam/usul")
# 
# def get_composers():
#     """ Get a list of makam composers in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing composers information::
# 
#         {"mbid": Musicbrainz composer id,
#         "name": Name of the composer}
# 
#     For additional information about each composer use :func:`get_composer`
# 
#     """
#     return conn._get_paged_json("api/makam/composer")
# 
# def get_artists():
#     """ Get a list of makam artists in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing artist information::
# 
#         {"mbid": Musicbrainz artist id,
#         "name": Name of the artist}
# 
#     For additional information about each artist use :func:`get_artist`
# 
#     """
#     return conn._get_paged_json("api/makam/artist")
# 
# def get_instruments():
#     """ Get a list of makam instruments in the database.
#     This function will automatically page through API results.
# 
#     returns: A list of dictionaries containing instrument information::
# 
#         {"id": instrument id,
#          "name": Name of the instrument
#         }
# 
#     For additional information about each instrument use :func:`get_instrument`
# 
#     """
#     return conn._get_paged_json("api/makam/instrument")
# 
# Path: dunyadesktop_app/cultures/dunya/docserver.py
# def document(recordingid):
#     """Get the available source filetypes for a Musicbrainz recording.
# 
#     :param recordingid: Musicbrainz recording ID
#     :returns: a list of filetypes in the database for this recording
# 
#     """
#     path = "document/by-id/%s" % recordingid
#     recording = conn._dunya_query_json(path)
#     return recording
# 
# def get_document_as_json(recordingid, thetype, subtype=None, part=None, version=None):
#     """ Get a derived filetype and load it as json.
# 
#     :param recordingid: Musicbrainz recording ID
#     :param derivedtype: the computed filetype
#     :param subtype: a subtype if the module has one
#     :param part: the file part if the module has one
#     :param version: a specific version, otherwise the most recent one will be used
# 
#     """
# 
#     doc = file_for_document(recordingid, thetype, subtype, part, version)
#     try:
#         return json.loads(doc)
#     except ValueError:
#         return doc
# 
# def get_mp3(recordingid):
#     return file_for_document(recordingid, "mp3")
# 
# Path: dunyadesktop_app/cultures/dunya/conn.py
# class HTTPError(Exception):
#     pass


# Path: dunyadesktop_app/cultures/makam/utilities.py
import sys
import os
import os.path
import json
import fnmatch
    import urllib
    import urllib.request as urllib
import numpy as np
from ..dunya.makam import (get_makams, get_forms, get_usuls,
                                   get_composers, get_artists, get_instruments)
from ..dunya.docserver import (document, get_document_as_json, get_mp3)
from ..dunya.conn import HTTPError
from PyQt5.QtCore import QObject, QThread, pyqtSignal

            if 'audioanalysis' in features:
                num_f += len(features['audioanalysis'])
                download_list.append('audioanalysis')
            if 'jointanalysis' in features:
                num_f += len(features['jointanalysis'])
                self.download_score(docid)
                download_list.append('jointanalysis')

            count = 0
            for thetype in download_list:
                for subtype in features[thetype]:
                    f_path = os.path.join(doc_folder,
                                          thetype + '--' + subtype + '.json')
                    if not os.path.exists(f_path):
                        try:
                            feature = get_document_as_json(docid, thetype,
                                                           subtype)
                            if feature:
                                json.dump(feature, open(f_path, 'w'))
                        except:
                            pass
                    count += 1
                    self.step_completed.emit(ResultObj(docid, count, num_f))

    def download_score(self, docid):
        SCORE_FOLDER = os.path.join(FOLDER, '..', 'scores')

        if not os.path.exists(SCORE_FOLDER):
            os.makedirs(SCORE_FOLDER)


        works = get_document_as_json(docid, 'audioanalysis',