Exemplo n.º 1
0
 def test_tv_items_query(self):
     u = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              img_sm='/',
              new_episode=3,
              update_detail='w:1')
     tv2 = TV(name='b',
              serialized='1',
              img_sm='/',
              new_episode=4,
              update_detail='w:2')
     tv3 = TV(name='c',
              serialized='1',
              img_sm='/',
              new_episode=5,
              update_detail='w:3')
     db.session.add(u)
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.add(tv3)
     db.session.commit()
     c = Collection(user_id=u.id, name='w')
     c.add_tv(tv1)
     c.add_tv(tv2)
     c.add_tv(tv3)
     db.session.commit()
     r = c.tv_items_query()
     assert isinstance(r, BaseQuery)
     for i in r.all():
         assert i in c.tv_items_list()
Exemplo n.º 2
0
 def test_remove_tv(self):
     u = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              img_sm='/',
              new_episode=3,
              update_detail='w:1')
     tv2 = TV(name='b',
              serialized='1',
              img_sm='/',
              new_episode=4,
              update_detail='w:2')
     tv3 = TV(name='c',
              serialized='1',
              img_sm='/',
              new_episode=5,
              update_detail='w:3')
     db.session.add(u)
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.add(tv3)
     db.session.commit()
     c = Collection(user_id=u.id, name='w')
     c.add_tv(tv1)
     c.add_tv(tv2)
     c.add_tv(tv3)
     db.session.commit()
     c.remove_tv(tv1)
     db.session.commit()
     assert c.tv == '2;3'
     c.remove_tv(2)
     db.session.commit()
     assert c.tv == '3'
     with pytest.raises(ValueError):
         c.remove_tv('a')
Exemplo n.º 3
0
 def test_tv_items_list(self):
     u = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              img_sm='/',
              new_episode=3,
              update_detail='w:1')
     tv2 = TV(name='b',
              serialized='1',
              img_sm='/',
              new_episode=4,
              update_detail='w:2')
     tv3 = TV(name='c',
              serialized='1',
              img_sm='/',
              new_episode=5,
              update_detail='w:3')
     db.session.add(u)
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.add(tv3)
     db.session.commit()
     c = Collection(user_id=u.id, name='w')
     c.add_tv(tv1)
     c.add_tv(tv2)
     c.add_tv(tv3)
     db.session.commit()
     r = c.tv_items_list()
     r_id = [i.id for i in r]
     assert isinstance(r, list)
     assert tv1.id in r_id
     assert tv2.id in r_id
     assert tv3.id in r_id
     assert len(r) == 3
Exemplo n.º 4
0
Arquivo: tv.py Projeto: Zo0x/hedhes
def unwatch_tv(tmdb_id):
    tv = TV.query.filter_by(tmdb_id=tmdb_id).first()
    if tv is None:
        data = tmdb.get_tv(tmdb_id)
        if not data:
            return jsonify({'result': False, 'data': 'TV show not found'})
        tv = TV(data)
    tv.watching = False
    tv.save()
    return jsonify({'result': True, 'data': 'TV show updated: not watching'})
Exemplo n.º 5
0
 def test_on_change_watched(self):
     u = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              img_sm='/',
              episodes=4,
              new_episode=4,
              update_detail='w:1')
     db.session.add(u)
     db.session.add(tv1)
     db.session.commit()
     h = HistoryTV(user_id=u.id,
                   tv_id=tv1.id,
                   watched_episodes='1;2;3',
                   timestamp_watched=datetime.datetime(2019, 1, 1))
     db.session.add(h)
     db.session.commit()
     assert HistoryTV.watched_to(u, tv1) == '3'
     assert h.finished is False
     assert h.timestamp_watched < datetime.datetime.now()
     h.watched_episodes = '1;2;3;4'
     db.session.add(h)
     db.session.commit()
     assert HistoryTV.watched_to(u, tv1) == '4'
     assert h.finished is True
     assert datetime.datetime.now(
     ) - h.timestamp_watched < datetime.timedelta(days=1)
Exemplo n.º 6
0
def index():
    return render_template("overview.html",
                           title='Overview',
                           heading='Overview',
                           search_form=SearchForm(),
                           recent_movies=Movie.recent_movies(),
                           recent_tv=TV.recent_tv(),
                           refreshing=Library.refreshing_all())
