示例#1
0
def process_file(dirname, filename):
    """
    Process a file with guessit and construct the wanted item.
    """

    log.info('Processing file: %s', filename)
    file_path = os.path.join(dirname, filename)

    # Check minimal video file size if needed
    if autosubliminal.MINVIDEOFILESIZE:
        file_size = os.path.getsize(file_path)
        # MINVIDEOFILESIZE is size in MB
        if file_size < autosubliminal.MINVIDEOFILESIZE * 1024 * 1024:
            log.warning('File size (%s) is lower than %sMB, skipping',
                        humanize_bytes(file_size),
                        autosubliminal.MINVIDEOFILESIZE)
            return None

    # Guess and create wanted item from guess
    wanted_item = WantedItem.from_guess(_guess(filename))
    if wanted_item is None:
        # Fallback to guess on full path
        wanted_item = WantedItem.from_guess(_guess(file_path))
    log.debug('WantedItem from guess: %r', wanted_item)

    # Enrich wanted item
    if wanted_item is not None:
        _enrich_wanted_item(wanted_item, file_path)

    return wanted_item
def process_file(dirname, filename):
    """
    Process a file with guessit and construct the wanted item.
    """

    log.info('Processing file: %s', filename)
    file_path = os.path.join(dirname, filename)

    # Check minimal video file size if needed
    if autosubliminal.MINVIDEOFILESIZE:
        file_size = os.path.getsize(file_path)
        # MINVIDEOFILESIZE is size in MB
        if file_size < autosubliminal.MINVIDEOFILESIZE * 1024 * 1024:
            log.warning('File size (%s) is lower than %sMB, skipping', humanize_bytes(file_size),
                        autosubliminal.MINVIDEOFILESIZE)
            return None

    # Guess and create wanted item from guess
    wanted_item = WantedItem.from_guess(_guess(filename))
    if wanted_item is None:
        # Fallback to guess on full path
        wanted_item = WantedItem.from_guess(_guess(file_path))
    log.debug('WantedItem from guess: %r', wanted_item)

    # Enrich wanted item
    if wanted_item is not None:
        _enrich_wanted_item(wanted_item, file_path)

    return wanted_item
示例#3
0
def test_count_wanted_queue_items():
    wanted_item_1 = WantedItem(type='movie', title='title1')
    wanted_item_2 = WantedItem(type='episode', title='title2')
    autosubliminal.WANTEDQUEUE = [wanted_item_1, wanted_item_2]
    assert count_wanted_queue_items() == 2
    assert count_wanted_queue_items(item_type='movie') == 1
    assert count_wanted_queue_items(item_type='episode') == 1
    assert count_wanted_queue_items(item_type='video') == 0
示例#4
0
def test_display_item_title():
    wanted_item_1 = WantedItem(title='title1')
    wanted_item_2 = WantedItem(title='title2', year=2016)
    wanted_item_empty = WantedItem()
    assert display_item_title(wanted_item_1) == 'title1'
    assert display_item_title(wanted_item_1, uppercase=True) == 'TITLE1'
    assert display_item_title(wanted_item_2) == 'title2 (2016)'
    assert display_item_title(wanted_item_2, uppercase=True) == 'TITLE2 (2016)'
    assert display_item_title(wanted_item_empty) == 'N/A'
    assert display_item_title(wanted_item_empty, default_value='default') == 'default'
    assert display_item_title(wanted_item_empty, default_value='default', uppercase=True) == 'DEFAULT'
示例#5
0
def test_wanted_item_copy_to():
    wanted_item_1 = WantedItem(type='episode',
                               title='titl1',
                               season=1,
                               episode=1)
    wanted_item_2 = WantedItem(type='episode',
                               title='title2',
                               season=2,
                               episode=2,
                               codec=2)
    wanted_item_1.copy_to(wanted_item_2)
    assert wanted_item_1 == wanted_item_2
示例#6
0
def test_compare_wanted_items():
    wanted_item_1 = WantedItem(type='episode',
                               title='testequal',
                               season=1,
                               episode=1)
    wanted_item_2 = WantedItem(type='episode',
                               title='testequal',
                               season=1,
                               episode=1)
    wanted_item_3 = WantedItem(type='episode',
                               title='testdifferent',
                               season=1,
                               episode=1)
    assert wanted_item_1 == wanted_item_2
    assert wanted_item_1 != wanted_item_3
    assert wanted_item_2 != wanted_item_3
