Skip to content

Add plugins for Gazelle-based sites (including RED and NWCD)#2017

Merged
liiight merged 1 commit intodevelopfrom
feature/gazelle-api
Nov 23, 2017
Merged

Add plugins for Gazelle-based sites (including RED and NWCD)#2017
liiight merged 1 commit intodevelopfrom
feature/gazelle-api

Conversation

@pR0Ps
Copy link
Copy Markdown
Member

@pR0Ps pR0Ps commented Nov 19, 2017

Motivation for changes:

Add capability to search Gazelle-based sites

Detailed changes:

  • Use the old what.cd plugin as a base (what.cd was Gazelle-based)
  • Use a base class to do most of the work
  • Implement specific sites (NWCD and RED included in this PR) in subclasses
  • Add 2FA detection (2FA is currently not supported)

To Do:

  • Implement search interface
  • Testing
  • Wiki documentation

@pR0Ps pR0Ps force-pushed the feature/gazelle-api branch from 2b94afd to 8179b12 Compare November 19, 2017 20:59
@pR0Ps pR0Ps changed the title Add Gazelle input plugin (based on old what.cd input plugin) [WIP] Add Gazelle input plugin (based on old what.cd input plugin) Nov 19, 2017
@pR0Ps pR0Ps force-pushed the feature/gazelle-api branch 2 times, most recently from 3d019c2 to 709376d Compare November 20, 2017 07:37
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance variables should be in lowercase

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, however, these are more like instance constants. They're changed during the initial setup of the class but should stay static after that point.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think it matters. even if they're changed on inheritence, they're still instance variables which is the equivilant of const, and should be lowercase. no biggie though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be lowercase

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could replace this to else

Copy link
Copy Markdown
Member Author

@pR0Ps pR0Ps Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using else would break in the case where no base_url is in the config but one is set up on the subclass so it doesn't need to be configured.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is redundant since you provided a default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parentheses are redundant here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this is more about the wrapping and less about the method of doing it? I was keeping to 80 chars out of habit but have just noticed that 120 is what's configured in setup.py - I'll unwrap the line since it's only 100 unwrapped.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant parentheses

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be moved to exception handling

Copy link
Copy Markdown
Member Author

@pR0Ps pR0Ps Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This response is a 200 in a success case. Any other 3xx or 2xx response, while not considered an error to requests, is considered an error at this point in execution.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid redundant line breaks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only works for python 3 IMO

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to be python 2 compatible

@pR0Ps pR0Ps force-pushed the feature/gazelle-api branch from 709376d to 734cac6 Compare November 20, 2017 08:23
@pR0Ps pR0Ps changed the title [WIP] Add Gazelle input plugin (based on old what.cd input plugin) Add Gazelle input plugin (based on old what.cd input plugin) Nov 20, 2017
@pR0Ps pR0Ps changed the title Add Gazelle input plugin (based on old what.cd input plugin) [WIP] Add Gazelle input plugin (based on old what.cd input plugin) Nov 20, 2017
@pR0Ps pR0Ps force-pushed the feature/gazelle-api branch from 68672c2 to 48a85cf Compare November 20, 2017 09:06

# Logged in successfully, it's ok if nothing matches now
task.no_entries_ok = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One too many linebreaks

self._session.cookies.clear()

if not force:
with FlexgetSession() as session:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer if task.requests is used whenever possible.