Exemplo n.º 7
0
Arquivo: tv.py Projeto: Zo0x/hedhes
def refresh_tv(tmdb_id):
    tv = TV.query.filter_by(tmdb_id=tmdb_id).first()
    if tv is None:
        data = tmdb.get_tv(tmdb_id)
        if not data:
            return jsonify({'result': False, 'data': 'TV show not found'})
        tv = TV(data)
    Library.refresh_tv_item(tv)
    return jsonify({'result': True, 'data': 'TV show refresh scheduled'})
Exemplo n.º 8
0
Arquivo: tv.py Projeto: Zo0x/hedhes
def save_tv(tmdb_id):
    tv = TV.factory(tmdb_id=tmdb_id)
    if tv is None:
        flash('TV show not found')
        return redirect('/')
    form = TVSettingsForm()
    if form.validate_on_submit():
        tv.search_quality = form.quality.data
        tv.save()
        flash('TV show data saved')
    return redirect('/tv/' + tmdb_id)
Exemplo n.º 9
0
Arquivo: tv.py Projeto: Zo0x/hedhes
def research_tv(tmdb_id):
    tv = TV.query.filter_by(tmdb_id=tmdb_id).first()
    if tv is None:
        data = tmdb.get_tv(tmdb_id)
        if not data:
            return jsonify({
                'result': False,
                'data': 'TV show manual search scheduled'
            })
        tv = TV(data)
    return jsonify({'result': True, 'data': 'TV show updated'})
Exemplo n.º 10
0
 def test_watched_ep_to_list(self):
     u = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              img_sm='/',
              new_episode=3,
              update_detail='w:1')
     db.session.add(u)
     db.session.add(tv1)
     db.session.commit()
     h = HistoryTV(user_id=u.id, tv_id=tv1.id, watched_episodes='1;2;3;4;5')
     assert h.watched_ep_to_list == ['1', '2', '3', '4', '5']
Exemplo n.º 11
0
 def test_is_finished(self):
     u = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              img_sm='/',
              new_episode=4,
              update_detail='w:1')
     tv2 = TV(name='b',
              serialized='1',
              img_sm='/',
              new_episode=4,
              update_detail='w:2')
     db.session.add(u)
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.commit()
     h = HistoryTV(user_id=u.id, tv_id=tv1.id, watched_episodes='1;2;3;4;5')
     db.session.add(h)
     db.session.commit()
     assert HistoryTV.is_finished(u, tv1) is True
     assert HistoryTV.is_finished(u, tv2) is False
Exemplo n.º 12
0
 def test_unsubscribe_tv(self):
     u = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              tv_type='剧情',
              country='中国',
              tv_release='2018-8-9')
     tv2 = TV(name='b',
              serialized='2',
              tv_type='戏剧',
              country='加拿大',
              tv_release='2015-8-9')
     db.session.add(u)
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.commit()
     u.subscribe_tv(tv1)
     db.session.commit()
     assert u.tv_is_subscribed(tv1) is True
     assert u.unsubscribe_tv(tv2) is False
     assert u.unsubscribe_tv(tv1) is True
     assert Subscription.query.first() is None
     assert TV.query.first() is not None
     assert User.query.first() is not None
Exemplo n.º 13
0
 def test_subscribe_tv(self):
     u1 = User(username='******', password='******', email='*****@*****.**')
     u2 = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              tv_type='剧情',
              country='中国',
              tv_release='2018-8-9')
     tv2 = TV(name='b',
              serialized='2',
              tv_type='戏剧',
              country='加拿大',
              tv_release='2015-8-9')
     db.session.add(u1)
     db.session.add(u2)
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.commit()
     u1.subscribe_tv(tv1)
     db.session.commit()
     assert u1.tv_is_subscribed(tv1) is True
     assert u1.tv_is_subscribed(tv2) is False
     assert u2.tv_is_subscribed(tv1) is False
     assert u1.subscribed_tv.filter_by(tv_id=tv1.id).first() is not None
Exemplo n.º 14
0
 def test_contains(self):
     u = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              img_sm='/',
              new_episode=3,
              update_detail='w:1')
     db.session.add(u)
     db.session.add(tv1)
     db.session.commit()
     c = Collection(user_id=u.id, name='w')
     c.add_tv(tv1)
     db.session.commit()
     assert c.contains(1) is True
     assert c.contains(tv1) is True
     assert c.contains(33) is False
     assert c.contains('a') is False
