Exemplo n.º 1
0
def checkGithub():

    # Get the latest commit available from github
    url = 'https://api.github.com/repos/%s/headphones/commits/%s' % (
        headphones.GIT_USER, headphones.GIT_BRANCH)
    logger.info('Retrieving latest version information from github')
    try:
        result = urllib2.urlopen(url, timeout=20).read()
        git = simplejson.JSONDecoder().decode(result)
        headphones.LATEST_VERSION = git['sha']
    except:
        logger.warn('Could not get the latest commit from github')
        headphones.COMMITS_BEHIND = 0
        return headphones.CURRENT_VERSION

    # See how many commits behind we are
    if headphones.CURRENT_VERSION:
        logger.info(
            'Comparing currently installed version with latest github version')
        url = 'https://api.github.com/repos/%s/headphones/compare/%s...%s' % (
            headphones.GIT_USER, headphones.CURRENT_VERSION,
            headphones.LATEST_VERSION)

        try:
            result = urllib2.urlopen(url, timeout=20).read()
            git = simplejson.JSONDecoder().decode(result)
            headphones.COMMITS_BEHIND = git['total_commits']
        except:
            logger.warn('Could not get commits behind from github')
            headphones.COMMITS_BEHIND = 0
            return headphones.CURRENT_VERSION

        if headphones.COMMITS_BEHIND >= 1:
            logger.info('New version is available. You are %s commits behind' %
                        headphones.COMMITS_BEHIND)
        elif headphones.COMMITS_BEHIND == 0:
            logger.info('Headphones is up to date')
        elif headphones.COMMITS_BEHIND == -1:
            logger.info(
                'You are running an unknown version of Headphones. Run the updater to identify your version'
            )

    else:
        logger.info(
            'You are running an unknown version of Headphones. Run the updater to identify your version'
        )

    return headphones.LATEST_VERSION
Exemplo n.º 2
0
def getLatestVersion_FromGit():
    latest_version = 'Unknown'

    # Can only work for non Windows driven installs, so check install type
    if lazylibrarian.INSTALL_TYPE == 'win':
        logger.debug(
            '(getLatestVersion_FromGit) Code Error - Windows install - should not be called under a windows install')
        latest_version = 'WINDOWS INSTALL'
    else:
        # check current branch value of the local git repo as folks may pull from a branch not master
        branch = lazylibrarian.CURRENT_BRANCH

        if (branch == 'InvalidBranch'):
            logger.debug('(getLatestVersion_FromGit) - Failed to get a valid branch name from local repo')
        else:

            # Get the latest commit available from github
            url = 'https://api.github.com/repos/%s/%s/commits/%s' % (
                lazylibrarian.GIT_USER, lazylibrarian.GIT_REPO, lazylibrarian.GIT_BRANCH)
            logger.debug(
                '(getLatestVersion_FromGit) Retrieving latest version information from github command=[%s]' %
                url)
            try:
                result = urllib2.urlopen(url, timeout=30).read()
                git = simplejson.JSONDecoder().decode(result)
                latest_version = git['sha']
                logger.debug('(getLatestVersion_FromGit) Branch [%s] has Latest Version has been set to [%s]' % (
                             branch, latest_version))
            except:
                logger.warn('(getLatestVersion_FromGit) Could not get the latest commit from github')
                latest_version = 'Not_Available_From_GitHUB'

    return latest_version
