Skip to content

Plex improvements#1607

Merged
liiight merged 8 commits intoFlexget:developfrom
jawilson:plex-improvements
Jan 6, 2017
Merged

Plex improvements#1607
liiight merged 8 commits intoFlexget:developfrom
jawilson:plex-improvements

Conversation

@jawilson
Copy link
Copy Markdown
Member

@jawilson jawilson commented Jan 5, 2017

Motivation for changes:

Plex doesn't support sync between servers and I wanted the ability to use Flexget to download optimized videos from my Plex server to my WD My Wireless Passport Pro. I added in a bit of functionality to support my needs, but it could be useful to others.

Detailed changes:

  • Add config for manually supplying Plex token
  • Emit entries for all versions (Media entries) of a video
  • Use same title/filename for movies as series
  • Fix filenames having double . before file extension
  • Add plex_ep_name, plex_year, plex_added, plex_media_title, and plex_stream_optimized entry fields

Addressed issues:

None

Config usage if relevant (new plugin or updated schema):

secrets: secretfile.yml

tasks:
  Movies:
    plex:
      server: '{{ secrets.plex.server }}'
      port: REDACTED
      token: '{{ secrets.plex.token }}'
      strip_year: yes
      unwatched_only: yes
      section: 'Movies'
      selection: recentlyAdded
    accept_all: yes
    limit_new: 6

Log and/or tests output (preferably both):

Full log isn't really necessary, you get the same basic output. Here's a resulting entry:

title            : The.Accountant_1080p_h264_dca-ma.mkv
url              : REDACTED
original_url     : REDACTED
accepted_by      : accept_all
filename         : The.Accountant_1080p_h264_dca-ma.mkv
plex_added       : 2016-12-24 21:16:34
plex_art         : REDACTED
plex_cover       : REDACTED
plex_duration    : 7674262
plex_episode_thumb:
plex_key         : 37710
plex_media_title : Original
plex_path        : /library/parts/73738/1482632186/file.mkv
plex_port        : REDACTED
plex_season_cover: REDACTED
plex_section     : 1
plex_section_name: Movies
plex_server      : REDACTED
plex_status      : unwatched
plex_summary     : As a math savant uncooks the books for a new client, the Treasury Department closes in on his activities and the body count starts to rise.
plex_title       : The Accountant
plex_url         : REDACTED
plex_userrating  :
plex_year        : 2016
quality          : <LazyField - value will be determined when it is accessed>
task             : Movies

title            : The.Accountant_1080p_h264_aac.mp4
url              : REDACTED
original_url     : REDACTED
accepted_by      : accept_all
filename         : The.Accountant_1080p_h264_aac.mp4
plex_added       : 2016-12-24 21:16:34
plex_art         : REDACTED
plex_cover       : REDACTED
plex_duration    : 7674258
plex_episode_thumb:
plex_key         : 37710
plex_media_title : Optimized for TV
plex_path        : /library/parts/73776/1482638137/file.mp4
plex_port        : REDACTED
plex_season_cover: REDACTED
plex_section     : 1
plex_section_name: Movies
plex_server      : REDACTED
plex_status      : unwatched
plex_stream_optimized: 1
plex_summary     : As a math savant uncooks the books for a new client, the Treasury Department closes in on his activities and the body count starts to rise.
plex_title       : The Accountant
plex_url         : REDACTED
plex_userrating  :
plex_year        : 2016
quality          : <LazyField - value will be determined when it is accessed>
task             : Movies

title            : The.Accountant_720p_h264_aac.mp4
url              : REDACTED
original_url     : REDACTED
accepted_by      : accept_all
filename         : The.Accountant_720p_h264_aac.mp4
plex_added       : 2016-12-24 21:16:34
plex_art         : REDACTED
plex_cover       : REDACTED
plex_duration    : 7674258
plex_episode_thumb:
plex_key         : 37710
plex_media_title : Optimized for Mobile
plex_path        : /library/parts/74206/1483401319/file.mp4
plex_port        : REDACTED
plex_season_cover: REDACTED
plex_section     : 1
plex_section_name: Movies
plex_server      : REDACTED
plex_status      : unwatched
plex_stream_optimized: 1
plex_summary     : As a math savant uncooks the books for a new client, the Treasury Department closes in on his activities and the body count starts to rise.
plex_title       : The Accountant
plex_url         : REDACTED
plex_userrating  :
plex_year        : 2016
quality          : <LazyField - value will be determined when it is accessed>
task             : Movies

title            : Snowden_1080p_h264_dca-ma.mkv
url              : REDACTED
original_url     : REDACTED
accepted_by      : accept_all
filename         : Snowden_1080p_h264_dca-ma.mkv
plex_added       : 2016-12-16 23:44:35
plex_art         : REDACTED
plex_cover       : REDACTED
plex_duration    : 8089089
plex_episode_thumb:
plex_key         : 37577
plex_media_title : Original
plex_path        : /library/parts/73333/1481949867/file.mkv
plex_port        : REDACTED
plex_season_cover: REDACTED
plex_section     : 1
plex_section_name: Movies
plex_server      : REDACTED
plex_status      : unwatched
plex_summary     : CIA employee Edward Snowden leaks thousands of classified documents to the press.
plex_title       : Snowden
plex_url         : REDACTED
plex_userrating  :
plex_year        : 2016
quality          : <LazyField - value will be determined when it is accessed>
task             : Movies

