示例#1
0
    def _rate_song(self):

        with DatabaseConn('music') as cursor_music:
            query = "SELECT rating FROM song WHERE idSong = ?"
            cursor_music.execute(query, (self.kodi_id, ))
            try:
                value = cursor_music.fetchone()[0]
                current_value = int(round(float(value), 0))
            except TypeError:
                pass
            else:
                new_value = dialog("numeric", 0, lang(30411),
                                   str(current_value))
                if new_value > -1:

                    new_value = int(new_value)
                    if new_value > 5:
                        new_value = 5

                    if settings('enableUpdateSongRating') == "true":
                        musicutils.updateRatingToFile(new_value,
                                                      self.api.get_file_path())

                    query = "UPDATE song SET rating = ? WHERE idSong = ?"
                    cursor_music.execute(query, (
                        new_value,
                        self.kodi_id,
                    ))
示例#2
0
    def delete_cached_artwork(cls, url):
        # Only necessary to remove and apply a new backdrop or poster
        with DatabaseConn('texture') as cursor_texture:
            try:
                cursor_texture.execute(
                    "SELECT cachedurl FROM texture WHERE url = ?", (url, ))
                cached_url = cursor_texture.fetchone()[0]

            except TypeError:
                log.info("Could not find cached url")

            except OperationalError:
                log.info("Database is locked. Skip deletion process.")

            else:  # Delete thumbnail as well as the entry
                thumbnails = xbmc.translatePath("special://thumbnails/%s" %
                                                cached_url).decode('utf-8')
                log.info("Deleting cached thumbnail: %s", thumbnails)
                xbmcvfs.delete(thumbnails)

                try:
                    cursor_texture.execute("DELETE FROM texture WHERE url = ?",
                                           (url, ))
                except OperationalError:
                    log.debug("Issue deleting url from cache. Skipping.")
示例#3
0
    def modify_playlist(self, item_ids):

        with DatabaseConn('emby') as cursor:
            emby_db = embydb.Embydb_Functions(cursor)

            log.info("---*** ADD TO PLAYLIST ***---")
            log.info("Items: %s", item_ids)

            playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)

            for item_id in item_ids:

                log.info("Adding %s to playlist", item_id)
                item = emby_db.getItem_byId(item_id)
                try:
                    db_id = item[0]
                    media_type = item[4]

                except TypeError:
                    # Item is not found in our database, add item manually
                    item = self.emby.getItem(item_id)
                    self.add_to_xbmc_playlist(playlist, item)

                else:  # Add to playlist
                    self.add_to_playlist(db_id, media_type)

            self.verify_playlist()

        return playlist
示例#4
0
    def delete_cache(cls):
        # Remove all existing textures first
        path = xbmc.translatePath('special://thumbnails/').decode('utf-8')
        if xbmcvfs.exists(path):
            dirs, ignore_files = xbmcvfs.listdir(path)
            for directory in dirs:
                ignore_dirs, files = xbmcvfs.listdir(path + directory)
                for file_ in files:

                    if os.path.supports_unicode_filenames:
                        filename = os.path.join(
                            path + directory.decode('utf-8'),
                            file_.decode('utf-8'))
                    else:
                        filename = os.path.join(
                            path.encode('utf-8') + directory, file_)

                    xbmcvfs.delete(filename)
                    log.debug("deleted: %s", filename)

        # remove all existing data from texture DB
        with DatabaseConn('texture') as cursor_texture:
            cursor_texture.execute(
                'SELECT tbl_name FROM sqlite_master WHERE type="table"')
            rows = cursor_texture.fetchall()
            for row in rows:
                table_name = row[0]
                if table_name != "version":
                    cursor_texture.execute("DELETE FROM " + table_name)
示例#5
0
    def _get_item_id(cls, kodi_id, item_type):

        item_id = None

        with DatabaseConn('emby') as cursor:
            emby_db = embydb.Embydb_Functions(cursor)
            db_item = emby_db.getItem_byKodiId(kodi_id, item_type)

        try:
            item_id = db_item[0]
        except TypeError:
            log.info("Could not retrieve item Id")

        return item_id
示例#6
0
    def _get_item_id(cls, kodi_id, item_type):

        item_id = xbmc.getInfoLabel('ListItem.Property(embyid)')

        if not item_id and kodi_id and item_type:

            with DatabaseConn('emby') as cursor:
                emby_db = embydb.Embydb_Functions(cursor)
                item = emby_db.getItem_byKodiId(kodi_id, item_type)
                try:
                    item_id = item[0]
                except TypeError:
                    pass

        return item_id
示例#7
0
    def play_all(self, item_ids, start_at):

        with DatabaseConn('emby') as cursor:
            emby_db = embydb.Embydb_Functions(cursor)

            player = xbmc.Player()
            playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
            playlist.clear()

            log.info("---*** PLAY ALL ***---")
            log.info("Items: %s and start at: %s", item_ids, start_at)

            started = False
            window('emby_customplaylist', value="true")

            if start_at:
                # Seek to the starting position
                window('emby_customplaylist.seektime', str(start_at))

            for item_id in item_ids:

                log.info("Adding %s to playlist", item_id)
                item = emby_db.getItem_byId(item_id)
                try:
                    db_id = item[0]
                    media_type = item[4]

                except TypeError:
                    # Item is not found in our database, add item manually
                    log.info(
                        "Item was not found in the database, manually adding item"
                    )
                    item = self.emby.getItem(item_id)
                    self.add_to_xbmc_playlist(playlist, item)

                else:  # Add to playlist
                    self.add_to_playlist(db_id, media_type)

                if not started:
                    started = True
                    player.play(playlist)

            self.verify_playlist()