Exemplo n.º 3
0
def checkGithub():

    # Get the latest commit available from github
    url = 'https://api.github.com/repos/%s/LazyLibrarian-1/commits/%s' % (
        user, branch)
    logger.info('Retrieving latest version information from github')
    try:
        result = urllib2.urlopen(url).read()
        git = simplejson.JSONDecoder().decode(result)
        lazylibrarian.LATEST_VERSION = git['sha']
    except:
        logger.warn('Could not get the latest commit from github')
        lazylibrarian.COMMITS_BEHIND = 0
        return lazylibrarian.CURRENT_VERSION

    # See how many commits behind we are
    if lazylibrarian.CURRENT_VERSION:
        logger.info(
            'Comparing currently installed version with latest github version')
        url = 'https://api.github.com/repos/%s/LazyLibrarian/compare/%s...%s' % (
            user, lazylibrarian.CURRENT_VERSION, lazylibrarian.LATEST_VERSION)

        try:
            result = urllib2.urlopen(url).read()
            git = simplejson.JSONDecoder().decode(result)
            lazylibrarian.COMMITS_BEHIND = git['total_commits']
        except:
            logger.warn('Could not get commits behind from github')
            lazylibrarian.COMMITS_BEHIND = 0
            return lazylibrarian.CURRENT_VERSION

        if lazylibrarian.COMMITS_BEHIND >= 1:
            logger.info('New version is available. You are %s commits behind' %
                        lazylibrarian.COMMITS_BEHIND)
        elif lazylibrarian.COMMITS_BEHIND == 0:
            logger.info('lazylibrarian is up to date')
        elif lazylibrarian.COMMITS_BEHIND == -1:
            logger.info(
                'You are running an unknown version of lazylibrarian. Run the updater to identify your version'
            )

    else:
        logger.info(
            'You are running an unknown version of lazylibrarian. Run the updater to identify your version'
        )

    return lazylibrarian.LATEST_VERSION
Exemplo n.º 4
0
def getCommitDifferenceFromGit():
    commits = -1
    # Takes current latest version value and trys to diff it with the latest
    # version in the current branch.
    if lazylibrarian.CURRENT_VERSION:
        logger.info(
            '[VersionCheck] -  Comparing currently installed version with latest github version'
        )
        url = 'https://api.github.com/repos/%s/LazyLibrarian/compare/%s...%s' % (
            lazylibrarian.GIT_USER, lazylibrarian.CURRENT_VERSION,
            lazylibrarian.LATEST_VERSION)
        logger.debug(
            '(getCommitDifferenceFromGit) -  Check for differences between local & repo by [%s]'
            % url)

        try:
            result = urllib2.urlopen(url, timeout=30).read()

            try:
                logger.debug('JSONDecode url')
                git = simplejson.JSONDecoder().decode(result)
                logger.debug('pull total_commits from json object')
                commits = git['total_commits']

                logger.debug(
                    '(getCommitDifferenceFromGit) -  GitHub reports as follows Status [%s] - Ahead [%s] - Behind [%s] - Total Commits [%s]'
                    % (git['status'], git['ahead_by'], git['behind_by'],
                       git['total_commits']))
            except:
                logger.warn(
                    '(getCommitDifferenceFromGit) -  could not get difference status from GitHub'
                )

        except:
            logger.warn(
                '(getCommitDifferenceFromGit) -  Could not get commits behind from github. Can happen if you have a local commit not pushed to repo'
            )

        if commits >= 1:
            logger.info(
                '[VersionCheck] -  New version is available. You are %s commits behind'
                % commits)
        elif commits == 0:
            logger.info('[VersionCheck] -  lazylibrarian is up to date ')
        elif commits == -1:
            logger.info(
                '[VersionCheck] -  You are running an unknown version of lazylibrarian. Run the updater to identify your version'
            )

    else:
        logger.info(
            'You are running an unknown version of lazylibrarian. Run the updater to identify your version'
        )

    logger.debug(
        '(getCommitDifferenceFromGit) - exiting with commit value of [%s]' %
        commits)
    # lazylibrarian.COMMITS_BEHIND = commits
    return commits