torrent_seeds=tor['seeders'],
torrent_leeches=tor['leechers'],
# Size is returned in bytes, convert to MB for compat with the content_size plugin
content_size=tor['size'] / (1024 ** 2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a util for this

Copy link
Copy Markdown
Member Author

@pR0Ps pR0Ps Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did see that but didn't think it was appropriate. That function takes a string, guesses the correct units, and converts it to MB. To use it I would have to do something like:

Entry(
    content_size=parse_filesize(str(tor['size']) + "b")
)

Is that preferred over just converting it manually?

Copy link
Copy Markdown
Contributor

@cvium cvium Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to create a function that does that. It's not the first time we've needed it. Or making it default to bytes if no unit is found.

return list(self.get_entries(self.search_results(params)))


class InputRedacted(InputGazelle):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugins that inherit from InputGazelle should be in separate files. Not sure where to put InputGazelle... maybe utils?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we don't really have a precedence for this. Making it part of core feels weird so I think it's best that all plugins be places together to avoid import issues

Copy link
Copy Markdown
Member Author

@pR0Ps pR0Ps Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of coupling between them and I worry that if they were split up it would be really easy to make a change in one of them that would break the others. Keeping them in the same file would help make it easier for people unfamiliar with the code to understand the implications of changing a parent class.

Ex: InputNotWhat inherits from InputRedacted. To set up the params and schema it just uses the parent classes values and adds/changes things. If RED makes a change and adds a releasetype and someone updates the plugin to include it without taking into account the child, it could break the NWCD plugin. Granted this is kinda messy anyway, but alternative was redefining the entire PARAMS structure which seemed like overkill since it's 95% the same.

This also holds true for things like cookies. If the InputRedacted plugin switched from using a cookie called session to one called red_session and the plugin is updated, InputNotWhat will break

To be honest I'm not totally happy with having InputNotWhat inherit from InputRedacted anyway so I'll look into solving this with a better inheritance model.

EDIT: Latest commit alleviates some of these concerns

@pR0Ps pR0Ps force-pushed the feature/gazelle-api branch 2 times, most recently from e39c081 to e0c7d8e Compare November 20, 2017 22:32
Copy link
Copy Markdown
Contributor

@cvium cvium Nov 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nitpick: We divide imports into four groups:

  1. future
  2. builtin
  3. flexget
  4. 3rd party.

So the sqlalchemy import should be moved down a line.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't typically include the TLD in the plugin name unless it's part of the site name... It should just be redacted

@pR0Ps
Copy link
Copy Markdown
Member Author

pR0Ps commented Nov 23, 2017

@liiight @cvium: I think at this point all the comments have been addressed. Is there anything else? If not I'll go ahead with rebasing the commits into something sane.

@liiight
Copy link
Copy Markdown
Member

liiight commented Nov 23, 2017

I think it's fine now. Don't worry about the commits, we squash the entire pr on merge

@pR0Ps pR0Ps force-pushed the feature/gazelle-api branch from 4b8b437 to 3068a70 Compare November 23, 2017 05:43
@pR0Ps pR0Ps changed the title [WIP] Add Gazelle input plugin (based on old what.cd input plugin) Add plugins for Gazelle-based sites (including RED and NWCD) Nov 23, 2017
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? We already set a user_agent in task.requests (https://github.com/Flexget/Flexget/blob/develop/flexget/utils/requests.py#L184)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to return False. No return statement is the same as return None

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I explicitly return False is that having it return True/False vs. True/None is a little more logical IMO. Same reason why I don't return True/0 even though it would behave the same way when used in truthyness comparisons.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Shouldn't this be called account_info?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this linebreak is necessary. We allow 120 chars.

Copy link
Copy Markdown
Contributor

@cvium cvium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My recent comments are purely stylistic, so you don't have to do them, but I really want the content_size to use our util (feel free to change it to default to bytes if no unit is provided).

@pR0Ps pR0Ps force-pushed the feature/gazelle-api branch from 3068a70 to 7935543 Compare November 23, 2017 13:23
@pR0Ps
Copy link
Copy Markdown
Member Author

pR0Ps commented Nov 23, 2017

@cvium Fixed up style issues and switched to using parse_filesize as per your original comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a plugin for this though https://flexget.com/Plugins/headers

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's useful, I didn't know about that - I've removed the custom UA support from the plugin

Plugin features:
- Can function as a search plugin or a task.
- Stores sessions in the DB to minimize logins.
- Configurable page limit (don't scrape the entire site accidentally)
- Extensible classes to allow adding other gazelle-based sites with
  minimal effort.

Provided plugins:
- Two generic plugins:
  - The 'gazelle' plugin should work for the vast majority of Gazelle-
    based sites, albeit with limited functionality.
  - The 'gazellemusic' plugin is compatible with the latest version of
    the public WhatCD Gazelle source. As most Gazelle-based music sites
    will have used that code as a starting point, this class should work
    for them.
- Two specific plugins:
  - The 'redacted' plugin is a customized version of the 'gazellemusic'
    plugin that works with RED's modifications to the Gazelle source.
  - The 'notwhatcd' plugin is the same thing for NWCD.
@pR0Ps pR0Ps force-pushed the feature/gazelle-api branch from 7935543 to a7c9254 Compare November 23, 2017 13:44
@liiight liiight merged commit 75fd63d into develop Nov 23, 2017
@liiight
Copy link
Copy Markdown
Member

liiight commented Nov 23, 2017

Thanks. Wanna update the wiki?

@cvium cvium deleted the feature/gazelle-api branch November 28, 2017 07:22
@pR0Ps
Copy link
Copy Markdown
Member Author

pR0Ps commented Dec 16, 2017

Added a wiki page: https://www.flexget.com/Searches/gazelle

@liiight
Copy link
Copy Markdown
Member

liiight commented Dec 16, 2017

Looks great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants