예제 #1
0
def absolute_listdir( path, media_type = "files", recursive = False, contains = "" ):
    absolute_files = []
    absolute_folders = []
    path = utils.smart_unicode( path )
    folders, files = xbmcvfs.listdir( path )
    for f in files:
        f = utils.smart_unicode( f )
        if media_type == "files":
            if not contains or ( contains and ( contains in f ) ):
                try:
                    absolute_files.append( os.path.join( path, f ).replace("\\\\","\\") )
                except UnicodeError:
                    utils.log( "Problem with path, skipping" )
                    utils.log( "Path: %s" % repr( path ) )
                    utils.log( "Filename: %s" % repr( path ) )
                except:
                    utils.log( "Problem with path, skipping" )
                    traceback.print_exc()
        else:
            if ( ( os.path.splitext( f )[ 1 ] ).lower() ).replace( ".", "" ) in ( xbmc.getSupportedMedia( media_type ) ).lower():
                if not contains or ( contains and ( contains in f ) ):
                    absolute_files.append( os.path.join( path, f ).replace("\\\\","\\") )
    if folders:
        absolute_folders = absolute_folder_paths( folders, path )
        if recursive:
            for folder in absolute_folders:
                absolute_files.extend( absolute_listdir( folder, media_type = media_type, recursive = recursive, contains = contains ) )
    return absolute_files
예제 #2
0
def absolute_listdir( path, media_type = "files", recursive = False, contains = "" ):
    absolute_files = []
    absolute_folders = []
    path = utils.smart_unicode( path )
    folders, files = xbmcvfs.listdir( path )
    for f in files:
        f = utils.smart_unicode( f )
        if media_type == "files":
            if not contains or ( contains and ( contains in f ) ):
                try:
                    absolute_files.append( os.path.join( path, f ).replace("\\\\","\\") )
                except UnicodeError:
                    utils.log( "Problem with path, skipping" )
                    utils.log( "Path: %s" % repr( path ) )
                    utils.log( "Filename: %s" % repr( path ) )
                except:
                    utils.log( "Problem with path, skipping" )
                    traceback.print_exc()
        else:
            if ( os.path.splitext( f )[ 1 ] ).lower() in ( xbmc.getSupportedMedia( media_type ) ).lower():
                if not contains or ( contains and ( contains in f ) ):
                    absolute_files.append( os.path.join( path, f ).replace("\\\\","\\") )
    if folders:
        absolute_folders = absolute_folder_paths( folders, path )
        if recursive:
            for folder in absolute_folders:
                absolute_files.extend( absolute_listdir( folder, media_type = media_type, recursive = recursive, contains = contains ) )
    return absolute_files
예제 #3
0
def absolute_folder_paths( folders, root_path ):
    actual_folders = []
    root_path = utils.smart_unicode( root_path )
    for folder in folders:
        folder = utils.smart_unicode( folder )
        try:
            actual_folders.append( os.path.join( root_path, folder ).replace("\\\\","\\") )
        except UnicodeError:
            utils.log( "Problem with path, skipping" )
            utils.log( "Path: %s" % repr( root_path ) )
            utils.log( "Folder: %s" % repr( folder ) )
        except:
            utils.log( "Problem with path, skipping" )
            traceback.print_exc()
    return actual_folders
예제 #4
0
    def remove(self, path):
        """
        Remove a file.

        Raises OSError on error.
        """
        path = self.abspath(path)
        logging.debug("remove %r" % path)
        logging.info("remove %r" % path)
        container, name = parse_fspath(path)

        if not name:
            raise IOSError(EACCES, "Can't remove a container")

        if self.isdir(path):
            raise IOSError(EACCES,
                           "Can't remove a directory (use rmdir instead)")

        meta = self.conn.head_object(container, name)
        if 'x-object-manifest' in meta:
            self._remove_path_folder_files(
                u'/' +
                smart_unicode(unquote(meta['x-object-manifest']), "utf-8"))
        self.conn.delete_object(container, name)
        self._listdir_cache.flush(posixpath.dirname(path))
        return not name
예제 #5
0
def absolute_folder_paths( folders, root_path ):
    actual_folders = []
    root_path = utils.smart_unicode( root_path )
    for folder in folders:
        folder = utils.smart_unicode( folder )
        try:
            actual_folders.append( os.path.join( root_path, folder ).replace("\\\\","\\") )
        except UnicodeError:
            utils.log( "Problem with path, skipping" )
            utils.log( "Path: %s" % repr( root_path ) )
            utils.log( "Folder: %s" % repr( folder ) )
        except:
            utils.log( "Problem with path, skipping" )
            traceback.print_exc()
    return actual_folders
        
예제 #6
0
def get_musicbrainz_artist_id(artist_search, limit=1, alias=False):
    name = ""
    id = ""
    sortname = ""
    artist_name = smart_unicode(
        (artist_search.replace('"', '?').replace('&', 'and')))
    if not alias:
        url = artist_url % (server, quote_plus(
            artist_name.encode("utf-8")), limit)
    else:
        url = alias_url % (server, quote_plus(
            artist_name.encode("utf-8")), limit)
    htmlsource = get_html_source(url, "", save_file=False)
    match = re.search('''<artist(.*?)</artist>''', htmlsource)
    if match:
        score_match = re.search('''score="(.*?)"''', htmlsource)
        name_match = re.search('''<name>(.*?)</name>''', htmlsource)
        id_match = re.search('''<artist id="(.*?)"(?:.*?)>''', htmlsource)
        if not id_match:
            id_match = re.search('''<artist (?:.*?)id="(.*?)">''', htmlsource)
        sort_name_match = re.search('''<sort-name>(.*?)</sort-name>''',
                                    htmlsource)

        if score_match:
            score = score_match.group(1)
        if name_match:
            name = unescape(smart_unicode(name_match.group(1)))
        if id_match:
            id = id_match.group(1)
        if sort_name_match:
            sortname = unescape(smart_unicode(sort_name_match.group(1)))
        log("Score     : %s" % score, xbmc.LOGDEBUG)
        log("Id        : %s" % id, xbmc.LOGDEBUG)
        log("Name      : %s" % name, xbmc.LOGDEBUG)
        log("Sort Name : %s" % sortname, xbmc.LOGDEBUG)
    else:
        if not alias:
            log("No Artist ID found trying aliases: %s" % artist_search,
                xbmc.LOGDEBUG)
            name, id, sortname = get_musicbrainz_artist_id(
                artist_search, limit, True)
        else:
            log("No Artist ID found for Artist: %s" % artist_search,
                xbmc.LOGDEBUG)
    xbmc.sleep(mb_delay)
    return name, id, sortname