Exemplo n.º 5
0
def getLatestVersion_FromGit():
    latest_version = 'Unknown'

    # Can only work for non Windows driven installs, so check install type
    if lazylibrarian.CONFIG['INSTALL_TYPE'] == 'win':
        logger.debug(
            '(getLatestVersion_FromGit) Code Error - Windows install - should not be called under a windows install'
        )
        latest_version = 'WINDOWS INSTALL'
    else:
        # check current branch value of the local git repo as folks may pull from a branch not master
        branch = lazylibrarian.CONFIG['GIT_BRANCH']

        if branch == 'InvalidBranch':
            logger.debug(
                '(getLatestVersion_FromGit) - Failed to get a valid branch name from local repo'
            )
        else:
            if branch == 'Package':  # check packages against master
                branch = 'master'
            # Get the latest commit available from github
            url = 'https://api.github.com/repos/%s/%s/commits/%s' % (
                lazylibrarian.CONFIG['GIT_USER'],
                lazylibrarian.CONFIG['GIT_REPO'], branch)
            logger.debug(
                '(getLatestVersion_FromGit) Retrieving latest version information from github command=[%s]'
                % url)
            try:
                request = urllib2.Request(url)
                request.add_header('User-Agent', USER_AGENT)
                resp = urllib2.urlopen(request, timeout=30)
                result = resp.read()
                git = simplejson.JSONDecoder().decode(result)
                latest_version = git['sha']
                logger.debug(
                    '(getLatestVersion_FromGit) Branch [%s] Latest Version has been set to [%s]'
                    % (branch, latest_version))
            except Exception as e:
                logger.warn(
                    '(getLatestVersion_FromGit) Could not get the latest commit from github'
                )
                if hasattr(e, 'reason'):
                    errmsg = e.reason
                else:
                    errmsg = str(e)

                logger.debug('git error for %s: %s' % (url, errmsg))
                latest_version = 'Not_Available_From_GitHUB'

    return latest_version
Exemplo n.º 6
0
def getCommitDifferenceFromGit():
    # See how many commits behind we are
    commits = -1
    # Takes current latest version value and trys to diff it with the latest
    # version in the current branch.
    commit_list = ''
    if lazylibrarian.CONFIG['LATEST_VERSION'] == 'Not_Available_From_GitHUB':
        commits = 0  # don't report a commit diff as we don't know anything
    if lazylibrarian.CONFIG['CURRENT_VERSION'] and commits != 0:
        logmsg(
            'info',
            '[VersionCheck] -  Comparing currently installed version with latest github version'
        )
        url = 'https://api.github.com/repos/%s/LazyLibrarian/compare/%s...%s' % (
            lazylibrarian.CONFIG['GIT_USER'],
            lazylibrarian.CONFIG['CURRENT_VERSION'],
            lazylibrarian.CONFIG['LATEST_VERSION'])
        logmsg(
            'debug',
            '(getCommitDifferenceFromGit) -  Check for differences between local & repo by [%s]'
            % url)

        try:
            request = urllib2.Request(url)
            request.add_header('User-Agent', USER_AGENT)
            resp = urllib2.urlopen(request, timeout=30)
            result = resp.read()
            try:
                logmsg('debug', 'JSONDecode url')
                git = simplejson.JSONDecoder().decode(result)
                logmsg('debug', 'pull total_commits from json object')
                commits = int(git['total_commits'])

                msg = '(getCommitDifferenceFromGit) -  GitHub reports as follows '
                msg += 'Status [%s] - Ahead [%s] - Behind [%s] - Total Commits [%s]' % (
                    git['status'], git['ahead_by'], git['behind_by'],
                    git['total_commits'])
                logmsg('debug', msg)

                if int(git['total_commits']) > 0:
                    messages = []
                    for item in git['commits']:
                        messages.insert(0, item['commit']['message'])
                    for line in messages:
                        commit_list = "%s\n%s" % (commit_list, line)
            except Exception:
                logmsg(
                    'warn',
                    '(getCommitDifferenceFromGit) -  could not get difference status from GitHub'
                )

        except Exception:
            msg = '(getCommitDifferenceFromGit) -  Could not get commits behind from github. '
            msg += 'Can happen if you have a local commit not pushed to repo or no connection to github'
            logmsg('warn', msg)

        if commits > 1:
            logmsg(
                'info',
                '[VersionCheck] -  New version is available. You are %s commits behind'
                % commits)
        elif commits == 1:
            logmsg(
                'info',
                '[VersionCheck] -  New version is available. You are one commit behind'
            )
        elif commits == 0:
            logmsg('info', '[VersionCheck] -  lazylibrarian is up to date ')
            # lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
        elif commits < 0:
            msg = '[VersionCheck] -  You are running an unknown version of lazylibrarian. '
            msg += 'Run the updater to identify your version'
            logmsg('info', msg)

    elif lazylibrarian.CONFIG['LATEST_VERSION'] == 'Not_Available_From_GitHUB':
        commit_list = 'Unable to get latest version from GitHub'
        logmsg('info', commit_list)
    else:
        logmsg(
            'info',
            'You are running an unknown version of lazylibrarian. Run the updater to identify your version'
        )

    logmsg(
        'debug',
        '(getCommitDifferenceFromGit) - exiting with commit value of [%s]' %
        commits)
    # lazylibrarian.CONFIG['COMMITS_BEHIND'] = commits
    return commits, commit_list
