class Lyrics:
    """
        Fetches, cleans and saves lyrics.
    """

    def __init__( self, Addon, prefetch ):
        # set our Addon class
        self.Addon = Addon
        # is this prefetch
        self.prefetch = prefetch
        # info regex
        self.clean_info_regex = re.compile( "\[[a-z]+?:.*\]\s" )
        # lrc regex
        self.clean_lrc_lyrics_regex = re.compile( "\[([0-9]+):([0-9]+(?:\.[0-9]+)?)\](.*)" )
        # Overall timestamp adjustment in milliseconds regex
        self.timestamp_lrc_lyrics_regex = re.compile( "\[offset:([+-]*[0-9]+)\]" )
        # Website downloaded from regex
        self.website_regex = re.compile( "\[we:(.+)\]" )
        # set our scraper object
        self.scraper = Scraper( self.Addon, prefetch=self.prefetch )

    def get_lyrics( self, song ):
        try:
            # if embedded lyrics are found set them
            if ( xbmc.getInfoLabel( "MusicPlayer.Offset(%d).Lyrics" % ( self.prefetch, ) ) ):
                song.lyrics = unicode( xbmc.getInfoLabel( "MusicPlayer.Offset(%d).Lyrics" % ( self.prefetch, ) ), "UTF-8", "replace" )
                song.message = self.Addon.getLocalizedString( 30861 )
            # if cached lyrics are found set them
            else:
                # use httpapi for smb:// paths if xbox, with hack for change in xbmc so older revisions still work
                if ( song.lyrics_path.startswith( "smb://" ) and os.environ.get( "OS", "n/a" ) == "xbox" ):
                    song.lyrics = unicode( base64.standard_b64decode( xbmc.executehttpapi( "FileDownload(%s,bare)" % ( song.lyrics_path, ) ).split("\r\n\r\n")[ -1 ].strip( BOM_UTF8 ) ), "UTF-8" )
                else:
                    song.lyrics = unicode( open( song.lyrics_path, "r" ).read().strip( BOM_UTF8 ), "UTF-8" )
                # set cached message
                song.message = self.Addon.getLocalizedString( 30862 )
        except Exception, e:
            # no lyrics found, so fetch lyrics from internet
            self.scraper.fetch_lyrics( song )
            # if the search was successful save lyrics
            if ( song.status ):
                self.save_lyrics( song )
        # we need to clean lyrics in case they are lrc tagged
        self._clean_lyrics( song )
 def __init__( self, Addon, prefetch ):
     # set our Addon class
     self.Addon = Addon
     # is this prefetch
     self.prefetch = prefetch
     # info regex
     self.clean_info_regex = re.compile( "\[[a-z]+?:.*\]\s" )
     # lrc regex
     self.clean_lrc_lyrics_regex = re.compile( "\[([0-9]+):([0-9]+(?:\.[0-9]+)?)\](.*)" )
     # Overall timestamp adjustment in milliseconds regex
     self.timestamp_lrc_lyrics_regex = re.compile( "\[offset:([+-]*[0-9]+)\]" )
     # Website downloaded from regex
     self.website_regex = re.compile( "\[we:(.+)\]" )
     # set our scraper object
     self.scraper = Scraper( self.Addon, prefetch=self.prefetch )
示例#3
0
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program. If not, see <http://www.gnu.org/licenses/>.
#

from xbmcswift2 import Plugin
from resources.lib.scraper import Scraper

STRINGS = {'page': 30001}

plugin = Plugin()
scraper = Scraper()


@plugin.route('/')
def show_topics():
    topics = scraper.get_video_topics()
    items = [{
        'label':
        topic['title'],
        'path':
        plugin.url_for(endpoint='show_videos', topic_id=topic['id'], page='1')
    } for topic in topics]
    return plugin.finish(items)


@plugin.route('/videos/<topic_id>/<page>/')