예제 #7
0
def get_musicbrainz_artists(artist_search, limit=1):
    log("Artist: %s" % artist_search, xbmc.LOGDEBUG)
    score = ""
    name = ""
    id = ""
    sortname = ""
    artists = []
    artist_name = smart_unicode(
        (artist_search.replace('"', '?').replace('&', 'and')))
    url = artist_url % (server, quote_plus(artist_name.encode("utf-8")), limit)
    htmlsource = get_html_source(url, "", save_file=False, overwrite=False)
    match = re.findall('''<artist(.*?)</artist>''', htmlsource)
    if match:
        for item in match:
            artist = {}
            artist["score"] = ""
            artist["name"] = ""
            artist["id"] = ""
            artist["sortname"] = ""
            score_match = re.search('''score="(.*?)"''', item)
            name_match = re.search('''<name>(.*?)</name>''', item)
            id_match = re.search('''id="(.*?)"(?:.*?)>''', item)
            if not id_match:
                id_match = re.search('''id="(.*?)">''', item)
            sort_name_match = re.search('''<sort-name>(.*?)</sort-name>''',
                                        item)
            if score_match:
                artist["score"] = score_match.group(1)
            if name_match:
                artist["name"] = unescape(smart_unicode(name_match.group(1)))
            if id_match:
                artist["id"] = id_match.group(1)
            if sort_name_match:
                artist["sortname"] = unescape(
                    smart_unicode(sort_name_match.group(1)))
            log("Score     : %s" % artist["score"], xbmc.LOGDEBUG)
            log("Id        : %s" % artist["id"], xbmc.LOGDEBUG)
            log("Name      : %s" % artist["name"], xbmc.LOGDEBUG)
            log("Sort Name : %s" % artist["sortname"], xbmc.LOGDEBUG)
            artists.append(artist)
    else:
        log("No Artist ID found for Artist: %s" % repr(artist_search),
            xbmc.LOGDEBUG)
    xbmc.sleep(mb_delay)
    return artists
def get_musicbrainz_artists( artist_search, limit=1 ):
    log( "Artist: %s" % artist_search, xbmc.LOGDEBUG )
    score = ""
    name = ""
    id = ""
    sortname = ""
    artists = []
    artist_name = smart_unicode( artist_search.replace( '"', '?' ) )
    url = artist_url % ( server, quote_plus( artist_name.encode("utf-8") ), limit )
    htmlsource = get_html_source( url, "", save_file = False, overwrite = False )
    match = re.findall( '''<artist(.*?)</artist>''', htmlsource )
    if match:
        for item in match:
            artist = {}
            artist["score"] = ""
            artist["name"] = ""
            artist["id"] = ""
            artist["sortname"] = ""
            score_match = re.search( '''score="(.*?)"''', item )
            name_match = re.search( '''<name>(.*?)</name>''', item )
            id_match = re.search( '''id="(.*?)"(?:.*?)>''', item )
            if not id_match:
                id_match = re.search( '''id="(.*?)">''', item )
            sort_name_match = re.search( '''<sort-name>(.*?)</sort-name>''', item )
            if score_match:
                artist["score"] = score_match.group(1)
            if name_match:
                artist["name"] = unescape( smart_unicode( name_match.group(1) ) )
            if id_match:
                artist["id"] = id_match.group(1)
            if sort_name_match:
                artist["sortname"] = unescape( smart_unicode( sort_name_match.group(1) ) )
            log( "Score     : %s" % artist["score"], xbmc.LOGDEBUG )
            log( "Id        : %s" % artist["id"], xbmc.LOGDEBUG )
            log( "Name      : %s" % artist["name"], xbmc.LOGDEBUG )
            log( "Sort Name : %s" % artist["sortname"], xbmc.LOGDEBUG )
            artists.append(artist)
    else:
        log( "No Artist ID found for Artist: %s" % repr( artist_search ), xbmc.LOGDEBUG )
    xbmc.sleep( mb_delay )
    return artists
def get_musicbrainz_artist_id( artist, limit=1, alias = False ):
    name = ""
    id = ""
    sortname = ""
    artist_name = smart_unicode( artist.replace( '"', '?' ) )
    if not alias:
        url = artist_url % ( server, quote_plus( artist_name.encode("utf-8") ), limit )
    else:
        url = alias_url % ( server, quote_plus( artist_name.encode("utf-8") ), limit )
    htmlsource = get_html_source( url, "", save_file = False)
    match = re.search( '''<artist(.*?)</artist>''', htmlsource )
    if match:
        score_match = re.search( '''score="(.*?)"''', htmlsource )
        name_match = re.search( '''<name>(.*?)</name>''', htmlsource )
        id_match = re.search( '''<artist id="(.*?)"(?:.*?)>''', htmlsource )
        if not id_match:
            id_match = re.search( '''<artist (?:.*?)id="(.*?)">''', htmlsource )
        sort_name_match = re.search( '''<sort-name>(.*?)</sort-name>''', htmlsource )
        
        if score_match:
            score = score_match.group(1)
        if name_match:
            name = unescape( smart_unicode( name_match.group(1) ) )
        if id_match:
            id = id_match.group(1)
        if sort_name_match:
            sortname = unescape( smart_unicode( sort_name_match.group(1) ) )
        log( "Score     : %s" % score, xbmc.LOGDEBUG )
        log( "Id        : %s" % id, xbmc.LOGDEBUG )
        log( "Name      : %s" % name, xbmc.LOGDEBUG )
        log( "Sort Name : %s" % sortname, xbmc.LOGDEBUG )
    else:
        if not alias:
            log( "No Artist ID found trying aliases: %s" % artist, xbmc.LOGDEBUG )
            name, id, sortname = get_musicbrainz_artist_id( artist, limit, True )
        else:
            log( "No Artist ID found for Artist: %s" % artist, xbmc.LOGDEBUG )
    xbmc.sleep( mb_delay )
    return name, id, sortname