Exemplo n.º 7
0
def getLatestVersion_FromGit():
    latest_version = 'Unknown'

    # Can only work for non Windows driven installs, so check install type
    if lazylibrarian.CONFIG['INSTALL_TYPE'] == 'win':
        logmsg(
            'debug',
            '(getLatestVersion_FromGit) Error - should not be called under a windows install'
        )
        latest_version = 'WINDOWS INSTALL'
    else:
        # check current branch value of the local git repo as folks may pull from a branch not master
        branch = lazylibrarian.CONFIG['GIT_BRANCH']

        if branch == 'InvalidBranch':
            logmsg(
                'debug',
                '(getLatestVersion_FromGit) - Failed to get a valid branch name from local repo'
            )
        else:
            if branch == 'Package':  # check packages against master
                branch = 'master'
            # Get the latest commit available from github
            url = 'https://api.github.com/repos/%s/%s/commits/%s' % (
                lazylibrarian.CONFIG['GIT_USER'],
                lazylibrarian.CONFIG['GIT_REPO'], branch)
            logmsg(
                'debug',
                '(getLatestVersion_FromGit) Retrieving latest version information from github command=[%s]'
                % url)

            age = lazylibrarian.CONFIG['GIT_UPDATED']
            try:
                request = urllib2.Request(url)
                request.add_header('User-Agent', USER_AGENT)
                if age:
                    logmsg(
                        'debug',
                        '(getLatestVersion_FromGit) Checking if modified since %s'
                        % age)
                    request.add_header('If-Modified-Since', age)
                resp = urllib2.urlopen(request, timeout=30)
                result = resp.read()
                git = simplejson.JSONDecoder().decode(result)
                latest_version = git['sha']
                logmsg(
                    'debug',
                    '(getLatestVersion_FromGit) Branch [%s] Latest Version has been set to [%s]'
                    % (branch, latest_version))
            except Exception as e:
                if hasattr(e, 'reason'):
                    errmsg = e.reason
                else:
                    errmsg = str(e)

                if hasattr(e, 'code') and str(e.code) == '304':  # Not modified
                    latest_version = lazylibrarian.CONFIG['CURRENT_VERSION']
                    logmsg(
                        'debug',
                        '(getLatestVersion_FromGit) Not modified, currently on Latest Version'
                    )
                    # lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
                else:
                    logmsg(
                        'warn',
                        '(getLatestVersion_FromGit) Could not get the latest commit from github'
                    )
                    logmsg('debug', 'git error for %s: %s' % (url, errmsg))
                    latest_version = 'Not_Available_From_GitHUB'

    return latest_version
Exemplo n.º 8
0
def getCommitDifferenceFromGit():
    commits = -1
    # Takes current latest version value and trys to diff it with the latest
    # version in the current branch.
    commit_list = ''
    if lazylibrarian.LATEST_VERSION == 'Not_Available_From_GitHUB':
        commits = 0  # don't report a commit diff as we don't know anything
    if lazylibrarian.CURRENT_VERSION and commits != 0:
        logger.info(
            '[VersionCheck] -  Comparing currently installed version with latest github version'
        )
        url = 'https://api.github.com/repos/%s/LazyLibrarian/compare/%s...%s' % (
            lazylibrarian.GIT_USER, lazylibrarian.CURRENT_VERSION,
            lazylibrarian.LATEST_VERSION)
        logger.debug(
            '(getCommitDifferenceFromGit) -  Check for differences between local & repo by [%s]'
            % url)

        try:
            result = urllib2.urlopen(url, timeout=30).read()

            try:
                logger.debug('JSONDecode url')
                git = simplejson.JSONDecoder().decode(result)
                logger.debug('pull total_commits from json object')
                commits = git['total_commits']

                logger.debug(
                    '(getCommitDifferenceFromGit) -  GitHub reports as follows Status [%s] - Ahead [%s] - Behind [%s] - Total Commits [%s]'
                    % (git['status'], git['ahead_by'], git['behind_by'],
                       git['total_commits']))

                if git['total_commits'] > 0:
                    messages = []
                    for item in git['commits']:
                        messages.insert(0, item['commit']['message'])
                    for line in messages:
                        commit_list = "%s\n%s" % (commit_list, line)
            except Exception:
                logger.warn(
                    '(getCommitDifferenceFromGit) -  could not get difference status from GitHub'
                )

        except Exception:
            logger.warn(
                '(getCommitDifferenceFromGit) -  Could not get commits behind from github. Can happen if you have a local commit not pushed to repo or no connection to github'
            )

        if commits > 1:
            logger.info(
                '[VersionCheck] -  New version is available. You are %s commits behind'
                % commits)
        elif commits == 1:
            logger.info(
                '[VersionCheck] -  New version is available. You are one commit behind'
            )
        elif commits == 0:
            logger.info('[VersionCheck] -  lazylibrarian is up to date ')
        elif commits == -1:
            logger.info(
                '[VersionCheck] -  You are running an unknown version of lazylibrarian. Run the updater to identify your version'
            )

    elif lazylibrarian.LATEST_VERSION == 'Not_Available_From_GitHUB':
        commit_list = 'Unable to get latest version from GitHub'
        logger.info(commit_list)
    else:
        logger.info(
            'You are running an unknown version of lazylibrarian. Run the updater to identify your version'
        )

    logger.debug(
        '(getCommitDifferenceFromGit) - exiting with commit value of [%s]' %
        commits)
    # lazylibrarian.COMMITS_BEHIND = commits
    return commits, commit_list