Exemplo n.º 15
0
 def test_tv_category(self):
     tv1 = TV(name='a',
              serialized='1',
              tv_type='剧情',
              country='中国',
              tv_release='2018-8-9')
     tv2 = TV(name='b',
              serialized='2',
              tv_type='戏剧',
              country='加拿大',
              tv_release='2015-8-9')
     tv3 = TV(name='c',
              serialized='1',
              tv_type='言情/古装',
              country='中国',
              tv_release='2018-8-9')
     tv4 = TV(name='d',
              serialized='2',
              tv_type='纪录片',
              country='中国',
              tv_release='2014-8-9')
     tv5 = TV(name='e',
              serialized='1',
              tv_type='剧情',
              country='日本',
              tv_release='2013-8-9')
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.add(tv3)
     db.session.add(tv4)
     db.session.add(tv5)
     db.session.commit()
     assert len(TV.tv_category(1, '剧情', '中国', 2018).all()) == 1
     assert len(TV.tv_category(1).all()) == 3
     assert len(TV.tv_category(country='日本').all()) == 1
     assert len(TV.tv_category(year='2019').all()) == 0
Exemplo n.º 16
0
Arquivo: tv.py Projeto: Zo0x/hedhes
def tvp(tmdb_id):
    tv = TV.query.filter_by(tmdb_id=tmdb_id).first()
    if tv is None:
        data = tmdb.get_tv(tmdb_id)
        if not data:
            flash('TV show %s not found.' % tmdb_id)
            return redirect('/')
        tv = TV(data)
    imdb = 'http://www.dereferer.org/?' + urllib.parse.quote_plus(
        'http://www.imdb.com/title/' + tv.imdb_id)
    settings_form = TVSettingsForm()
    settings_form.quality.data = tv.search_quality
    return render_template('tv/view.html',
                           title=tv.title,
                           heading=tv.title,
                           media=tv,
                           search_form=SearchForm(),
                           settings_form=settings_form,
                           imdb_link=imdb,
                           refreshing=Library.refreshing_tv(tmdb_id))
Exemplo n.º 17
0
Arquivo: tv.py Projeto: Zo0x/hedhes
def add_tv(tmdb_id):
    data = tmdb.get_tv(tmdb_id)
    if not data:
        return jsonify({'result': False, 'data': 'TV show not found'})
    tv = TV.query.filter_by(tmdb_id=tmdb_id).first()
    if tv is None:
        tv = TV(data)
    tv.in_library = True
    tv.offline = True
    tv.added = datetime.now()
    tv.save()
    for season in data['seasons']:
        s = tmdb.get_tv_season(tmdb_id, season['season_number'])
        if s is not None:
            tvs = TVSeason(tv.id, s['season_number'])
            tvs.populate(s)
            tvs.save()
            for episode in s['episodes']:
                eps = TVEpisode(tv.id, tvs.id)
                eps.populate(episode)
                eps.save()
    return jsonify({'result': True, 'data': 'TV show added to library'})
Exemplo n.º 18
0
    def test_generate_categories(self):
        tv1 = TV(name='a',
                 serialized='1',
                 tv_type='剧情',
                 country='中国',
                 tv_release='2018-8-9')
        tv2 = TV(name='b',
                 serialized='2',
                 tv_type='戏剧',
                 country='加拿大',
                 tv_release='2015-8-9')
        tv3 = TV(name='c',
                 serialized='1',
                 tv_type='言情/古装',
                 country='中国',
                 tv_release='2018-8-9')
        tv4 = TV(name='d',
                 serialized='2',
                 tv_type='纪录片',
                 country='中国',
                 tv_release='2014-8-9')
        tv5 = TV(name='e',
                 serialized='1',
                 tv_type='剧情',
                 country='日本',
                 tv_release='2013-8-9')
        db.session.add(tv1)
        db.session.add(tv2)
        db.session.add(tv3)
        db.session.add(tv4)
        db.session.add(tv5)
        db.session.commit()
        r = TV.generate_categories()

        assert len(r['tv_types']) == 6
        assert '剧情' in r['tv_types']
        assert len(r['serialized']) == 4
        assert '1' in r['serialized']
        assert len(r['country']) == 4
        assert '中国' in r['country']
        assert len(r['year']) == 5
        assert '2018' in r['year']
        assert '' in r['year']