示例#7
0
def test_wanted_item_trim_release_group():
    wanted_item_1 = WantedItem(type='episode',
                               title='test',
                               season=1,
                               episode=1,
                               releasegrp='KILLERS[rarbg]')
    assert wanted_item_1.releasegrp == 'KILLERS'
示例#8
0
def test_wanted_item_with_multi_episode():
    # Example file: Marvels.Agents.of.S.H.I.E.L.D.S05E01-E02.720p.HDTV.x264-AVS.mkv
    wanted_item_1 = WantedItem(type='episode',
                               title='test',
                               season=1,
                               episode=[1, 2])
    assert wanted_item_1.episode == [1, 2]
示例#9
0
def test_wanted_item_with_multi_codec():
    # Example file: Code.37.S03E02.NL.VLAAMS.720p.HDTV.x264-SHOWGEMiST_xvid.avi
    wanted_item_1 = WantedItem(type='episode',
                               title='test',
                               season=1,
                               episode=1,
                               codec=['H.264', 'Xvid'])
    assert wanted_item_1.codec == ['H.264', 'Xvid']
示例#10
0
def test_refine_movie():
    movie = Movie(name=os.path.join(resources_dir, 'Refine.Movie.mkv'), title='Refine')
    wanted_item = WantedItem(type='movie', title='Title', year=2018, source='Source', quality='Resolution',
                             codec='Codec', releasegrp='Group')
    refine(movie, wanted_item)
    assert movie.title == 'Title'
    assert movie.year == 2018
    assert movie.source == 'Source'
    assert movie.resolution == 'Resolution'
    assert movie.video_codec == 'Codec'
    assert movie.release_group == 'Group'
示例#11
0
def test_refine_episode():
    episode = Episode(name=os.path.join(resources_dir, 'Refine.Episode.mkv'), series='Refine', season=0, episode=0)
    wanted_item = WantedItem(type='episode', title='Series', year=2018, season=1, episode=[1, 2], source='Source',
                             quality='Resolution', codec='Codec', releasegrp='Group')
    refine(episode, wanted_item)
    assert episode.series == 'Series'
    assert episode.year == 2018
    assert episode.season == 1
    assert episode.episode == 1  # Only first episode is kept when refining
    assert episode.source == 'Source'
    assert episode.resolution == 'Resolution'
    assert episode.video_codec == 'Codec'
    assert episode.release_group == 'Group'
示例#12
0
def test_display_item_name():
    wanted_item_1 = WantedItem(title='title1')
    wanted_item_2 = WantedItem(title='title2', year=2016, type='mmovie')
    wanted_item_3 = WantedItem(title='title3', type='episode', season=1, episode=1)
    wanted_item_4 = WantedItem(title='title4', year=2016, type='episode', season=1, episode=1)
    wanted_item_5 = WantedItem(title='title5', year=2016, type='episode', season=1, episode=[1, 2])
    wanted_item_empty = WantedItem()
    assert display_item_name(wanted_item_1) == 'title1'
    assert display_item_name(wanted_item_1, uppercase=True) == 'TITLE1'
    assert display_item_name(wanted_item_2) == 'title2 (2016)'
    assert display_item_name(wanted_item_2, uppercase=True) == 'TITLE2 (2016)'
    assert display_item_name(wanted_item_3) == 'title3 S01E01'
    assert display_item_name(wanted_item_3, uppercase=True) == 'TITLE3 S01E01'
    assert display_item_name(wanted_item_4) == 'title4 (2016) S01E01'
    assert display_item_name(wanted_item_4, uppercase=True) == 'TITLE4 (2016) S01E01'
    assert display_item_name(wanted_item_5) == 'title5 (2016) S01E01-E02'
    assert display_item_name(wanted_item_5, uppercase=True) == 'TITLE5 (2016) S01E01-E02'
    assert display_item_name(wanted_item_empty) == 'N/A'
    assert display_item_name(wanted_item_empty, default_value='default') == 'default'
    assert display_item_name(wanted_item_empty, default_value='default', uppercase=True) == 'DEFAULT'
示例#13
0
# coding=utf-8

from autosubliminal.core.item import DownloadItem, WantedItem
from autosubliminal.notifiers.pushbullet import PushbulletNotifier

notifier_name = 'Pushbullet'

