📜 ⬆️ ⬇️

Marking viewed series on MyShows.ru

Formulation of the problem


Task: to automate routine actions to mark viewed episodes on the site myshows.ru . Let me explain, after watching the next series of The Big Bang Theory, I open my series , find the series, find the watched episode and mark it as “watched”.

After the discovery of api.myshows.ru , the idea immediately arose of seriously simplifying this process. I would like it to look like this: call the context menu of the file with the just viewed series and select "Mark on myshows.ru".

It will be based on a Ruby script that will take file names as arguments, determine the name of the series, the number of the season and episode, and then mark the series in your profile via the site's API.
')

API


At first it was decided to make a wrapper on top of their Ruby API. It turned out to be an unremarkable myshows library that uses httparty to communicate with the site. Due to the general employment of me, the library does not implement all the functionality of the site, but only the search for serials / episodes and their marking, since this is exactly what is needed to solve the problem. Here is an example of use:

require 'rubygems' require 'myshows' profile = MyShows::Profile.new 'demo', 'fe01ce2a7fbac8fafaed7c982a04e229' tbbt = profile.show 'big bang theory' tbbt.title # => 'The Big Bang Theory' pilot = tbbt.episode 1, 1 pilot.title # => 'Pilot' pilot.check! 

It is worth noting that the Profile # show method, which searches for a TV series by name among your TV shows, is optimized to find the names of TV shows. He can find serials by abbreviation of title, by part of title, by title without spaces, and so on. This is due to the fact that the names of TV shows in the file names are often very distorted: lietome.s03e01.webdl.rus.novafilm.tv.avi instead of lie.to.me.s03e01.webdl.rus.novafilm.tv.avi, House .MDs07e01.rus.LostFilm.TV.avi instead of House.s07e01.rus.LostFilm.TV.avi and so on.

File name parsing


The script should be able to get the name of the file with the series, recognize in it the name of the series, the number of the season and episode. Everybody stand back. I know regular expressions. Searching the local network for recording this information in a file name, I identified two main and wrote the corresponding regular expressions:
There are also variations with or without other delimiters; this does not greatly complicate regular expressions. They are quite simple, you can find them in the final script code in the parse_filename function.

UPD: reminded that one file can correspond to two series. This problem is solved by simple corrections in regular expressions.

Script


Combining the parsing of the file name and the use of the myshows library, we get a simple script that takes the file names as arguments, tries to mark them in your profile and reports to stdout the success of this action:

 $ myshows-checker ".../V.s02e01.LostFilm.TV.avi" ".../V.s03e01.LostFilm.TV.avi" Checked V (2009) - 2x1 - Red Rain Error: episode with number 3x1 was not found in show V (2009) 

The username and md5 password the script is trying to pull out from the ~ / .myshows file, I did not think of a better way.

File Manager Integration


Of course, this script can be used from other scripts and from the command line, but I still watch TV shows opening them with a double click in the file manager.

Here it is necessary to say that I am a Mac OS X user, and therefore further words will be about the integration of a previously written script with this OS. If you are not interested, you can go directly to the conclusion.

We will use Automator . You need to create a new Service that will receive "selected movie files" in "any program."

Add the action “Run shell script”, select “/ usr / bin / ruby” as the language with the input “as arguments”. Then we insert a previously written script in the field for entering the script, replacing what was there (for beauty, you can delete the first line "#! / ...").

Add the action "Run AppleScript". It is necessary to display informational messages printed by the script in any form. It was decided to use the display dialog function, it turns out about the following AppleScript:

 on run {input, parameters} repeat with msg in input display dialog msg buttons {"OK"} end repeat return input end run 

It should have turned out to be something like this:


The service is ready to use, it remains only to save and come up with a name. Now in Finder you can call it:


UPD: suggested that you can use Growl to display messages. To do this, you must run the following AppleScript once

 tell application "GrowlHelperApp" register as application ¬ "MyShows Checker" all notifications {"Notification"} ¬ default notifications {"Notification"} end tell 

and make changes to the created Service

 on run {input, parameters} repeat with msg in input tell application "GrowlHelperApp" notify with name ¬ "Notification" title ¬ "MyShows Checker" description msg ¬ application name ¬ "MyShows Checker" image from location ¬ "file:///path/to/some/image.png" end tell end repeat return input end run 

Optionally, you can after the lines “image from location” specify the path to the picture that will be used as an icon, otherwise just erase the piece from “image from ...” to “... / some / image.png”.

Looks much better than “display dialog ...”


Conclusion


It works, it pleases.

The measurements showed that the average time of the script is 2-5 seconds to mark the series of one series, that is, it will take about the same time to mark one episode of the series and ten takes about the same time, but it will take 20-50 seconds to mark the pilot series of ten different series, not necessary. The bottleneck of the entire system is requests to the site and downloading large lists of episodes. The service created by Automator works longer, there is a constant addition.

And now I have an appeal to those who are interested in this idea. Surely there are people who celebrate serials on myshows.ru and use Windows, KDE, Gnome, .... The Ruby script itself is cross-platform, but integration with a specific file manager is not. In this regard, people are looking for who could tell you how to integrate such a Ruby script into their favorite file manager.

UPD:
Thanks to Nebulosa for an alternative implementation on bash.

Source: https://habr.com/ru/post/112772/


All Articles