Quantcast
Channel: help - Forum - FlexGet
Viewing all articles
Browse latest Browse all 837

Help with avistaz.to plugin

$
0
0

@steve321 wrote:

Hi Guys.

I developed a plugin for avistaz.to - but have a hard time to test it. Please help.

Here is the plugin for avistaz.to

from __future__ import unicode_literals, division, absolute_import
import logging
import re
import urllib
import requests

from flexget import plugin
from flexget import validator
from flexget.entry import Entry
from flexget.event import event
from flexget.utils.soup import get_soup
from flexget.utils.search import torrent_availability, normalize_unicode, clean_title
from flexget.utils.requests import Session

log = logging.getLogger('search_avistaz')

session = Session()

CATEGORIES = {
    'All': 0,
    'Movie': 1,
    'Music': 3,
    'TV-Show': 2
}

URL = 'https://avistaz.to/'


class SearchAVISTAZ(object):

    schema = {
        'type': 'object',
        'properties':
        {
            'username': {'type': 'string'},
            'password': {'type': 'string'},
            'category': {
                'type': 'string',
                'enum': list(CATEGORIES)
            },
        },
        'required': ['category'],
        'additionalProperties': False
    }

    def validator(self):
        """Return config validator."""
        root = validator.factory('dict')
        root.accept('text', key='username', required=True)
        root.accept('text', key='password', required=True)

        root.accept('choice', key='category').accept_choices(CATEGORIES)
        root.accept('number', key='category')
        categories = root.accept('list', key='category')
        categories.accept('choice', key='category').accept_choices(CATEGORIES)
        categories.accept('number', key='category')

        return root

    @plugin.internet(log)
    def search(self, task, entry, config=None):

        if not session.cookies:
            log.debug('Logging in to %s...' % URL)
            params = {'username_email': config['username'],
                      'password': config['password'],
                      'remember': '1',
                      'submit': 'Login'}
            session.post(URL + 'auth/login', data=params)

        category = config.get('category', 'all')
        category_url_fragment = '&type=%s' % urllib.quote(category)

        base_url = 'https://avistaz.to/torrents?in=0'

        entries = set()
        for search_string in entry.get('search_strings', [entry['title']]):
            query = normalize_unicode(search_string)
            query_url_fragment = '&search=' + urllib.quote(query.encode('utf8'))

            # http://publichd.se/index.php?page=torrents&active=0&category=5;15&search=QUERY
            url = (base_url + category_url_fragment + query_url_fragment)
            log.debug('search url: %s' % url)

            page = requests.get(url).content
            soup = get_soup(page)

            for result in soup.find_all('td', attrs={'class': True}):
                entry = Entry()
                entry['title'] = result.find('td', attrs={'class': 'torrent-filename'}).text
                entry['url'] = URL + result.find('a', href=re.compile(r'.torrent$'))['href']

                comments, seeds, leeches, completed = result.find_all('td', text=re.compile('^\d+$'))
                entry['torrent_seeds'] = int(seeds.text)
                entry['torrent_leeches'] = int(leeches.text)
                entry['search_sort'] = torrent_availability(entry['torrent_seeds'],entry['torrent_leeches'])

                size = result.find_all('td', text=re.compile('(\d+(?:[.,]\d+)*)\s?([KMG]B)')).next
                size = re.search('(\d+(?:[.,]\d+)*)\s?([KMG]B)', size)

                if size:
                    if size.group(2) == 'GB':
                        entry['content_size'] = int(float(size.group(1)) * 1000 ** 3 / 1024 ** 2)
                    elif size.group(2) == 'MB':
                        entry['content_size'] = int(float(size.group(1)) * 1000 ** 2 / 1024 ** 2)
                    elif size.group(2) == 'KB':
                        entry['content_size'] = int(float(size.group(1)) * 1000 / 1024 ** 2)
                    else:
                        entry['content_size'] = int(float(size.group(1)) / 1024 ** 2)

                entries.add(entry)

        return entries


@event('plugin.register')
def register_plugin():
    plugin.register(SearchAVISTAZ, 'avistaz', groups=['search'], api_ver=2, debug=True)

And here is the config.yml

templates:
  global:
    
    exists:
      - /torrents/complete
      - /torrents/downloading
      - /torrents/seeding
      - /torrents/watching

    free_space:
      path: /torrents
      space: 1024

    transmission:
      host: localhost
      port: 9091
      username: username
      password: password

    content_filter:
      require:
        - '*.mkv'
        - '*.avi'
        - '*.mpg'
        - '*.mp4'
      reject: 
        - '*.wmv'
        - '*.r0'
        - '*.rar'
        - '*.part0'

    magnets: no

    torrent_alive:
      min_seeds: 1
      reject_for: 2 hours

    domain_delay:
      avistaz.to: 60 seconds


  tv_gen:
    configure_series:
      settings:
        quality: 720p+ dvdscr+ 480p+ webrip+

    regexp:
      from: title
      reject:
        - trailer
        - screener
        - subbed
        - dubbed
        - subtitles
        - subs
        - NL
        - Subs

tasks:
  GEN_TV:
    template: tv_gen
    discover:
      what:
        - emit_series: yes
      from:
        - avistaz:
            username: username
            password: password
            category: TV-Show
    series:
    - Running Man:
        identified_by: ep
        ep_regexp:
          - E(\d+)
#       identified_by: sequence
#       sequence_regexp: E(\d\d\d)
#       id_regexp: \.e(\d\d\d)\.
#       id_regexp: \.e(\d\d\d)\.
        begin: 285
    - Oh My Venus (2015)
    - Descendants of the Sun (2016)

The problem is that I cannot make it work. It seams there is a problem with the series identifier.
The series name on avistaz is e.g. Running Man E290 720p WITH HDTV HD 720p
Tried to catch the series number like E285 but failed.

This is the input

flexget -c config.yml  execute --test --debug --discover-now

This is the output

2016-03-15 17:33 INFO     performance                   Enabling plugin and SQLAlchemy performance debugging
2016-03-15 17:33 VERBOSE  task_queue                    There are 1 tasks to execute. Shutdown will commence when they have completed.
2016-03-15 17:33 INFO     configure_series GEN_TV          Did not get any series to generate series configuration
2016-03-15 17:33 CRITICAL plugin        GEN_TV          `begin` value `285` does not match identifier type for identified_by `ep`
2016-03-15 17:33 WARNING  task          GEN_TV          Aborting task (plugin: series_db)
2016-03-15 17:33 INFO     performance                   Performance results for task GEN_TV:

The problem is that I am not sure weather the plugin is able to login and search for the result.
Maybe there is smth wrong in the plugin code?

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 837

Trending Articles