Exemplo n.º 9
0
    def _update_cache(self):
        '''
        Since we call the same url for both info and artwork, we'll update both at the same time
        '''
        myDB = db.DBConnection()

        # Since lastfm uses release ids rather than release group ids for albums, we have to do a artist + album search for albums
        if self.id_type == 'artist':

            params = {
                "method": "artist.getInfo",
                "api_key": lastfm_apikey,
                "mbid": self.id,
                "format": "json"
            }

            url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(
                params)
            logger.debug('Retrieving artist information from: ' + url)

            try:
                result = urllib2.urlopen(url, timeout=20).read()
            except:
                logger.warn('Could not open url: ' + url)
                return

            if result:

                try:
                    data = simplejson.JSONDecoder().decode(result)
                except:
                    logger.warn('Could not parse data from url: ' + url)
                    return
                try:
                    self.info_summary = data['artist']['bio']['summary']
                except Exception:
                    logger.debug('No artist bio summary found on url: ' + url)
                    self.info_summary = None
                try:
                    self.info_content = data['artist']['bio']['content']
                except Exception:
                    logger.debug('No artist bio found on url: ' + url)
                    self.info_content = None
                try:
                    image_url = data['artist']['image'][-1]['#text']
                except Exception:
                    logger.debug('No artist image found on url: ' + url)
                    image_url = None

                thumb_url = self._get_thumb_url(data)
                if not thumb_url:
                    logger.debug('No artist thumbnail image found on url: ' +
                                 url)

        else:

            dbartist = myDB.action(
                'SELECT ArtistName, AlbumTitle FROM albums WHERE AlbumID=?',
                [self.id]).fetchone()

            params = {
                "method": "album.getInfo",
                "api_key": lastfm_apikey,
                "artist": dbartist['ArtistName'].encode('utf-8'),
                "album": dbartist['AlbumTitle'].encode('utf-8'),
                "format": "json"
            }

            url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(
                params)

            logger.debug('Retrieving artist information from: ' + url)
            try:
                result = urllib2.urlopen(url, timeout=20).read()
            except:
                logger.warn('Could not open url: ' + url)
                return

            if result:
                try:
                    data = simplejson.JSONDecoder().decode(result)
                except:
                    logger.warn('Could not parse data from url: ' + url)
                    return
                try:
                    self.info_summary = data['album']['wiki']['summary']
                except Exception:
                    logger.debug('No album summary found from: ' + url)
                    self.info_summary = None
                try:
                    self.info_content = data['album']['wiki']['content']
                except Exception:
                    logger.debug('No album infomation found from: ' + url)
                    self.info_content = None
                try:
                    image_url = data['album']['image'][-1]['#text']
                except Exception:
                    logger.debug('No album image link found on url: ' + url)
                    image_url = None

                thumb_url = self._get_thumb_url(data)

                if not thumb_url:
                    logger.debug('No album thumbnail image found on url: ' +
                                 url)

        #Save the content & summary to the database no matter what if we've opened up the url
        if self.id_type == 'artist':
            controlValueDict = {"ArtistID": self.id}
        else:
            controlValueDict = {"ReleaseGroupID": self.id}

        newValueDict = {
            "Summary": self.info_summary,
            "Content": self.info_content,
            "LastUpdated": helpers.today()
        }

        myDB.upsert("descriptions", newValueDict, controlValueDict)

        # Save the image URL to the database
        if image_url:
            if self.id_type == 'artist':
                myDB.action('UPDATE artists SET ArtworkURL=? WHERE ArtistID=?',
                            [image_url, self.id])
            else:
                myDB.action('UPDATE albums SET ArtworkURL=? WHERE AlbumID=?',
                            [image_url, self.id])

        # Save the thumb URL to the database
        if thumb_url:
            if self.id_type == 'artist':
                myDB.action('UPDATE artists SET ThumbURL=? WHERE ArtistID=?',
                            [thumb_url, self.id])
            else:
                myDB.action('UPDATE albums SET ThumbURL=? WHERE AlbumID=?',
                            [thumb_url, self.id])

        # Should we grab the artwork here if we're just grabbing thumbs or info?? Probably not since the files can be quite big
        if image_url and self.query_type == 'artwork':
            try:
                artwork = urllib2.urlopen(image_url, timeout=20).read()
            except Exception, e:
                logger.error('Unable to open url "' + image_url +
                             '". Error: ' + str(e))
                artwork = None

            if artwork:

                # Make sure the artwork dir exists:
                if not os.path.isdir(self.path_to_art_cache):
                    try:
                        os.makedirs(self.path_to_art_cache)
                    except Exception, e:
                        logger.error(
                            'Unable to create artwork cache dir. Error: ' +
                            str(e))
                        self.artwork_errors = True
                        self.artwork_url = image_url

                #Delete the old stuff
                for artwork_file in self.artwork_files:
                    try:
                        os.remove(artwork_file)
                    except:
                        logger.error('Error deleting file from the cache: ' +
                                     artwork_file)

                ext = os.path.splitext(image_url)[1]

                artwork_path = os.path.join(
                    self.path_to_art_cache,
                    self.id + '.' + helpers.today() + ext)
                try:
                    f = open(artwork_path, 'wb')
                    f.write(artwork)
                    f.close()
                except Exception, e:
                    logger.error('Unable to write to the cache dir: ' + str(e))
                    self.artwork_errors = True
                    self.artwork_url = image_url