예제 #10
0
파일: fs.py 프로젝트: cloudfs/ftp-cloudfs
    def remove(self, path):
        """
        Remove a file.

        Raises OSError on error.
        """
        path = self.abspath(path)
        logging.debug("remove %r" % path)
        logging.info("remove %r" % path)
        container, name = parse_fspath(path)

        if not name:
            raise IOSError(EACCES, "Can't remove a container")

        if self.isdir(path):
            raise IOSError(EACCES, "Can't remove a directory (use rmdir instead)")

        meta = self.conn.head_object(container, name)
        if 'x-object-manifest' in meta:
            self._remove_path_folder_files(u'/' + smart_unicode(unquote(meta['x-object-manifest']), "utf-8"))
        self.conn.delete_object(container, name)
        self._listdir_cache.flush(posixpath.dirname(path))
        return not name
예제 #11
0
    def listdir_container(self, cache, container, path=""):
        """Fills cache with the list dir of the container"""
        container = smart_str(container)
        path = smart_str(path)
        logging.debug("listdir container %r path %r" % (container, path))
        if path:
            prefix = path.rstrip("/") + "/"
        else:
            prefix = None
        _, objects = self.conn.get_container(container,
                                             prefix=prefix,
                                             delimiter="/")

        # override 10000 objects limit with markers
        nbobjects = len(objects)
        while nbobjects >= 10000:
            # get last object as a marker
            lastobject = objects[-1]
            if 'subdir' in lastobject:
                # {u'subdir': 'dirname'}
                lastobjectname = lastobject['subdir'].rstrip("/")
            else:
                lastobjectname = lastobject['name']
            # get a new list with the marker
            _, newobjects = self.conn.get_container(container,
                                                    prefix=prefix,
                                                    delimiter="/",
                                                    marker=lastobjectname)
            # get the new list length
            nbobjects = len(newobjects)
            logging.debug("number of objects after marker %s: %s" %
                          (lastobjectname, nbobjects))
            # add the new list to current list
            objects.extend(newobjects)
        logging.debug("total number of objects %s:" % len(objects))

        if self.cffs.hide_part_dir:
            manifests = {}

        for obj in objects:
            # {u'bytes': 4820,  u'content_type': '...',  u'hash': u'...',  u'last_modified': u'2008-11-05T00:56:00.406565',  u'name': u'new_object'},
            if 'subdir' in obj:
                # {u'subdir': 'dirname'}
                obj['name'] = obj['subdir'].rstrip("/")

                # If a manifest and it's segment directory have the
                # same name then we have to choose which we want to
                # show, we can't show both. So we choose to keep the
                # manifest if hide_part_dir is enabled.
                #
                # We can do this here because swift returns objects in
                # alphabetical order so the manifest will come before
                # its segments.
                if self.cffs.hide_part_dir and obj['name'] in manifests:
                    logging.debug(
                        "Not adding subdir %s which would overwrite manifest" %
                        obj['name'])
                    continue
            elif obj.get('bytes') == 0 and obj.get('hash') and obj.get(
                    'content_type') != 'application/directory':
                # if it's a 0 byte file, has a hash and is not a directory, we make an extra call
                # to check if it's a manifest file and retrieve the real size / hash
                manifest_obj = self.conn.head_object(container, obj['name'])
                logging.debug("possible manifest file: %r" % manifest_obj)
                if 'x-object-manifest' in manifest_obj:
                    if self.cffs.hide_part_dir:
                        manifests[obj['name']] = smart_unicode(
                            unquote(manifest_obj['x-object-manifest']),
                            "utf-8")
                    logging.debug("manifest found: %s" %
                                  manifest_obj['x-object-manifest'])
                    obj['hash'] = manifest_obj['etag']
                    obj['bytes'] = int(manifest_obj['content-length'])
            obj['count'] = 1
            # Keep all names in utf-8, just like the filesystem
            name = posixpath.basename(obj['name']).encode("utf-8")
            cache[name] = self._make_stat(**obj)

        if self.cffs.hide_part_dir:
            for manifest in manifests:
                manifest_container, manifest_obj = parse_fspath(
                    '/' + manifests[manifest])
                if manifest_container == container:
                    for cache_obj in cache.copy():
                        # hide any manifest segments, but not the manifest itself, if it
                        # happens to share a prefix with its segments.
                        if unicode(unquote(cache_obj), "utf-8") != manifest and \
                           unicode(unquote(os.path.join(path, cache_obj)), "utf-8").startswith(manifest_obj):
                            logging.debug("hiding manifest %r segment %r" %
                                          (manifest, cache_obj))
                            del cache[cache_obj]