title            : Snowden_1080p_h264_aac.mp4
url              : REDACTED
original_url     : REDACTED
accepted_by      : accept_all
filename         : Snowden_1080p_h264_aac.mp4
plex_added       : 2016-12-16 23:44:35
plex_art         : REDACTED
plex_cover       : REDACTED
plex_duration    : 8089110
plex_episode_thumb:
plex_key         : 37577
plex_media_title : Optimized for TV
plex_path        : /library/parts/73365/1481955972/file.mp4
plex_port        : REDACTED
plex_season_cover: REDACTED
plex_section     : 1
plex_section_name: Movies
plex_server      : REDACTED
plex_status      : unwatched
plex_stream_optimized: 1
plex_summary     : CIA employee Edward Snowden leaks thousands of classified documents to the press.
plex_title       : Snowden
plex_url         : REDACTED
plex_userrating  :
plex_year        : 2016
quality          : <LazyField - value will be determined when it is accessed>
task             : Movies

title            : Snowden_720p_h264_aac.mp4
url              : REDACTED
original_url     : REDACTED
accepted_by      : accept_all
filename         : Snowden_720p_h264_aac.mp4
plex_added       : 2016-12-16 23:44:35
plex_art         : REDACTED
plex_cover       : REDACTED
plex_duration    : 8089110
plex_episode_thumb:
plex_key         : 37577
plex_media_title : Optimized for Mobile
plex_path        : /library/parts/74207/1483404339/file.mp4
plex_port        : REDACTED
plex_season_cover: REDACTED
plex_section     : 1
plex_section_name: Movies
plex_server      : REDACTED
plex_status      : unwatched
plex_stream_optimized: 1
plex_summary     : CIA employee Edward Snowden leaks thousands of classified documents to the press.
plex_title       : Snowden
plex_url         : REDACTED
plex_userrating  :
plex_year        : 2016
quality          : <LazyField - value will be determined when it is accessed>
task             : Movies

* Add ability to simply use plex token for authentication
* Add plex_media_title attribute for optimized version titles
* Add plex_stream_optimized attribute for indicating optimized version
* Create an entry for all media versions (including original and optimized)
* Fix extra '.' before file extension when using original_filename
if config['username'] and config['password']:
if config['token']:
accesstoken = config['token']
log.debug("Using accesstoken: %s" % accesstoken)
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.

Pass it as argument instead of doing the string formatting explicitly. Code seems fine otherwise.

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 don't follow. Are you referring to the debug line? I literally just copied line 161, and I can't seem to find any other style for logging in the project.

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.

It should be log.debug("Using accesstoken: %s", accesstoken) instead of log.debug("Using accesstoken: %s" % accesstoken).

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.

Ah, I missed that.

@cvium
Copy link
Copy Markdown
Contributor

cvium commented Jan 5, 2017

Are username and password never used if the token is specified? If so, you might as well change the schema to not accept username + password and token.

@jawilson
Copy link
Copy Markdown
Member Author

jawilson commented Jan 5, 2017

Yes, the only use of the username + password is to get a token from the Plex.tv API. In my setup, I didn't want to depend on internet connectivity, just local network to my Plex server.

I'm looking into how to prevent username + password and token in the schema.

@cvium
Copy link
Copy Markdown
Contributor

cvium commented Jan 5, 2017

@jawilson
Copy link
Copy Markdown
Member Author

jawilson commented Jan 5, 2017

It's a bit different here. You actually don't have to supply a token or username/password if you're Plex server is set up to allow unauthenticated access from you (usually for localhost or local network). So we need something that is either username + password or token or neither.

@cvium
Copy link
Copy Markdown
Contributor

cvium commented Jan 5, 2017

Maybe something like this then: https://github.com/Flexget/Flexget/blob/develop/flexget/plugins/notifiers/pushbullet.py#L50-L56

@liiight
Copy link
Copy Markdown
Member

liiight commented Jan 5, 2017

While you're improving the schema, you should add a bilateral dependency between username and password.
https://github.com/Flexget/Flexget/blob/develop/flexget/plugins/notifiers/email.py#L100

@jawilson
Copy link
Copy Markdown
Member Author

jawilson commented Jan 5, 2017

Aha! I wanted to do that but couldn't figure out a clean way. It's been so long since I've messed with the JSON schema.

@cvium
Copy link
Copy Markdown
Contributor

cvium commented Jan 5, 2017

Is it ready then? Seems fine to me

@jawilson
Copy link
Copy Markdown
Member Author

jawilson commented Jan 5, 2017

Should be, everything works fine for me.

@jawilson
Copy link
Copy Markdown
Member Author

jawilson commented Jan 5, 2017

Shall I merge than? I figure you shouldn't merge your own PRs.

@liiight liiight merged commit 3c96b92 into Flexget:develop Jan 6, 2017
@jawilson jawilson deleted the plex-improvements branch January 6, 2017 18:12
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