Exemplo n.º 10
0
    def get_image_links(self, ArtistID=None, AlbumID=None):
        '''
        Here we're just going to open up the last.fm url, grab the image links and return them
        Won't save any image urls, or save the artwork in the cache. Useful for search results, etc.
        '''
        if ArtistID:

            self.id_type = 'artist'

            params = {
                "method": "artist.getInfo",
                "api_key": lastfm_apikey,
                "mbid": ArtistID,
                "format": "json"
            }

            url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(
                params)
            logger.debug('Retrieving artist information from: ' + url)

            try:
                result = urllib2.urlopen(url, timeout=20).read()
            except:
                logger.warn('Could not open url: ' + url)
                return

            if result:

                try:
                    data = simplejson.JSONDecoder().decode(result)
                except:
                    logger.warn('Could not parse data from url: ' + url)
                    return

                try:
                    image_url = data['artist']['image'][-1]['#text']
                except Exception:
                    logger.debug('No artist image found on url: ' + url)
                    image_url = None

                thumb_url = self._get_thumb_url(data)
                if not thumb_url:
                    logger.debug('No artist thumbnail image found on url: ' +
                                 url)

        else:

            self.id_type = 'album'

            params = {
                "method": "album.getInfo",
                "api_key": lastfm_apikey,
                "mbid": AlbumID,
                "format": "json"
            }

            url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(
                params)
            logger.debug('Retrieving album information from: ' + url)

            try:
                result = urllib2.urlopen(url, timeout=20).read()
            except:
                logger.warn('Could not open url: ' + url)
                return

            if result:

                try:
                    data = simplejson.JSONDecoder().decode(result)
                except:
                    logger.warn('Could not parse data from url: ' + url)
                    return

                try:
                    image_url = data['artist']['image'][-1]['#text']
                except Exception:
                    logger.debug('No artist image found on url: ' + url)
                    image_url = None

                thumb_url = self._get_thumb_url(data)

                if not thumb_url:
                    logger.debug('No artist thumbnail image found on url: ' +
                                 url)

        image_dict = {'artwork': image_url, 'thumbnail': thumb_url}
        return image_dict
Exemplo n.º 11
0
        content = {'Content-Type': 'application/json', 'Content-Length': len(data)}

        req = urllib2.Request(host+'/jsonrpc', data, content)

        if self.username and self.password:
            base64string = base64.encodestring('%s:%s' % (self.username, self.password)).replace('\n', '')
            req.add_header("Authorization", "Basic %s" % base64string)

        try:
            handle = urllib2.urlopen(req)
        except Exception, e:
            logger.warn('Error opening XBMC url: %s' % e)
            return

        response = simplejson.JSONDecoder().decode(handle.read())

        try:
            return response[0]['result']
        except:
            logger.warn('XBMC returned error: %s' % response[0]['error'])
            return

    def update(self):
                    
        # From what I read you can't update the music library on a per directory or per path basis
        # so need to update the whole thing

        hosts = [x.strip() for x in self.hosts.split(',')]

        for host in hosts:
Exemplo n.º 12
0
        return parse_unquote(atom.replace('+', ' '),
                             encoding=encoding,
                             errors=errors)
except ImportError:
    # Python 2
    from urllib import unquote as parse_unquote

    def unquote_qs(atom, encoding, errors='strict'):
        return parse_unquote(atom.replace('+', ' ')).decode(encoding, errors)


try:
    # Prefer simplejson, which is usually more advanced than the builtin
    # module.
    import lib.simplejson as json
    json_decode = json.JSONDecoder().decode
    _json_encode = json.JSONEncoder().iterencode
except ImportError:
    if sys.version_info >= (2, 6):
        # Python >=2.6 : json is part of the standard library
        import json
        json_decode = json.JSONDecoder().decode
        _json_encode = json.JSONEncoder().iterencode
    else:
        json = None

        def json_decode(s):
            raise ValueError('No JSON library is available')

        def _json_encode(s):
            raise ValueError('No JSON library is available')