예제 #12
0
def auto_download( type, artist_list, background=False ):
    is_canceled = False
    log( "Autodownload", xbmc.LOGDEBUG )
    try:
        artist_count = 0
        download_count = 0
        cdart_existing = 0
        album_count = 0
        d_error=False
        percent = 1
        successfully_downloaded = []
        if type in ( "clearlogo_allartists", "artistthumb_allartists", "fanart_allartists", "musicbanner_allartists" ):
            if type == "clearlogo_allartists":
                type = "clearlogo"
            elif type == "artistthumb_allartists":
                type = "artistthumb"
            elif type == "musicbanner_allartists":
                type = "musicbanner"
            else:
                type = "fanart"
        count_artist_local = len( artist_list )
        dialog_msg( "create", heading = __language__(32046), background = background )
        #Onscreen Dialog - Automatic Downloading of Artwork
        key_label = type
        for artist in artist_list:
            low_res = True
            if dialog_msg( "iscanceled", background = background ) or is_canceled:
                is_canceled = True
                break
            artist_count += 1
            if not artist["has_art"] == "True":
            # If fanart.tv does not report that it has an artist match skip it.
                continue
            percent = int( (artist_count / float(count_artist_local) ) * 100)
            if percent < 1:
                percent = 1
            if percent > 100:
                percent = 100
            log( "Artist: %-40s Local ID: %-10s   Distant MBID: %s" % ( artist["name"], artist["local_id"], artist["musicbrainz_artistid"] ), xbmc.LOGNOTICE )
            if type in ( "fanart", "clearlogo", "artistthumb", "musicbanner" ) and artist[ "has_art" ]:
                dialog_msg( "update", percent = percent, line1 = "%s%s" % ( __language__(32038), get_unicode( artist["name"] ) ), background = background )
                auto_art = {}
                temp_art = {}
                temp_art["musicbrainz_artistid"] = artist["musicbrainz_artistid"]
                auto_art["musicbrainz_artistid"] = artist["musicbrainz_artistid"]
                temp_art["artist"] = artist["name"]
                auto_art["artist"] = artist["name"]
                path = os.path.join( music_path, change_characters( smart_unicode( artist["name"] ) ) )
                if type == "fanart":
                    art = remote_fanart_list( auto_art )
                elif type == "clearlogo":
                    art = remote_clearlogo_list( auto_art )
                    arthd = remote_hdlogo_list( auto_art )
                elif type == "musicbanner":
                    art = remote_banner_list( auto_art )
                else:
                    art = remote_artistthumb_list( auto_art )
                if art:
                    if type == "fanart":
                        temp_art["path"] = path
                        auto_art["path"] = os.path.join( path, "extrafanart" ).replace( "\\\\" , "\\" )
                        if not exists( auto_art["path"] ):
                            try:
                                if _makedirs( auto_art["path"] ):
                                    log( "extrafanart directory made", xbmc.LOGDEBUG )
                            except:
                                print_exc()
                                log( "unable to make extrafanart directory", xbmc.LOGDEBUG )
                                continue
                        else:
                            log( "extrafanart directory already exists", xbmc.LOGDEBUG )
                    else:
                        auto_art["path"] = path
                    if type == "fanart":
                        if enable_fanart_limit:
                            fanart_dir, fanart_files = listdir( auto_art["path"] )
                            fanart_number = len( fanart_files )
                            if fanart_number == fanart_limit:
                                continue
                        if not exists( os.path.join( path, "fanart.jpg" ).replace( "\\\\", "\\" ) ):
                            message, d_success, final_destination, is_canceled = download_art( art[0], temp_art, artist["local_id"], "fanart", "single", 0, background )
                        for artwork in art:
                            fanart = {}
                            if enable_fanart_limit and fanart_number == fanart_limit:
                                log( "Fanart Limit Reached", xbmc.LOGNOTICE )
                                continue
                            if exists( os.path.join( auto_art["path"], os.path.basename( artwork ) ) ):
                                log( "Fanart already exists, skipping", xbmc.LOGDEBUG )
                                continue
                            else:
                                message, d_success, final_destination, is_canceled = download_art( artwork, auto_art, artist["local_id"], "fanart", "auto", 0, background )
                            if d_success == 1:
                                if enable_fanart_limit:
                                    fanart_number += 1
                                download_count += 1
                                fanart["artist"] = auto_art["artist"]
                                fanart["path"] = final_destination
                                successfully_downloaded.append( fanart )
                            else:
                                log( "Download Error...  Check Path.", xbmc.LOGDEBUG )
                                log( "    Path: %s" % auto_art["path"], xbmc.LOGDEBUG )
                                d_error = True
                    else:
                        if type == "clearlogo":
                            if arthd and enable_hdlogos:
                                artwork = arthd[0]
                            else:
                                artwork = art[0]
                        else:
                            artwork = art[0]
                        if type == "artistthumb":
                            if resizeondownload:
                                low_res = check_size( auto_art["path"], key_label, 1000, 1000 )
                            # Fixed always redownloading Thumbs
                            else:
                                low_res = False
                            if exists( os.path.join( auto_art["path"], "folder.jpg" ) ) and not low_res:
                                log( "Artist Thumb already exists, skipping", xbmc.LOGDEBUG )
                                continue
                            else:
                                message, d_success, final_destination, is_canceled = download_art( artwork , auto_art, artist["local_id"], "artistthumb", "auto", 0, background )
                        elif type == "clearlogo":
                            if enable_hdlogos and resizeondownload and arthd:
                                low_res = check_size( auto_art["path"], key_label, 800, 310 )
                            else:
                                low_res = False
                            if exists( os.path.join( auto_art["path"], "logo.png" ) ) and not low_res:
                                log( "ClearLOGO already exists, skipping", xbmc.LOGDEBUG )
                                continue
                            else:
                                message, d_success, final_destination, is_canceled = download_art( artwork , auto_art, artist["local_id"], "clearlogo", "auto", 0, background )
                        elif type == "musicbanner":
                            if exists( os.path.join( auto_art["path"], "banner.jpg" ) ):
                                log( "Music Banner already exists, skipping", xbmc.LOGDEBUG )
                                continue
                            else:
                                message, d_success, final_destination, is_canceled = download_art( artwork , auto_art, artist["local_id"], "musicbanner", "auto", 0, background )
                        if d_success == 1:
                            download_count += 1
                            auto_art["path"] = final_destination
                            successfully_downloaded.append( auto_art )
                        else:
                            log( "Download Error...  Check Path.", xbmc.LOGDEBUG )
                            log( "    Path: %s" % auto_art["path"], xbmc.LOGDEBUG )
                            d_error = True
                else :
                        log( "Artist Match not found", xbmc.LOGDEBUG )
            elif type in ( "cdart", "cover" ) and artist[ "has_art" ]:
                local_album_list = get_local_albums_db( artist["name"], background )
                if type == "cdart":
                    remote_art_url = remote_cdart_list( artist )
                else:
                    remote_art_url = remote_coverart_list( artist )
                for album in local_album_list:
                    low_res = True
                    if dialog_msg( "iscanceled", background = background ):
                            break
                    if not remote_art_url:
                        log( "No artwork found", xbmc.LOGDEBUG )
                        break
                    album_count += 1
                    if not album["musicbrainz_albumid"]:
                        continue
                    dialog_msg( "update", percent = percent, line1 = "%s%s" % ( __language__(32038) , get_unicode( artist["name"] ) ), line2 = "%s%s" % (__language__(32039) , get_unicode( album["title"] ) ), background = background )
                    name = artist["name"]
                    title = album["title"]
                    log( "Album: %s" % album["title"], xbmc.LOGDEBUG )
                    if not album[key_label] or resizeondownload:
                        musicbrainz_albumid = album["musicbrainz_albumid"]
                        art = artwork_search( remote_art_url, musicbrainz_albumid, album["disc"], key_label )
                        if art:
                            if resizeondownload:
                                low_res = check_size( album["path"].replace( "\\\\", "\\" ), key_label, art["size"], art["size"] )
                            if art["picture"]: 
                                log( "ALBUM MATCH ON FANART.TV FOUND", xbmc.LOGDEBUG )
                                #log( "test_album[0]: %s" % test_album[0], xbmc.LOGDEBUG )
                                if low_res:
                                    message, d_success, final_destination, is_canceled = download_art( art["picture"], album, album["local_id"], key_label, "auto", 0, background )
                                    if d_success == 1:
                                        download_count += 1
                                        album[key_label] = True
                                        album["path"] = final_destination
                                        successfully_downloaded.append( album )
                                    else:
                                        log( "Download Error...  Check Path.", xbmc.LOGDEBUG )
                                        log( "    Path: %s" % repr( album["path"] ), xbmc.LOGDEBUG )
                                        d_error = True
                                else:
                                    pass
                            else:
                                log( "ALBUM NOT MATCHED ON FANART.TV", xbmc.LOGDEBUG )
                        else:
                            log( "ALBUM NOT MATCHED ON FANART.TV", xbmc.LOGDEBUG )
                    else:
                        log( "%s artwork file already exists, skipping..." % key_label, xbmc.LOGDEBUG )
        dialog_msg( "close", background = background )
        if d_error:
            dialog_msg( "ok", line1 = __language__(32026), line2 = "%s: %s" % ( __language__(32041), download_count ), background = background )
        else:
            dialog_msg( "ok", line1 = __language__(32040), line2 = "%s: %s" % ( __language__(32041), download_count ), background = background  )
        return download_count, successfully_downloaded
    except:
        print_exc()
        dialog_msg( "close", background = background )