示例#8
0
    def _cache_all_music_entries(self, pdialog):

        with DatabaseConn('music') as cursor_music:

            cursor_music.execute("SELECT url FROM art")
            result = cursor_music.fetchall()
            total = len(result)

            log.info("Image cache sync about to process %s images", total)

            count = 0
            for url in result:

                if pdialog.iscanceled():
                    break

                percentage = int((float(count) / float(total)) * 100)
                message = "%s of %s" % (count, total)
                pdialog.update(percentage, "%s %s" % (lang(33045), message))
                self.cache_texture(url[0])
                count += 1
def main():
    config = configparser.ConfigParser()
    config.read('config.ini')
    base_config = config['crawler']
    configure_logging(base_config.get('logfile', None),
                      log_level=int(base_config['loglevel']))
    couch_config = config['couchdb']

    with DatabaseConn(couch_config) as db:
        logger = logging.getLogger('tweet_crawler')

        crawler = TweetCrawler(config['twitter'],
                               BoundingBox(base_config['bbox']), db, logger)
        try:
            crawler.download_tweets()
        except KeyboardInterrupt:
            logger.info('interrupt received; disconnecting')
        except Exception as ex:
            logger.exception(ex)
        finally:
            crawler.disconnect()
            sys.exit(0)
示例#10
0
    def _cache_all_video_entries(self, pdialog):

        with DatabaseConn('video') as cursor_video:

            cursor_video.execute(
                "SELECT url FROM art WHERE media_type != 'actor'"
            )  # dont include actors
            result = cursor_video.fetchall()
            total = len(result)
            log.info("Image cache sync about to process %s images", total)
            cursor_video.close()

            count = 0
            for url in result:

                if pdialog.iscanceled():
                    break

                percentage = int((float(count) / float(total)) * 100)
                message = "%s of %s (%s)" % (count, total,
                                             len(self.image_cache_threads))
                pdialog.update(percentage, "%s %s" % (lang(33045), message))
                self.cache_texture(url[0])
                count += 1
示例#11
0
#
import configparser
import logging
import time
from database import DatabaseConn
from utils import configure_logging


if __name__ == '__main__':
    config = configparser.ConfigParser()
    config.read('config.ini')
    base_config = config['crawler']
    configure_logging('user_db.log', log_level=20)
    couch_config = config['couchdb']

    with DatabaseConn(couch_config) as db_conn:
        logger = logging.getLogger('create_user_db')
        with db_conn.bulk_db as bulk_db, db_conn.user_db as user_db, open('users.txt') as f:
            for doc in bulk_db:
                if type(doc['user']) is int:
                    if 'added_at' in doc:
                        logger.info('deleting misplaced user %d' % doc['user'])
                        doc.delete()
                else:
                    user = doc['user']['id']
                    doc_id = str(user)
                    if doc_id not in user_db:
                        logger.info('adding new user %d' % user)
                        user_db.create_document({
                            '_id': doc_id,
                            'user': user,
示例#12
0
    def itemsbyId(self, items, process, pdialog=None):
        # Process items by itemid. Process can be added, update, userdata, remove
        embycursor = self.embycursor
        kodicursor = self.kodicursor

        itemtypes = {

            'Movie': Movies,
            'BoxSet': Movies,
            'MusicVideo': MusicVideos,
            'Series': TVShows,
            'Season': TVShows,
            'Episode': TVShows,
            'MusicAlbum': Music,
            'MusicArtist': Music,
            'AlbumArtist': Music,
            'Audio': Music
        }

        update_videolibrary = False
        total = 0
        for item in items:
            total += len(items[item])

        if total == 0:
            return False

        #log.info("Processing %s: %s", process, items)
        if pdialog:
            pdialog.update(heading="Processing %s: %s items" % (process, total))

        # this is going to open a music connection even if it is not needed but
        # I feel that is better than trying to sort out the login yourself
        with DatabaseConn('music') as cursor_music:
            
            for itemtype in items:

                # Safety check
                if not itemtypes.get(itemtype):
                    # We don't process this type of item
                    continue

                itemlist = items[itemtype]
                if not itemlist:
                    # The list to process is empty
                    continue

                if itemtype in ('MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio'):
                    if self.music_enabled:
                        items_process = itemtypes[itemtype](embycursor, cursor_music, pdialog) # see note above
                    else:
                        # Music is not enabled, do not proceed with itemtype
                        continue
                else:
                    update_videolibrary = True
                    items_process = itemtypes[itemtype](embycursor, kodicursor, pdialog)

                if process == "added":
                    items_process.add_all(itemtype, itemlist)
                elif process == "remove":
                    items_process.remove_all(itemtype, itemlist)
                else:
                    process_items = self.emby.getFullItems(itemlist)
                    items_process.process_all(itemtype, process, process_items, total)


        return (True, update_videolibrary)