Exemplo n.º 19
0
 def test_get_timeline_json(self):
     tv1 = TV(name='a',
              serialized='1',
              img_sm='/',
              new_episode=3,
              update_detail='w:1')
     tv2 = TV(name='b',
              serialized='1',
              img_sm='/',
              new_episode=4,
              update_detail='w:2')
     tv3 = TV(name='c',
              serialized='1',
              img_sm='/',
              new_episode=5,
              update_detail='w:3')
     tv4 = TV(name='d',
              serialized='1',
              img_sm='/',
              new_episode=6,
              update_detail='w:4')
     tv5 = TV(name='e',
              serialized='1',
              img_sm='/',
              new_episode=7,
              update_detail='w:5')
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.add(tv3)
     db.session.add(tv4)
     db.session.add(tv5)
     db.session.commit()
     r = TV.get_timeline_json()
     now = datetime.datetime.now()
     m = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e'}
     for i in range(-7, 7):
         date = now + datetime.timedelta(days=i)
         week = date.weekday()
         assert r[i + 7]['date'] == str(date.month) + '-' + str(date.day)
         if week in m:
             assert r[i + 7]['items'][0]['name'] == m[week]
Exemplo n.º 20
0
 def test_subscribed_tv_order_by_watched(self):
     u1 = User(username='******', password='******', email='*****@*****.**')
     u2 = User(username='******', password='******', email='*****@*****.**')
     tv1 = TV(name='a',
              serialized='1',
              tv_type='剧情',
              country='中国',
              tv_release='2018-8-9')
     tv2 = TV(name='b',
              serialized='2',
              tv_type='戏剧',
              country='加拿大',
              tv_release='2015-8-9')
     tv3 = TV(name='c',
              serialized='1',
              tv_type='言情/古装',
              country='中国',
              tv_release='2018-8-9')
     tv4 = TV(name='d',
              serialized='2',
              tv_type='纪录片',
              country='中国',
              tv_release='2014-8-9')
     tv5 = TV(name='e',
              serialized='1',
              tv_type='剧情',
              country='日本',
              tv_release='2013-8-9')
     db.session.add(u1)
     db.session.add(u2)
     db.session.add(tv1)
     db.session.add(tv2)
     db.session.add(tv3)
     db.session.add(tv4)
     db.session.add(tv5)
     db.session.commit()
     s1 = Subscription(user_id=u1.id, tv_id=tv1.id)
     s2 = Subscription(user_id=u1.id, tv_id=tv2.id)
     s3 = Subscription(user_id=u1.id, tv_id=tv3.id)
     s4 = Subscription(user_id=u1.id, tv_id=tv5.id)
     db.session.add(s1)
     db.session.add(s2)
     db.session.add(s3)
     db.session.add(s4)
     db.session.commit()
     h1 = HistoryTV(user_id=u1.id,
                    tv_id=tv1.id,
                    timestamp_watched=datetime.datetime(2019, 1, 1))
     h2 = HistoryTV(user_id=u1.id,
                    tv_id=tv2.id,
                    timestamp_watched=datetime.datetime(2019, 1, 3))
     h3 = HistoryTV(user_id=u1.id,
                    tv_id=tv3.id,
                    timestamp_watched=datetime.datetime(2019, 1, 5))
     h4 = HistoryTV(user_id=u1.id,
                    tv_id=tv5.id,
                    timestamp_watched=datetime.datetime(2019, 1, 12))
     h5 = HistoryTV(user_id=u2.id,
                    tv_id=tv4.id,
                    timestamp_watched=datetime.datetime(2019, 1, 18))
     db.session.add(h1)
     db.session.add(h2)
     db.session.add(h3)
     db.session.add(h4)
     db.session.add(h5)
     db.session.commit()
     result = u1.subscribed_tv_order_by_watched().all()
     r_s = [i.subscribed_tv for i in u1.subscribed_tv.all()]
     assert len(result) == len(r_s)
     assert result[0].id == tv5.id
     assert result[-1].id == tv1.id
     assert tv4 not in r_s
     assert u2.subscribed_tv_order_by_watched().first() is None
Exemplo n.º 21
0
 def test_store_and_load_tv(self):
     tv = TV(name='egg')
     db.session.add(tv)
     db.session.commit()
     tv = TV.query.filter_by(id=1).first()
     assert tv.name == 'egg'
Exemplo n.º 22
0
 def test_update_detail_for_human(self):
     tv1 = TV(name='a', update_detail='w:1,3,5')
     tv2 = TV(name='a', update_detail='m:1,3,5')
     assert tv1.update_detail_for_human == '周一、周三、周五'
     assert tv2.update_detail_for_human == '1号、3号、5号'