예제 #13
0
def get_musicbrainz_album( album_title, artist, e_count, limit=1, with_singles=False, by_release=False, use_alias=False, use_live=False ):
    """ Retrieves information for Album from MusicBrainz using provided Album title and Artist name. 
        
        Use:
            album, albums = get_musicbrainz_album( album_title, artist, e_count, limit, with_singles, by_release )
        
        album_title  - the album title(must be unicode)
        artist       - the artist's name(must be unicode)
        e_count      - used internally(should be set to 0)
        limit        - limit the number of responses
        with_singles - set to True to look up single releases at the same time
        by_release   - use release name for search
    """
    match_within = "~2"
    album = {}
    albums = []
    count = e_count
    album["score"] = ""
    album["id"] = ""
    album["title"] = ""
    album["artist"] = ""
    album["artist_id"] = ""
    log( "Artist: %s" % smart_unicode( artist ), xbmc.LOGDEBUG )
    album_temp = smart_unicode( album_title )
    artist = smart_unicode( get_unicode( artist ) )
    album_title = smart_unicode( get_unicode( album_title ) )
    log( "Artist: %s" % artist, xbmc.LOGDEBUG )
    log( "Album: %s" % album_title, xbmc.LOGDEBUG )
    artist = artist.replace('"','?')
    album_title = album_title.replace('"','?')
    if limit == 1:
        if not use_alias:
            url = release_group_url_artist % ( server, quote_plus( album_title.encode("utf-8") ), match_within, quote_plus( artist.encode("utf-8") ) )
            if not with_singles and not by_release and not use_live:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles or Live albums", xbmc.LOGDEBUG )
                url = url + nolive_nosingles + query_limit % limit
            elif not with_singles and not by_release and use_live:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles", xbmc.LOGDEBUG )
                url = url + live_nosingles + query_limit % limit
            elif not by_release:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Including Singles and Live albums", xbmc.LOGDEBUG )
                url = url + query_limit % limit
            elif not with_singles:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Using Release Name", xbmc.LOGDEBUG )
                url = release_group_url_artist % ( server, quote_plus( album_title.encode("utf-8") ), match_within, quote_plus( artist.encode("utf-8") ) ) + query_limit % limit
        elif use_alias:
            url = release_group_url_alias % ( server, quote_plus( album_title.encode("utf-8") ), match_within, quote_plus( artist.encode("utf-8") ) )
            if not with_singles and not by_release and not use_live:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles or Live albums", xbmc.LOGDEBUG )
                url = url + nolive_nosingles + query_limit % limit
            elif not with_singles and not by_release and use_live:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles", xbmc.LOGDEBUG )
                url = url + live_nosingles + query_limit % limit
            elif not by_release:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Including Singles and Live albums", xbmc.LOGDEBUG )
                url = url + query_limit % limit
            elif not with_singles:
                log( "Retrieving MusicBrainz Info - Checking by Artist - Using Release Name", xbmc.LOGDEBUG )
                url = release_group_url_alias % ( server, quote_plus( album_title.encode("utf-8") ), match_within, quote_plus( artist.encode("utf-8") ) ) + query_limit % limit
        htmlsource = get_html_source( url, "", save_file = False, overwrite = False )
        match = re.search( '''<release-group-list count="(?:.*?)" offset="(?:.*?)">(.*?)</release-group-list>''', htmlsource )
        if match:
            try:
                mbid = re.search( '''<release-group id="(.*?)"(?:.*?)">''', htmlsource)
                if not mbid:
                    mbid = re.search( '''<release-group (?:.*?)id="(.*?)">''', htmlsource )
                mbtitle = re.search( '''<title>(.*?)</title>''', htmlsource)
                mbartist = re.search( '''<name>(.*?)</name>''', htmlsource)
                mbartistid = re.search( '''<artist id="(.*?)">''', htmlsource)
                album["id"] = mbid.group(1)
                album["title"] = unescape( smart_unicode( mbtitle.group(1) ) )
                album["artist"] = unescape( smart_unicode( mbartist.group(1) ) )
                album["artist_id"] = mbartistid.group(1)
            except:
                pass            
        if not album["id"]:
            xbmc.sleep( mb_delay ) # sleep for allowing proper use of webserver
            if not with_singles and not by_release and not use_alias and not use_live:
                log( "No releases found on MusicBrainz, Checking For Live Album", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, False, False, False, True ) # try again by using artist alias
            elif not with_singles and not by_release and not use_alias and use_live:
                log( "No releases found on MusicBrainz, Checking by Artist Alias", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, False, False, True, False ) # try again by using artist alias
            elif use_alias and not with_singles and not by_release and not use_live:
                log( "No releases found on MusicBrainz, Checking by Release Name", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, False, True, False, False ) # try again by using release name
            elif by_release and not with_singles and not use_alias:
                log( "No releases found on MusicBrainz, Checking by Release name and Artist Alias", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, False, True, True, False ) # try again by using release name and artist alias
            elif by_release and not with_singles and use_alias:
                log( "No releases found on MusicBrainz, checking singles", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, True, False, False, False ) # try again with singles
            elif with_singles and not use_alias and not by_release:
                log( "No releases found on MusicBrainz, checking singles and Artist Alias", xbmc.LOGDEBUG )
                album, albums = get_musicbrainz_album( album_title, artist, 0, limit, True, False, True, False ) # try again with singles and artist alias
            else:
                log( "No releases found on MusicBrainz.", xbmc.LOGDEBUG )
                album["artist"], album["artist_id"], sort_name = get_musicbrainz_artist_id( artist )
    else:
        match_within = "~4"
        url = release_group_url_artist % ( server, ( album_title.encode("utf-8") ), match_within, ( artist.encode("utf-8") ) ) + query_limit % limit
        htmlsource = get_html_source( url, "", save_file = False, overwrite = False )
        match = re.search( '''<release-group-list count="(?:.*?)" offset="(?:.*?)">(.*?)</release-group-list>''', htmlsource )
        if match:
            match_release_group = re.findall( '''<release-group(.*?)</release-group>''', match.group( 1 ) )
            if match_release_group:
                for item in match_release_group:
                    album = {}
                    album["score"] = ""
                    album["id"] = ""
                    album["title"] = ""
                    album["artist"] = ""
                    album["artist_id"] = ""
                    try:
                        mbscore = re.search( '''score="(.*?)"''', item)
                        mbid = re.search( '''<release-group id="(.*?)"(?:.*?)">''', item)
                        if not mbid:
                            mbid = re.search( '''id="(.*?)"(?:.*?)">''', item)
                            if not mbid:
                                mbid = re.search( '''<release-group (?:.*?)id="(.*?)">''', htmlsource )
                        mbtitle = re.search( '''<title>(.*?)</title>''', item)
                        mbartist = re.search( '''<name>(.*?)</name>''', item)
                        mbartistid = re.search( '''<artist id="(.*?)">''', item)
                        album["score"] = mbscore.group(1)
                        album["id"] = mbid.group(1)
                        album["title"] = unescape( smart_unicode( mbtitle.group(1) ) )
                        album["artist"] = unescape( smart_unicode( mbartist.group(1) ) )
                        album["artist_id"] = mbartistid.group(1)
                        log( "Score     : %s" % album["score"], xbmc.LOGDEBUG )
                        log( "Title     : %s" % album["title"], xbmc.LOGDEBUG )
                        log( "Id        : %s" % album["id"], xbmc.LOGDEBUG )
                        log( "Artist    : %s" % album["artist"], xbmc.LOGDEBUG )
                        log( "Artist ID : %s" % album["artist_id"], xbmc.LOGDEBUG )
                        albums.append(album)
                    except:
                        print_exc()
                    
            else:
                pass
        else:
            pass
    xbmc.sleep( mb_delay ) # sleep for allowing proper use of webserver
    return album, albums