download_item = DownloadItem(WantedItem())
download_item.videopath = 'path/to/video'
download_item.subtitlepath = 'path/to/subtitle'
download_item.downlang = 'en'
download_item.provider = 'provider'


def test_pushbullet_disabled():
    notifier = PushbulletNotifier()
    assert notifier.name == notifier_name
    assert notifier.notify('test') is False
    assert notifier.notify_download(download_item) is False


def test_pushbullet_exception(monkeypatch):
    monkeypatch.setattr('autosubliminal.NOTIFYPUSHBULLET', True)
    monkeypatch.setattr('autosubliminal.PUSHBULLETAPI',
                        '123456')  # Invalid api key
    notifier = PushbulletNotifier()
    assert notifier.name == notifier_name
    assert notifier.notify('test') is False
    assert notifier.notify_download(download_item) is False

示例#14
0
def test_notifiers_notify_download(mocker):
    mocker.patch('autosubliminal.notifiers.generic.BaseNotifier.notify_download', return_value=True)
    assert autosubliminal.notifiers.notify_download(DownloadItem(WantedItem())) is True
示例#15
0
def test_skip_refine():
    movie = Movie(name=os.path.join(resources_dir, 'Refine.Movie.Not.Exists.mkv'), title='Refine')
    wanted_item = WantedItem(type='movie', title='Title')
    refine(movie, wanted_item)
    assert movie.title == 'Refine'
示例#16
0
# coding=utf-8

import datetime

from autosubliminal.core.item import WantedItem

wanted_item = WantedItem()
wanted_item.timestamp = '2018-01-01 12:30:01'


def test_compare_wanted_items():
    wanted_item_1 = WantedItem(type='episode',
                               title='testequal',
                               season=1,
                               episode=1)
    wanted_item_2 = WantedItem(type='episode',
                               title='testequal',
                               season=1,
                               episode=1)
    wanted_item_3 = WantedItem(type='episode',
                               title='testdifferent',
                               season=1,
                               episode=1)
    assert wanted_item_1 == wanted_item_2
    assert wanted_item_1 != wanted_item_3
    assert wanted_item_2 != wanted_item_3


def test_wanted_item_with_multi_episode():
    # Example file: Marvels.Agents.of.S.H.I.E.L.D.S05E01-E02.720p.HDTV.x264-AVS.mkv
    wanted_item_1 = WantedItem(type='episode',
示例#17
0
def test_wanted_item_copy_to():
    wanted_item_1 = WantedItem(type='episode', title='titl1', season=1, episode=1)
    wanted_item_2 = WantedItem(type='episode', title='title2', season=2, episode=2, codec=2)
    wanted_item_1.copy_to(wanted_item_2)
    assert wanted_item_1 == wanted_item_2
示例#18
0
# coding=utf-8

import datetime

from autosubliminal.core.item import WantedItem

wanted_item = WantedItem()
wanted_item.timestamp = '2018-01-01 12:30:01'


def test_compare_wanted_items():
    wanted_item_1 = WantedItem(type='episode', title='testequal', season=1, episode=1)
    wanted_item_2 = WantedItem(type='episode', title='testequal', season=1, episode=1)
    wanted_item_3 = WantedItem(type='episode', title='testdifferent', season=1, episode=1)
    assert wanted_item_1 == wanted_item_2
    assert wanted_item_1 != wanted_item_3
    assert wanted_item_2 != wanted_item_3


def test_wanted_item_with_multi_episode():
    # Example file: Marvels.Agents.of.S.H.I.E.L.D.S05E01-E02.720p.HDTV.x264-AVS.mkv
    wanted_item_1 = WantedItem(type='episode', title='test', season=1, episode=[1, 2])
    assert wanted_item_1.episode == [1, 2]


def test_wanted_item_with_multi_sources():
    # Example file: Inferno.2016.1080p.WEB.BluRay.x264-[GROUP1.AG].mp4
    wanted_item_1 = WantedItem(type='movie', title='test', source=['Web', 'Blu-ray'])
    assert wanted_item_1.source == ['Web', 'Blu-ray']

示例#19
0
def test_wanted_item_with_multi_sources():
    # Example file: Inferno.2016.1080p.WEB.BluRay.x264-[GROUP1.AG].mp4
    wanted_item_1 = WantedItem(type='movie',
                               title='test',
                               source=['Web', 'Blu-ray'])
    assert wanted_item_1.source == ['Web', 'Blu-ray']