예제 #14
0
파일: tuan800_gae.py 프로젝트: kaiix/tuan
def get_tuans(content):
    soup = BeautifulSoup(content)
    tuans = {}
    for tag in soup.findAll('div', attrs={'class': 'new_ms_bt'}):
        tuans[tag.p.a['href']] = smart_unicode(tag.p.a.text)
    return tuans
예제 #15
0
def get_musicbrainz_album(album_title,
                          artist,
                          e_count,
                          limit=1,
                          with_singles=False,
                          by_release=False,
                          use_alias=False,
                          use_live=False):
    """ Retrieves information for Album from MusicBrainz using provided Album title and Artist name. 
        
        Use:
            album, albums = get_musicbrainz_album( album_title, artist, e_count, limit, with_singles, by_release )
        
        album_title  - the album title(must be unicode)
        artist       - the artist's name(must be unicode)
        e_count      - used internally(should be set to 0)
        limit        - limit the number of responses
        with_singles - set to True to look up single releases at the same time
        by_release   - use release name for search
    """
    match_within = "~2"
    album = {}
    albums = []
    count = e_count
    album["score"] = ""
    album["id"] = ""
    album["title"] = ""
    album["artist"] = ""
    album["artist_id"] = ""
    album_temp = smart_unicode(album_title)
    artist = smart_unicode(get_unicode(artist))
    album_title = smart_unicode(get_unicode(album_title))
    log("Artist: %s" % artist, xbmc.LOGDEBUG)
    log("Album: %s" % album_title, xbmc.LOGDEBUG)
    artist = artist.replace('"', '?')
    artist = artist.replace('&', 'and')
    album_title = album_title.replace('"', '?')
    album_title = album_title.replace('&', 'and')
    if limit == 1:
        if not use_alias:
            url = release_group_url_artist % (
                server, quote_plus(album_title.encode("utf-8")), match_within,
                quote_plus(artist.encode("utf-8")))
            if not with_singles and not by_release and not use_live:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles or Live albums",
                    xbmc.LOGDEBUG)
                url = url + nolive_nosingles + query_limit % limit
            elif not with_singles and not by_release and use_live:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles",
                    xbmc.LOGDEBUG)
                url = url + live_nosingles + query_limit % limit
            elif not by_release:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Including Singles and Live albums",
                    xbmc.LOGDEBUG)
                url = url + query_limit % limit
            elif not with_singles:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Using Release Name",
                    xbmc.LOGDEBUG)
                url = release_group_url_artist % (
                    server, quote_plus(
                        album_title.encode("utf-8")), match_within,
                    quote_plus(artist.encode("utf-8"))) + query_limit % limit
        elif use_alias:
            url = release_group_url_alias % (
                server, quote_plus(album_title.encode("utf-8")), match_within,
                quote_plus(artist.encode("utf-8")))
            if not with_singles and not by_release and not use_live:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles or Live albums",
                    xbmc.LOGDEBUG)
                url = url + nolive_nosingles + query_limit % limit
            elif not with_singles and not by_release and use_live:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Not including Singles",
                    xbmc.LOGDEBUG)
                url = url + live_nosingles + query_limit % limit
            elif not by_release:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Including Singles and Live albums",
                    xbmc.LOGDEBUG)
                url = url + query_limit % limit
            elif not with_singles:
                log(
                    "Retrieving MusicBrainz Info - Checking by Artist - Using Release Name",
                    xbmc.LOGDEBUG)
                url = release_group_url_alias % (
                    server, quote_plus(
                        album_title.encode("utf-8")), match_within,
                    quote_plus(artist.encode("utf-8"))) + query_limit % limit
        htmlsource = get_html_source(url, "", save_file=False, overwrite=False)
        match = re.search(
            '''<release-group-list count="(?:.*?)" offset="(?:.*?)">(.*?)</release-group-list>''',
            htmlsource)
        if match:
            try:
                mbid = re.search('''<release-group id="(.*?)"(?:.*?)">''',
                                 htmlsource)
                if not mbid:
                    mbid = re.search('''<release-group (?:.*?)id="(.*?)">''',
                                     htmlsource)
                mbtitle = re.search('''<title>(.*?)</title>''', htmlsource)
                mbartist = re.search('''<name>(.*?)</name>''', htmlsource)
                mbartistid = re.search('''<artist id="(.*?)">''', htmlsource)
                album["id"] = mbid.group(1)
                album["title"] = unescape(smart_unicode(mbtitle.group(1)))
                album["artist"] = unescape(smart_unicode(mbartist.group(1)))
                album["artist_id"] = mbartistid.group(1)
            except:
                pass
        if not album["id"]:
            xbmc.sleep(mb_delay)  # sleep for allowing proper use of webserver
            if not with_singles and not by_release and not use_alias and not use_live:
                log(
                    "No releases found on MusicBrainz, Checking For Live Album",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, False, False, False,
                    True)  # try again by using artist alias
            elif not with_singles and not by_release and not use_alias and use_live:
                log(
                    "No releases found on MusicBrainz, Checking by Artist Alias",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, False, False, True,
                    False)  # try again by using artist alias
            elif use_alias and not with_singles and not by_release and not use_live:
                log(
                    "No releases found on MusicBrainz, Checking by Release Name",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, False, True, False,
                    False)  # try again by using release name
            elif by_release and not with_singles and not use_alias:
                log(
                    "No releases found on MusicBrainz, Checking by Release name and Artist Alias",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, False, True, True,
                    False)  # try again by using release name and artist alias
            elif by_release and not with_singles and use_alias:
                log("No releases found on MusicBrainz, checking singles",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, True, False, False,
                    False)  # try again with singles
            elif with_singles and not use_alias and not by_release:
                log(
                    "No releases found on MusicBrainz, checking singles and Artist Alias",
                    xbmc.LOGDEBUG)
                album, albums = get_musicbrainz_album(
                    album_title, artist, 0, limit, True, False, True,
                    False)  # try again with singles and artist alias
            else:
                log("No releases found on MusicBrainz.", xbmc.LOGDEBUG)
                album["artist"], album[
                    "artist_id"], sort_name = get_musicbrainz_artist_id(artist)
    else:
        match_within = "~4"
        url = release_group_url_artist % (
            server, (album_title.encode("utf-8")), match_within,
            (artist.encode("utf-8"))) + query_limit % limit
        htmlsource = get_html_source(url, "", save_file=False, overwrite=False)
        match = re.search(
            '''<release-group-list count="(?:.*?)" offset="(?:.*?)">(.*?)</release-group-list>''',
            htmlsource)
        if match:
            match_release_group = re.findall(
                '''<release-group(.*?)</release-group>''', match.group(1))
            if match_release_group:
                for item in match_release_group:
                    album = {}
                    album["score"] = ""
                    album["id"] = ""
                    album["title"] = ""
                    album["artist"] = ""
                    album["artist_id"] = ""
                    try:
                        mbscore = re.search('''score="(.*?)"''', item)
                        mbid = re.search(
                            '''<release-group id="(.*?)"(?:.*?)">''', item)
                        if not mbid:
                            mbid = re.search('''id="(.*?)"(?:.*?)">''', item)
                            if not mbid:
                                mbid = re.search(
                                    '''<release-group (?:.*?)id="(.*?)">''',
                                    htmlsource)
                        mbtitle = re.search('''<title>(.*?)</title>''', item)
                        mbartist = re.search('''<name>(.*?)</name>''', item)
                        mbartistid = re.search('''<artist id="(.*?)">''', item)
                        album["score"] = mbscore.group(1)
                        album["id"] = mbid.group(1)
                        album["title"] = unescape(
                            smart_unicode(mbtitle.group(1)))
                        album["artist"] = unescape(
                            smart_unicode(mbartist.group(1)))
                        album["artist_id"] = mbartistid.group(1)
                        log("Score     : %s" % album["score"], xbmc.LOGDEBUG)
                        log("Title     : %s" % album["title"], xbmc.LOGDEBUG)
                        log("Id        : %s" % album["id"], xbmc.LOGDEBUG)
                        log("Artist    : %s" % album["artist"], xbmc.LOGDEBUG)
                        log("Artist ID : %s" % album["artist_id"],
                            xbmc.LOGDEBUG)
                        albums.append(album)
                    except:
                        print_exc()

            else:
                pass
        else:
            pass
    xbmc.sleep(mb_delay)  # sleep for allowing proper use of webserver
    return album, albums
예제 #16
0
파일: fs.py 프로젝트: cloudfs/ftp-cloudfs
    def listdir_container(self, cache, container, path=""):
        """Fills cache with the list dir of the container"""
        container = smart_str(container)
        path = smart_str(path)
        logging.debug("listdir container %r path %r" % (container, path))
        if path:
            prefix = path.rstrip("/")+"/"
        else:
            prefix = None
        _, objects = self.conn.get_container(container, prefix=prefix, delimiter="/")

        # override 10000 objects limit with markers
        nbobjects = len(objects)
        while nbobjects >= 10000:
            # get last object as a marker
            lastobject = objects[-1]
            if 'subdir' in lastobject:
                # {u'subdir': 'dirname'}
                lastobjectname = lastobject['subdir'].rstrip("/")
            else:
                lastobjectname = lastobject['name']
            # get a new list with the marker
            _, newobjects = self.conn.get_container(container, prefix=prefix, delimiter="/", marker=lastobjectname)
            # get the new list length
            nbobjects = len(newobjects)
            logging.debug("number of objects after marker %s: %s" % (lastobjectname, nbobjects))
            # add the new list to current list
            objects.extend(newobjects)
        logging.debug("total number of objects %s:" % len(objects))

        if self.cffs.hide_part_dir:
            manifests = {}

        for obj in objects:
            # {u'bytes': 4820,  u'content_type': '...',  u'hash': u'...',  u'last_modified': u'2008-11-05T00:56:00.406565',  u'name': u'new_object'},
            if 'subdir' in obj:
                # {u'subdir': 'dirname'}
                obj['name'] = obj['subdir'].rstrip("/")

                # If a manifest and it's segment directory have the
                # same name then we have to choose which we want to
                # show, we can't show both. So we choose to keep the
                # manifest if hide_part_dir is enabled.
                #
                # We can do this here because swift returns objects in
                # alphabetical order so the manifest will come before
                # its segments.
                if self.cffs.hide_part_dir and obj['name'] in manifests:
                    logging.debug("Not adding subdir %s which would overwrite manifest" % obj['name'])
                    continue
            elif obj.get('bytes') == 0 and obj.get('hash') and obj.get('content_type') != 'application/directory':
                # if it's a 0 byte file, has a hash and is not a directory, we make an extra call
                # to check if it's a manifest file and retrieve the real size / hash
                manifest_obj = self.conn.head_object(container, obj['name'])
                logging.debug("possible manifest file: %r" % manifest_obj)
                if 'x-object-manifest' in manifest_obj:
                    if self.cffs.hide_part_dir:
                        manifests[obj['name']] = smart_unicode(unquote(manifest_obj['x-object-manifest']), "utf-8")
                    logging.debug("manifest found: %s" % manifest_obj['x-object-manifest'])
                    obj['hash'] = manifest_obj['etag']
                    obj['bytes'] = int(manifest_obj['content-length'])
            obj['count'] = 1
            # Keep all names in utf-8, just like the filesystem
            name = posixpath.basename(obj['name']).encode("utf-8")
            cache[name] = self._make_stat(**obj)

        if self.cffs.hide_part_dir:
            for manifest in manifests:
                manifest_container, manifest_obj = parse_fspath('/' + manifests[manifest])
                if manifest_container == container:
                    for cache_obj in cache.copy():
                        # hide any manifest segments, but not the manifest itself, if it
                        # happens to share a prefix with its segments.
                        if unicode(unquote(cache_obj), "utf-8") != manifest and \
                           unicode(unquote(os.path.join(path, cache_obj)), "utf-8").startswith(manifest_obj):
                            logging.debug("hiding manifest %r segment %r" % (manifest, cache_obj))
                            del cache[cache_obj]