1SUBLIMINAL(1) subliminal SUBLIMINAL(1)
2
3
4
6 subliminal - subliminal Documentation
7
8 Subliminal is a python 2.7+ library to search and download subtitles.
9 It comes with an easy to use yet powerful CLI suitable for direct use
10 or cron jobs.
11
13 Usage
14 CLI
15 Download English subtitles:
16
17 $ subliminal download -l en The.Big.Bang.Theory.S05E18.HDTV.x264-LOL.mp4
18 Collecting videos [####################################] 100%
19 1 video collected / 0 video ignored
20 Downloading subtitles [####################################] 100%
21 Downloaded 1 subtitle
22
23 WARNING:
24 For cron usage, make sure to specify a maximum age (with --age) so
25 subtitles are searched for recent videos only. Otherwise you will
26 get banned from the providers for abuse due to too many requests. If
27 subliminal didn’t find subtitles for an old video, it’s unlikely it
28 will find subtitles for that video ever anyway.
29
30 See cli for more details on the available commands and options.
31
32 Nautilus/Nemo integration
33 See the dedicated project page for more information.
34
35 High level API
36 You can call subliminal in many different ways depending on how much
37 control you want over the process. For most use cases, you can stick to
38 the standard API.
39
40 Common
41 Let’s start by importing subliminal:
42
43 >>> import os
44 >>> from babelfish import *
45 >>> from subliminal import *
46
47 Before going further, there are a few things to know about subliminal.
48
49 Video
50 The Movie and Episode classes represent a video, existing or not. You
51 can create a video by name (or path) with Video.fromname, use
52 scan_video() on an existing file path to get even more information
53 about the video or use scan_videos() on an existing directory path to
54 scan a whole directory for videos.
55
56 >>> video = Video.fromname('The.Big.Bang.Theory.S05E18.HDTV.x264-LOL.mp4')
57 >>> video
58 <Episode ['The Big Bang Theory', 5x18]>
59
60 Here video information was guessed based on the name of the video, you
61 can access some video attributes:
62
63 >>> video.video_codec
64 'h264'
65 >>> video.release_group
66 'LOL'
67
68 Configuration
69 Before proceeding to listing and downloading subtitles, you need to
70 configure the cache. Subliminal uses a cache to reduce repeated queries
71 to providers and improve overall performance with no impact on search
72 quality. For the sake of this example, we’re going to use a memory
73 backend.
74
75 >>> my_region = region.configure('dogpile.cache.memory')
76
77 WARNING:
78 Choose a cache that fits your application and prefer persistent over
79 volatile backends. The file backend is usually a good choice. See
80 dogpile.cache’s documentation for more details on backends.
81
82 Now that we’re done with the basics, let’s have some real fun.
83
84 Listing
85 To list subtitles, subliminal provides a list_subtitles() function that
86 will return all found subtitles:
87
88 >>> subtitles = list_subtitles([video], {Language('hun')}, providers=['podnapisi'])
89 >>> subtitles[video]
90 [<PodnapisiSubtitle 'ZtAW' [hu]>, <PodnapisiSubtitle 'ONAW' [hu]>]
91
92 NOTE:
93 As you noticed, all parameters are iterables but only contain one
94 item which means you can deal with a lot of videos, languages and
95 providers at the same time. For the sake of this example, we filter
96 providers to use only one, pass providers=None (default) to search
97 on all providers.
98
99 Scoring
100 It’s usual you have multiple candidates for subtitles. To help you
101 chose which one to download, subliminal can compare them to the video
102 and tell you exactly what matches with get_matches():
103
104 >>> for s in subtitles[video]:
105 ... sorted(s.get_matches(video))
106 ['episode', 'format', 'release_group', 'season', 'series', 'video_codec', 'year']
107 ['episode', 'format', 'season', 'series', 'year']
108
109 And then compute a score with those matches with compute_score():
110
111 >>> for s in subtitles[video]:
112 ... {s: compute_score(s, video)}
113 {<PodnapisiSubtitle 'ZtAW' [hu]>: 354}
114 {<PodnapisiSubtitle 'ONAW' [hu]>: 337}
115
116 Now you should have a better idea about which one you should choose.
117
118 Downloading
119 We can settle on the first subtitle and download its content using
120 download_subtitles():
121
122 >>> subtitle = subtitles[video][0]
123 >>> subtitle.content is None
124 True
125 >>> download_subtitles([subtitle])
126 >>> subtitle.content.split(b'\n')[2]
127 b'Elszaladok a boltba'
128
129 If you want a string instead of bytes, you can access decoded content
130 with the text property:
131
132 >>> subtitle.text.split('\n')[3]
133 'néhány apróságért.'
134
135 Downloading best subtitles
136 Downloading best subtitles is what you want to do in almost all cases,
137 as a shortcut for listing, scoring and downloading you can use down‐
138 load_best_subtitles():
139
140 >>> best_subtitles = download_best_subtitles([video], {Language('hun')}, providers=['podnapisi'])
141 >>> best_subtitles[video]
142 [<PodnapisiSubtitle 'ZtAW' [hu]>]
143 >>> best_subtitle = best_subtitles[video][0]
144 >>> best_subtitle.content.split(b'\n')[2]
145 b'Elszaladok a boltba'
146
147 We end up with the same subtitle but with one line of code. Neat.
148
149 Save
150 We got ourselves a nice subtitle, now we can save it on the file system
151 using save_subtitles():
152
153 >>> save_subtitles(video, [best_subtitle])
154 [<PodnapisiSubtitle 'ZtAW' [hu]>]
155 >>> os.listdir()
156 ['The.Big.Bang.Theory.S05E18.HDTV.x264-LOL.hu.srt']
157
158 How it works
159 Providers
160 Subliminal uses multiple providers to give users a vast choice and have
161 a better chance to find the best matching subtitles. Current supported
162 providers are:
163
164 · Addic7ed
165
166 · LegendasTV
167
168 · NapiProjekt
169
170 · OpenSubtitles
171
172 · Podnapisi
173
174 · Shooter
175
176 · SubsCenter
177
178 · TheSubDB
179
180 · TvSubtitles
181
182 Providers all inherit the same Provider base class and thus share the
183 same API. They are registered on the subliminal.providers entry point
184 and are exposed through the provider_manager for easy access.
185
186 To work with multiple providers seamlessly, the ProviderPool exposes
187 the same API but distributes it to its providers and AsyncProviderPool
188 does it asynchronously.
189
190 Scoring
191 Rating subtitles and comparing them is probably the most difficult part
192 and this is where subliminal excels with its powerful scoring algo‐
193 rithm.
194
195 Using guessit and enzyme, subliminal extracts properties of the video
196 and match them with the properties of the subtitles found with the
197 providers.
198
199 Equations in subliminal.score give a score to each property (called a
200 match). The more matches the video and the subtitle have, the higher
201 the score computed with compute_score() gets.
202
203 Libraries
204 Various libraries are used by subliminal and are key to its success:
205
206 · guessit to guess information from filenames
207
208 · enzyme to detect embedded subtitles in videos and read other video
209 metadata
210
211 · babelfish to work with languages
212
213 · requests to make human readable HTTP requests
214
215 · BeautifulSoup to parse HTML and XML
216
217 · dogpile.cache to cache intermediate search results
218
219 · stevedore to manage the provider entry point
220
221 · chardet to detect subtitles’ encoding
222
223 · pysrt to validate downloaded subtitles
224
225 CLI
226 subliminal
227 Usage: subliminal [OPTIONS] COMMAND [ARGS]...
228
229 Subtitles, faster than your thoughts.
230
231 Options:
232 --addic7ed USERNAME PASSWORD Addic7ed configuration.
233 --legendastv USERNAME PASSWORD LegendasTV configuration.
234 --opensubtitles USERNAME PASSWORD
235 OpenSubtitles configuration.
236 --subscenter USERNAME PASSWORD SubsCenter configuration.
237 --cache-dir DIRECTORY Path to the cache directory. [default:
238 /builddir/.cache/subliminal]
239 --debug Print useful information for debugging
240 subliminal and for reporting bugs.
241 --version Show the version and exit.
242 --help Show this message and exit.
243
244 Commands:
245 cache Cache management.
246 download Download best subtitles.
247
248 Suggestions and bug reports are greatly appreciated:
249 https://github.com/Diaoul/subliminal/
250
251 subliminal download
252 Usage: subliminal download [OPTIONS] PATH...
253
254 Download best subtitles.
255
256 PATH can be an directory containing videos, a video file path or a video
257 file name. It can be used multiple times.
258
259 If an existing subtitle is detected (external or embedded) in the correct
260 language, the download is skipped for the associated video.
261
262 Options:
263 -l, --language LANGUAGE Language as IETF code, e.g. en, pt-BR (can
264 be used multiple times). [required]
265 -p, --provider [addic7ed|legendastv|opensubtitles|podnapisi|shooter|subscenter|thesubdb|tvsubtitles]
266 Provider to use (can be used multiple
267 times).
268 -r, --refiner [metadata|omdb|tvdb]
269 Refiner to use (can be used multiple times).
270 -a, --age AGE Filter videos newer than AGE, e.g. 12h,
271 1w2d.
272 -d, --directory DIR Directory where to save subtitles, default
273 is next to the video file.
274 -e, --encoding ENC Subtitle file encoding, default is to
275 preserve original encoding.
276 -s, --single Save subtitle without language code in the
277 file name, i.e. use .srt extension. Do not
278 use this unless your media player requires
279 it.
280 -f, --force Force download even if a subtitle already
281 exist.
282 -hi, --hearing-impaired Prefer hearing impaired subtitles.
283 -m, --min-score INTEGER RANGE Minimum score for a subtitle to be
284 downloaded (0 to 100).
285 -w, --max-workers INTEGER RANGE
286 Maximum number of threads to use.
287 -z, --archives / -Z, --no-archives
288 Scan archives for videos (supported
289 extensions: .rar). [default: True]
290 -v, --verbose Increase verbosity.
291 --help Show this message and exit.
292
293 subliminal cache
294 Usage: subliminal cache [OPTIONS]
295
296 Cache management.
297
298 Options:
299 --clear-subliminal Clear subliminal's cache. Use this ONLY if your cache is
300 corrupted or if you experience issues.
301 --help Show this message and exit.
302
303 Provider Guide
304 This guide is going to explain how to add a Provider to subliminal. You
305 are encouraged to take a look at the existing providers, it can be a
306 nice base to start your own provider.
307
308 Requirements
309 When starting a provider you should be able to answer to the following
310 questions:
311
312 · What languages does my provider support?
313
314 · What are the language codes for the supported languages?
315
316 · Does my provider deliver subtitles for episodes? for movies?
317
318 · Does my provider require a video hash?
319
320 Each response of these questions will help you set the correct
321 attributes for your Provider.
322
323 Video Validation
324 Not all providers deliver subtitles for Episode. Some may require a
325 hash. The check() method does validation against a Video object and
326 will return False if the given Video isn’t suitable. If you’re not
327 happy with the default implementation, you can override it.
328
329 Configuration
330 API keys must not be configurable by the user and must remain linked to
331 subliminal. Hence they must be written in the provider module.
332
333 Per-user authentication is allowed and must be configured at instantia‐
334 tion as keyword arguments. Configuration will be done by the user
335 through the provider_configs argument of the list_subtitles() and down‐
336 load_best_subtitles() functions. No network operation must be done dur‐
337 ing instantiation, only configuration. Any error in the configuration
338 must raise a ConfigurationError.
339
340 Beyond this point, if an error occurs, a generic ProviderError excep‐
341 tion must be raised. You can also use more explicit exception classes
342 AuthenticationError and DownloadLimitExceeded.
343
344 Initialization / Termination
345 Actual authentication operations must take place in the initialize()
346 method. If you need anything to be executed when the provider isn’t
347 used anymore like logout, use terminate().
348
349 Caching policy
350 To save bandwidth and improve querying time, intermediate data should
351 be cached when possible. Typical use case is when a query to retrieve
352 show ids is required prior to the query to actually search for subti‐
353 tles. In that case the function that gets the show id from the show
354 name must be cached. Expiration time should be SHOW_EXPIRATION_TIME
355 for shows and EPISODE_EXPIRATION_TIME for episodes.
356
357 Language
358 To be able to handle various language codes, subliminal makes use of
359 babelfish Language and converters. You must set the attribute languages
360 with a set of supported Language.
361
362 If you cannot find a suitable converter for your provider, you can make
363 one of your own.
364
365 Querying
366 The query() method parameters must include all aspects of provider’s
367 querying with primary types.
368
369 Subtitle
370 A custom Subtitle subclass must be created to represent a subtitle from
371 the provider. It must have relevant attributes that can be used to
372 compute the matches of the subtitle against a Video object.
373
374 Score computation
375 To be able to compare subtitles coming from different providers between
376 them, the get_matches() method must be implemented.
377
378 Unittesting
379 All possible uses of query(), list_subtitles() and download_subtitle()
380 methods must have integration tests. Use vcrpy for recording and play‐
381 back of network activity. Other functions must be unittested. If nec‐
382 essary, you can use unittest.mock to mock some functions.
383
385 If you are looking for information on a specific function, class or
386 method, this part of the documentation is for you.
387
388 Core
389 subliminal.core.ARCHIVE_EXTENSIONS
390 Supported archive extensions
391
392 class subliminal.core.ProviderPool(providers=None, provider_con‐
393 figs=None)
394 A pool of providers with the same API as a single Provider.
395
396 It has a few extra features:
397
398 · Lazy loads providers when needed and supports the with
399 statement to terminate() the providers on exit.
400
401 · Automatically discard providers on failure.
402
403 Parameters
404
405 · providers (list) – name of providers to use, if not
406 all.
407
408 · provider_configs (dict) – provider configuration as
409 keyword arguments per provider name to pass when
410 instanciating the Provider.
411
412 providers = None
413 Name of providers to use
414
415 provider_configs = None
416 Provider configuration
417
418 initialized_providers = None
419 Initialized providers
420
421 discarded_providers = None
422 Discarded providers
423
424 list_subtitles_provider(provider, video, languages)
425 List subtitles with a single provider.
426
427 The video and languages are checked against the provider.
428
429 Parameters
430
431 · provider (str) – name of the provider.
432
433 · video (Video) – video to list subtitles for.
434
435 · languages (set of Language) – languages to
436 search for.
437
438 Returns
439 found subtitles.
440
441 Return type
442 list of Subtitle or None
443
444 list_subtitles(video, languages)
445 List subtitles.
446
447 Parameters
448
449 · video (Video) – video to list subtitles for.
450
451 · languages (set of Language) – languages to
452 search for.
453
454 Returns
455 found subtitles.
456
457 Return type
458 list of Subtitle
459
460 download_subtitle(subtitle)
461 Download subtitle’s content.
462
463 Parameters
464 subtitle (Subtitle) – subtitle to download.
465
466 Returns
467 True if the subtitle has been successfully down‐
468 loaded, False otherwise.
469
470 Return type
471 bool
472
473 download_best_subtitles(subtitles, video, languages,
474 min_score=0, hearing_impaired=False, only_one=False, com‐
475 pute_score=None)
476 Download the best matching subtitles.
477
478 Parameters
479
480 · subtitles (list of Subtitle) – the subtitles to
481 use.
482
483 · video (Video) – video to download subtitles for.
484
485 · languages (set of Language) – languages to down‐
486 load.
487
488 · min_score (int) – minimum score for a subtitle
489 to be downloaded.
490
491 · hearing_impaired (bool) – hearing impaired pref‐
492 erence.
493
494 · only_one (bool) – download only one subtitle,
495 not one per language.
496
497 · compute_score – function that takes subtitle and
498 video as positional arguments, hearing_impaired
499 as keyword argument and returns the score.
500
501 Returns
502 downloaded subtitles.
503
504 Return type
505 list of Subtitle
506
507 terminate()
508 Terminate all the initialized_providers.
509
510 class subliminal.core.AsyncProviderPool(max_workers=None, *args,
511 **kwargs)
512 Subclass of ProviderPool with asynchronous support for
513 list_subtitles().
514
515 Parameters
516 max_workers (int) – maximum number of threads to use. If
517 None, max_workers will be set to the number of providers.
518
519 max_workers = None
520 Maximum number of threads to use
521
522 list_subtitles_provider(provider, video, languages)
523 List subtitles with a single provider.
524
525 The video and languages are checked against the provider.
526
527 Parameters
528
529 · provider (str) – name of the provider.
530
531 · video (Video) – video to list subtitles for.
532
533 · languages (set of Language) – languages to
534 search for.
535
536 Returns
537 found subtitles.
538
539 Return type
540 list of Subtitle or None
541
542 list_subtitles(video, languages)
543 List subtitles.
544
545 Parameters
546
547 · video (Video) – video to list subtitles for.
548
549 · languages (set of Language) – languages to
550 search for.
551
552 Returns
553 found subtitles.
554
555 Return type
556 list of Subtitle
557
558 subliminal.core.check_video(video, languages=None, age=None, unde‐
559 fined=False)
560 Perform some checks on the video.
561
562 All the checks are optional. Return False if any of this check
563 fails:
564
565 · languages already exist in video’s subtitle_languages.
566
567 · video is older than age.
568
569 · video has an undefined language in subtitle_languages.
570
571 Parameters
572
573 · video (Video) – video to check.
574
575 · languages (set of Language) – desired languages.
576
577 · age (datetime.timedelta) – maximum age of the video.
578
579 · undefined (bool) – fail on existing undefined language.
580
581 Returns
582 True if the video passes the checks, False otherwise.
583
584 Return type
585 bool
586
587 subliminal.core.search_external_subtitles(path, directory=None)
588 Search for external subtitles from a video path and their asso‐
589 ciated language.
590
591 Unless directory is provided, search will be made in the same
592 directory as the video file.
593
594 Parameters
595
596 · path (str) – path to the video.
597
598 · directory (str) – directory to search for subtitles.
599
600 Returns
601 found subtitles with their languages.
602
603 Return type
604 dict
605
606 subliminal.core.scan_video(path)
607 Scan a video from a path.
608
609 Parameters
610 path (str) – existing path to the video.
611
612 Returns
613 the scanned video.
614
615 Return type
616 Video
617
618 subliminal.core.scan_archive(path)
619 Scan an archive from a path.
620
621 Parameters
622 path (str) – existing path to the archive.
623
624 Returns
625 the scanned video.
626
627 Return type
628 Video
629
630 subliminal.core.scan_videos(path, age=None, archives=True)
631 Scan path for videos and their subtitles.
632
633 See refine() to find additional information for the video.
634
635 Parameters
636
637 · path (str) – existing directory path to scan.
638
639 · age (datetime.timedelta) – maximum age of the video or
640 archive.
641
642 · archives (bool) – scan videos in archives.
643
644 Returns
645 the scanned videos.
646
647 Return type
648 list of Video
649
650 subliminal.core.refine(video, episode_refiners=None, movie_refin‐
651 ers=None, **kwargs)
652 Refine a video using refiners.
653
654 NOTE:
655 Exceptions raised in refiners are silently passed and logged.
656
657 Parameters
658
659 · video (Video) – the video to refine.
660
661 · episode_refiners (tuple) – refiners to use for
662 episodes.
663
664 · movie_refiners (tuple) – refiners to use for movies.
665
666 · **kwargs – additional parameters for the refine() func‐
667 tions.
668
669 subliminal.core.list_subtitles(videos, languages, pool_class=<class
670 'subliminal.core.ProviderPool'>, **kwargs)
671 List subtitles.
672
673 The videos must pass the languages check of check_video().
674
675 Parameters
676
677 · videos (set of Video) – videos to list subtitles for.
678
679 · languages (set of Language) – languages to search for.
680
681 · pool_class (ProviderPool, AsyncProviderPool or similar)
682 – class to use as provider pool.
683
684 · **kwargs – additional parameters for the provided
685 pool_class constructor.
686
687 Returns
688 found subtitles per video.
689
690 Return type
691 dict of Video to list of Subtitle
692
693 subliminal.core.download_subtitles(subtitles, pool_class=<class 'sub‐
694 liminal.core.ProviderPool'>, **kwargs)
695 Download content of subtitles.
696
697 Parameters
698
699 · subtitles (list of Subtitle) – subtitles to download.
700
701 · pool_class (ProviderPool, AsyncProviderPool or similar)
702 – class to use as provider pool.
703
704 · **kwargs – additional parameters for the provided
705 pool_class constructor.
706
707 subliminal.core.download_best_subtitles(videos, languages, min_score=0,
708 hearing_impaired=False, only_one=False, compute_score=None,
709 pool_class=<class 'subliminal.core.ProviderPool'>, **kwargs)
710 List and download the best matching subtitles.
711
712 The videos must pass the languages and undefined (only_one)
713 checks of check_video().
714
715 Parameters
716
717 · videos (set of Video) – videos to download subtitles
718 for.
719
720 · languages (set of Language) – languages to download.
721
722 · min_score (int) – minimum score for a subtitle to be
723 downloaded.
724
725 · hearing_impaired (bool) – hearing impaired preference.
726
727 · only_one (bool) – download only one subtitle, not one
728 per language.
729
730 · compute_score – function that takes subtitle and video
731 as positional arguments, hearing_impaired as keyword
732 argument and returns the score.
733
734 · pool_class (ProviderPool, AsyncProviderPool or similar)
735 – class to use as provider pool.
736
737 · **kwargs – additional parameters for the provided
738 pool_class constructor.
739
740 Returns
741 downloaded subtitles per video.
742
743 Return type
744 dict of Video to list of Subtitle
745
746 subliminal.core.save_subtitles(video, subtitles, single=False, direc‐
747 tory=None, encoding=None)
748 Save subtitles on filesystem.
749
750 Subtitles are saved in the order of the list. If a subtitle with
751 a language has already been saved, other subtitles with the same
752 language are silently ignored.
753
754 The extension used is .lang.srt by default or .srt is single is
755 True, with lang being the IETF code for the language of the sub‐
756 title.
757
758 Parameters
759
760 · video (Video) – video of the subtitles.
761
762 · subtitles (list of Subtitle) – subtitles to save.
763
764 · single (bool) – save a single subtitle, default is to
765 save one subtitle per language.
766
767 · directory (str) – path to directory where to save the
768 subtitles, default is next to the video.
769
770 · encoding (str) – encoding in which to save the subti‐
771 tles, default is to keep original encoding.
772
773 Returns
774 the saved subtitles
775
776 Return type
777 list of Subtitle
778
779 Video
780 subliminal.video.VIDEO_EXTENSIONS
781 Video extensions
782
783 class subliminal.video.Video(name, format=None, release_group=None,
784 resolution=None, video_codec=None, audio_codec=None, imdb_id=None,
785 hashes=None, size=None, subtitle_languages=None)
786 Base class for videos.
787
788 Represent a video, existing or not.
789
790 Parameters
791
792 · name (str) – name or path of the video.
793
794 · format (str) – format of the video (HDTV, WEB-DL, Blu‐
795 Ray, …).
796
797 · release_group (str) – release group of the video.
798
799 · resolution (str) – resolution of the video stream
800 (480p, 720p, 1080p or 1080i).
801
802 · video_codec (str) – codec of the video stream.
803
804 · audio_codec (str) – codec of the main audio stream.
805
806 · imdb_id (str) – IMDb id of the video.
807
808 · hashes (dict) – hashes of the video file by provider
809 names.
810
811 · size (int) – size of the video file in bytes.
812
813 · subtitle_languages (set) – existing subtitle languages.
814
815 name = None
816 Name or path of the video
817
818 format = None
819 Format of the video (HDTV, WEB-DL, BluRay, …)
820
821 release_group = None
822 Release group of the video
823
824 resolution = None
825 Resolution of the video stream (480p, 720p, 1080p or
826 1080i)
827
828 video_codec = None
829 Codec of the video stream
830
831 audio_codec = None
832 Codec of the main audio stream
833
834 imdb_id = None
835 IMDb id of the video
836
837 hashes = None
838 Hashes of the video file by provider names
839
840 size = None
841 Size of the video file in bytes
842
843 subtitle_languages = None
844 Existing subtitle languages
845
846 property exists
847 Test whether the video exists
848
849 property age
850 Age of the video
851
852 classmethod fromguess(name, guess)
853 Create an Episode or a Movie with the given name based on
854 the guess.
855
856 Parameters
857
858 · name (str) – name of the video.
859
860 · guess (dict) – guessed data.
861
862 Raise ValueError if the type of the guess is invalid
863
864 classmethod fromname(name)
865 Shortcut for fromguess() with a guess guessed from the
866 name.
867
868 Parameters
869 name (str) – name of the video.
870
871 class subliminal.video.Episode(name, series, season, episode,
872 title=None, year=None, original_series=True, tvdb_id=None,
873 series_tvdb_id=None, series_imdb_id=None, **kwargs)
874 Episode Video.
875
876 Parameters
877
878 · series (str) – series of the episode.
879
880 · season (int) – season number of the episode.
881
882 · episode (int) – episode number of the episode.
883
884 · title (str) – title of the episode.
885
886 · year (int) – year of the series.
887
888 · original_series (bool) – whether the series is the
889 first with this name.
890
891 · tvdb_id (int) – TVDB id of the episode.
892
893 · **kwargs – additional parameters for the Video con‐
894 structor.
895
896 series = None
897 Series of the episode
898
899 season = None
900 Season number of the episode
901
902 episode = None
903 Episode number of the episode
904
905 title = None
906 Title of the episode
907
908 year = None
909 Year of series
910
911 original_series = None
912 The series is the first with this name
913
914 tvdb_id = None
915 TVDB id of the episode
916
917 series_tvdb_id = None
918 TVDB id of the series
919
920 series_imdb_id = None
921 IMDb id of the series
922
923 classmethod fromguess(name, guess)
924 Create an Episode or a Movie with the given name based on
925 the guess.
926
927 Parameters
928
929 · name (str) – name of the video.
930
931 · guess (dict) – guessed data.
932
933 Raise ValueError if the type of the guess is invalid
934
935 classmethod fromname(name)
936 Shortcut for fromguess() with a guess guessed from the
937 name.
938
939 Parameters
940 name (str) – name of the video.
941
942 class subliminal.video.Movie(name, title, year=None, **kwargs)
943 Movie Video.
944
945 Parameters
946
947 · title (str) – title of the movie.
948
949 · year (int) – year of the movie.
950
951 · **kwargs – additional parameters for the Video con‐
952 structor.
953
954 title = None
955 Title of the movie
956
957 year = None
958 Year of the movie
959
960 classmethod fromguess(name, guess)
961 Create an Episode or a Movie with the given name based on
962 the guess.
963
964 Parameters
965
966 · name (str) – name of the video.
967
968 · guess (dict) – guessed data.
969
970 Raise ValueError if the type of the guess is invalid
971
972 classmethod fromname(name)
973 Shortcut for fromguess() with a guess guessed from the
974 name.
975
976 Parameters
977 name (str) – name of the video.
978
979 Subtitle
980 subliminal.subtitle.SUBTITLE_EXTENSIONS
981 Subtitle extensions
982
983 class subliminal.subtitle.Subtitle(language, hearing_impaired=False,
984 page_link=None, encoding=None)
985 Base class for subtitle.
986
987 Parameters
988
989 · language (Language) – language of the subtitle.
990
991 · hearing_impaired (bool) – whether or not the subtitle
992 is hearing impaired.
993
994 · page_link (str) – URL of the web page from which the
995 subtitle can be downloaded.
996
997 · encoding (str) – Text encoding of the subtitle.
998
999 provider_name = ''
1000 Name of the provider that returns that class of subtitle
1001
1002 language = None
1003 Language of the subtitle
1004
1005 hearing_impaired = None
1006 Whether or not the subtitle is hearing impaired
1007
1008 page_link = None
1009 URL of the web page from which the subtitle can be down‐
1010 loaded
1011
1012 content = None
1013 Content as bytes
1014
1015 encoding = None
1016 Encoding to decode with when accessing text
1017
1018 property id
1019 Unique identifier of the subtitle
1020
1021 property text
1022 Content as string
1023
1024 If encoding is None, the encoding is guessed with
1025 guess_encoding()
1026
1027 is_valid()
1028 Check if a text is a valid SubRip format.
1029
1030 Returns
1031 whether or not the subtitle is valid.
1032
1033 Return type
1034 bool
1035
1036 guess_encoding()
1037 Guess encoding using the language, falling back on
1038 chardet.
1039
1040 Returns
1041 the guessed encoding.
1042
1043 Return type
1044 str
1045
1046 get_matches(video)
1047 Get the matches against the video.
1048
1049 Parameters
1050 video (Video) – the video to get the matches with.
1051
1052 Returns
1053 matches of the subtitle.
1054
1055 Return type
1056 set
1057
1058 subliminal.subtitle.get_subtitle_path(video_path, language=None, exten‐
1059 sion='.srt')
1060 Get the subtitle path using the video_path and language.
1061
1062 Parameters
1063
1064 · video_path (str) – path to the video.
1065
1066 · language (Language) – language of the subtitle to put
1067 in the path.
1068
1069 · extension (str) – extension of the subtitle.
1070
1071 Returns
1072 path of the subtitle.
1073
1074 Return type
1075 str
1076
1077 subliminal.subtitle.guess_matches(video, guess, partial=False)
1078 Get matches between a video and a guess.
1079
1080 If a guess is partial, the absence information won’t be counted
1081 as a match.
1082
1083 Parameters
1084
1085 · video (Video) – the video.
1086
1087 · guess (dict) – the guess.
1088
1089 · partial (bool) – whether or not the guess is partial.
1090
1091 Returns
1092 matches between the video and the guess.
1093
1094 Return type
1095 set
1096
1097 subliminal.subtitle.fix_line_ending(content)
1098 Fix line ending of content by changing it to
1099
1100 param bytes content
1101 content of the subtitle.
1102
1103 return the content with fixed line endings.
1104
1105 rtype bytes
1106
1107 Providers
1108 class subliminal.providers.TimeoutSafeTransport(timeout, *args,
1109 **kwargs)
1110 Timeout support for xmlrpc.client.SafeTransport.
1111
1112 class subliminal.providers.ParserBeautifulSoup(markup, parsers,
1113 **kwargs)
1114 A bs4.BeautifulSoup that picks the first parser available in
1115 parsers.
1116
1117 Parameters
1118
1119 · markup – markup for the bs4.BeautifulSoup.
1120
1121 · parsers (list) – parser names, in order of preference.
1122
1123 class subliminal.providers.Provider
1124 Base class for providers.
1125
1126 If any configuration is possible for the provider, like creden‐
1127 tials, it must take place during instantiation.
1128
1129 Raise ConfigurationError if there is a configuration error
1130
1131 languages = {}
1132 Supported set of Language
1133
1134 video_types = (<class 'subliminal.video.Episode'>, <class 'sub‐
1135 liminal.video.Movie'>)
1136 Supported video types
1137
1138 required_hash = None
1139 Required hash, if any
1140
1141 initialize()
1142 Initialize the provider.
1143
1144 Must be called when starting to work with the provider.
1145 This is the place for network initialization or login
1146 operations.
1147
1148 NOTE:
1149 This is called automatically when entering the with
1150 statement
1151
1152 terminate()
1153 Terminate the provider.
1154
1155 Must be called when done with the provider. This is the
1156 place for network shutdown or logout operations.
1157
1158 NOTE:
1159 This is called automatically when exiting the with
1160 statement
1161
1162 classmethod check(video)
1163 Check if the video can be processed.
1164
1165 The video is considered invalid if not an instance of
1166 video_types or if the required_hash is not present in
1167 hashes attribute of the video.
1168
1169 Parameters
1170 video (Video) – the video to check.
1171
1172 Returns
1173 True if the video is valid, False otherwise.
1174
1175 Return type
1176 bool
1177
1178 query(*args, **kwargs)
1179 Query the provider for subtitles.
1180
1181 Arguments should match as much as possible the actual
1182 parameters for querying the provider
1183
1184 Returns
1185 found subtitles.
1186
1187 Return type
1188 list of Subtitle
1189
1190 Raise ProviderError
1191
1192 list_subtitles(video, languages)
1193 List subtitles for the video with the given languages.
1194
1195 This will call the query() method internally. The parame‐
1196 ters passed to the query() method may vary depending on
1197 the amount of information available in the video.
1198
1199 Parameters
1200
1201 · video (Video) – video to list subtitles for.
1202
1203 · languages (set of Language) – languages to
1204 search for.
1205
1206 Returns
1207 found subtitles.
1208
1209 Return type
1210 list of Subtitle
1211
1212 Raise ProviderError
1213
1214 download_subtitle(subtitle)
1215 Download subtitle’s content.
1216
1217 Parameters
1218 subtitle (Subtitle) – subtitle to download.
1219
1220 Raise ProviderError
1221
1222 Addic7ed
1223 subliminal.providers.addic7ed.series_year_re = re.com‐
1224 pile("^(?P<series>[ \\w\\'.:(),&!?-]+?)(?: \\((?P<year>\\d{4})\\))?$")
1225 Series header parsing regex
1226
1227 class subliminal.providers.addic7ed.Addic7edSubtitle(language, hear‐
1228 ing_impaired, page_link, series, season, episode, title, year, version,
1229 download_link)
1230 Addic7ed Subtitle.
1231
1232 property id
1233 Unique identifier of the subtitle
1234
1235 get_matches(video)
1236 Get the matches against the video.
1237
1238 Parameters
1239 video (Video) – the video to get the matches with.
1240
1241 Returns
1242 matches of the subtitle.
1243
1244 Return type
1245 set
1246
1247 class subliminal.providers.addic7ed.Addic7edProvider(username=None,
1248 password=None)
1249 Addic7ed Provider.
1250
1251 initialize()
1252 Initialize the provider.
1253
1254 Must be called when starting to work with the provider.
1255 This is the place for network initialization or login
1256 operations.
1257
1258 NOTE:
1259 This is called automatically when entering the with
1260 statement
1261
1262 terminate()
1263 Terminate the provider.
1264
1265 Must be called when done with the provider. This is the
1266 place for network shutdown or logout operations.
1267
1268 NOTE:
1269 This is called automatically when exiting the with
1270 statement
1271
1272 _get_show_ids()
1273 Get the dict of show ids per series by querying the
1274 shows.php page.
1275
1276 Returns
1277 show id per series, lower case and without quotes.
1278
1279 Return type
1280 dict
1281
1282 _search_show_id(series, year=None)
1283 Search the show id from the series and year.
1284
1285 Parameters
1286
1287 · series (str) – series of the episode.
1288
1289 · year (int) – year of the series, if any.
1290
1291 Returns
1292 the show id, if found.
1293
1294 Return type
1295 int
1296
1297 get_show_id(series, year=None, country_code=None)
1298 Get the best matching show id for series, year and coun‐
1299 try_code.
1300
1301 First search in the result of _get_show_ids() and fall‐
1302 back on a search with _search_show_id().
1303
1304 Parameters
1305
1306 · series (str) – series of the episode.
1307
1308 · year (int) – year of the series, if any.
1309
1310 · country_code (str) – country code of the series,
1311 if any.
1312
1313 Returns
1314 the show id, if found.
1315
1316 Return type
1317 int
1318
1319 query(series, season, year=None, country=None)
1320 Query the provider for subtitles.
1321
1322 Arguments should match as much as possible the actual
1323 parameters for querying the provider
1324
1325 Returns
1326 found subtitles.
1327
1328 Return type
1329 list of Subtitle
1330
1331 Raise ProviderError
1332
1333 list_subtitles(video, languages)
1334 List subtitles for the video with the given languages.
1335
1336 This will call the query() method internally. The parame‐
1337 ters passed to the query() method may vary depending on
1338 the amount of information available in the video.
1339
1340 Parameters
1341
1342 · video (Video) – video to list subtitles for.
1343
1344 · languages (set of Language) – languages to
1345 search for.
1346
1347 Returns
1348 found subtitles.
1349
1350 Return type
1351 list of Subtitle
1352
1353 Raise ProviderError
1354
1355 download_subtitle(subtitle)
1356 Download subtitle’s content.
1357
1358 Parameters
1359 subtitle (Subtitle) – subtitle to download.
1360
1361 Raise ProviderError
1362
1363 LegendasTv
1364 subliminal.providers.legendastv.type_map = {'C': 'episode', 'M':
1365 'movie', 'S': 'episode'}
1366 Conversion map for types
1367
1368 subliminal.providers.legendastv.season_re = re.compile(' - (?P<sea‐
1369 son>\\d+)(\\xaa|a|st|nd|rd|th) (temporada|season)', re.IGNORECASE)
1370 BR title season parsing regex
1371
1372 subliminal.providers.legendastv.downloads_re = re.compile('(?P<down‐
1373 loads>\\d+) downloads')
1374 Downloads parsing regex
1375
1376 subliminal.providers.legendastv.rating_re = re.compile('nota (?P<rat‐
1377 ing>\\d+)')
1378 Rating parsing regex
1379
1380 subliminal.providers.legendastv.timestamp_re = re.com‐
1381 pile('(?P<day>\\d+)/(?P<month>\\d+)/(?P<year>\\d+) -
1382 (?P<hour>\\d+):(?P<minute>\\d+)')
1383 Timestamp parsing regex
1384
1385 subliminal.providers.legendastv.releases_key = 'sublimi‐
1386 nal.providers.legendastv:releases|{archive_id}'
1387 Cache key for releases
1388
1389 class subliminal.providers.legendastv.LegendasTVArchive(id, name, pack,
1390 featured, link, downloads=0, rating=0, timestamp=None)
1391 LegendasTV Archive.
1392
1393 Parameters
1394
1395 · id (str) – identifier.
1396
1397 · name (str) – name.
1398
1399 · pack (bool) – contains subtitles for multiple episodes.
1400
1401 · pack – featured.
1402
1403 · link (str) – link.
1404
1405 · downloads (int) – download count.
1406
1407 · rating (int) – rating (0-10).
1408
1409 · timestamp (datetime.datetime) – timestamp.
1410
1411 id = None
1412 Identifier
1413
1414 name = None
1415 Name
1416
1417 pack = None
1418 Pack
1419
1420 featured = None
1421 Featured
1422
1423 link = None
1424 Link
1425
1426 downloads = None
1427 Download count
1428
1429 rating = None
1430 Rating (0-10)
1431
1432 timestamp = None
1433 Timestamp
1434
1435 content = None
1436 Compressed content as rarfile.RarFile or zipfile.ZipFile
1437
1438 class subliminal.providers.legendastv.LegendasTVSubtitle(language,
1439 type, title, year, imdb_id, season, archive, name)
1440 LegendasTV Subtitle.
1441
1442 property id
1443 Unique identifier of the subtitle
1444
1445 get_matches(video, hearing_impaired=False)
1446 Get the matches against the video.
1447
1448 Parameters
1449 video (Video) – the video to get the matches with.
1450
1451 Returns
1452 matches of the subtitle.
1453
1454 Return type
1455 set
1456
1457 class subliminal.providers.legendastv.LegendasTVProvider(username=None,
1458 password=None)
1459 LegendasTV Provider.
1460
1461 Parameters
1462
1463 · username (str) – username.
1464
1465 · password (str) – password.
1466
1467 initialize()
1468 Initialize the provider.
1469
1470 Must be called when starting to work with the provider.
1471 This is the place for network initialization or login
1472 operations.
1473
1474 NOTE:
1475 This is called automatically when entering the with
1476 statement
1477
1478 terminate()
1479 Terminate the provider.
1480
1481 Must be called when done with the provider. This is the
1482 place for network shutdown or logout operations.
1483
1484 NOTE:
1485 This is called automatically when exiting the with
1486 statement
1487
1488 search_titles(title)
1489 Search for titles matching the title.
1490
1491 Parameters
1492 title (str) – the title to search for.
1493
1494 Returns
1495 found titles.
1496
1497 Return type
1498 dict
1499
1500 get_archives(title_id, language_code)
1501 Get the archive list from a given title_id and lan‐
1502 guage_code.
1503
1504 Parameters
1505
1506 · title_id (int) – title id.
1507
1508 · language_code (int) – language code.
1509
1510 Returns
1511 the archives.
1512
1513 Return type
1514 list of LegendasTVArchive
1515
1516 download_archive(archive)
1517 Download an archive’s content.
1518
1519 Parameters
1520 archive (LegendasTVArchive) – the archive to down‐
1521 load content of.
1522
1523 query(language, title, season=None, episode=None, year=None)
1524 Query the provider for subtitles.
1525
1526 Arguments should match as much as possible the actual
1527 parameters for querying the provider
1528
1529 Returns
1530 found subtitles.
1531
1532 Return type
1533 list of Subtitle
1534
1535 Raise ProviderError
1536
1537 list_subtitles(video, languages)
1538 List subtitles for the video with the given languages.
1539
1540 This will call the query() method internally. The parame‐
1541 ters passed to the query() method may vary depending on
1542 the amount of information available in the video.
1543
1544 Parameters
1545
1546 · video (Video) – video to list subtitles for.
1547
1548 · languages (set of Language) – languages to
1549 search for.
1550
1551 Returns
1552 found subtitles.
1553
1554 Return type
1555 list of Subtitle
1556
1557 Raise ProviderError
1558
1559 download_subtitle(subtitle)
1560 Download subtitle’s content.
1561
1562 Parameters
1563 subtitle (Subtitle) – subtitle to download.
1564
1565 Raise ProviderError
1566
1567 NapiProjekt
1568 subliminal.providers.napiprojekt.get_subhash(hash)
1569 Get a second hash based on napiprojekt’s hash.
1570
1571 Parameters
1572 hash (str) – napiprojekt’s hash.
1573
1574 Returns
1575 the subhash.
1576
1577 Return type
1578 str
1579
1580 class subliminal.providers.napiprojekt.NapiProjektSubtitle(language,
1581 hash)
1582 NapiProjekt Subtitle.
1583
1584 property id
1585 Unique identifier of the subtitle
1586
1587 get_matches(video)
1588 Get the matches against the video.
1589
1590 Parameters
1591 video (Video) – the video to get the matches with.
1592
1593 Returns
1594 matches of the subtitle.
1595
1596 Return type
1597 set
1598
1599 class subliminal.providers.napiprojekt.NapiProjektProvider
1600 NapiProjekt Provider.
1601
1602 initialize()
1603 Initialize the provider.
1604
1605 Must be called when starting to work with the provider.
1606 This is the place for network initialization or login
1607 operations.
1608
1609 NOTE:
1610 This is called automatically when entering the with
1611 statement
1612
1613 terminate()
1614 Terminate the provider.
1615
1616 Must be called when done with the provider. This is the
1617 place for network shutdown or logout operations.
1618
1619 NOTE:
1620 This is called automatically when exiting the with
1621 statement
1622
1623 query(language, hash)
1624 Query the provider for subtitles.
1625
1626 Arguments should match as much as possible the actual
1627 parameters for querying the provider
1628
1629 Returns
1630 found subtitles.
1631
1632 Return type
1633 list of Subtitle
1634
1635 Raise ProviderError
1636
1637 list_subtitles(video, languages)
1638 List subtitles for the video with the given languages.
1639
1640 This will call the query() method internally. The parame‐
1641 ters passed to the query() method may vary depending on
1642 the amount of information available in the video.
1643
1644 Parameters
1645
1646 · video (Video) – video to list subtitles for.
1647
1648 · languages (set of Language) – languages to
1649 search for.
1650
1651 Returns
1652 found subtitles.
1653
1654 Return type
1655 list of Subtitle
1656
1657 Raise ProviderError
1658
1659 download_subtitle(subtitle)
1660 Download subtitle’s content.
1661
1662 Parameters
1663 subtitle (Subtitle) – subtitle to download.
1664
1665 Raise ProviderError
1666
1667 OpenSubtitles
1668 class subliminal.providers.opensubtitles.OpenSubtitlesSubtitle(lan‐
1669 guage, hearing_impaired, page_link, subtitle_id, matched_by,
1670 movie_kind, hash, movie_name, movie_release_name, movie_year,
1671 movie_imdb_id, series_season, series_episode, filename, encoding)
1672 OpenSubtitles Subtitle.
1673
1674 property id
1675 Unique identifier of the subtitle
1676
1677 get_matches(video)
1678 Get the matches against the video.
1679
1680 Parameters
1681 video (Video) – the video to get the matches with.
1682
1683 Returns
1684 matches of the subtitle.
1685
1686 Return type
1687 set
1688
1689 class subliminal.providers.opensubtitles.OpenSubtitlesProvider(user‐
1690 name=None, password=None)
1691 OpenSubtitles Provider.
1692
1693 Parameters
1694
1695 · username (str) – username.
1696
1697 · password (str) – password.
1698
1699 initialize()
1700 Initialize the provider.
1701
1702 Must be called when starting to work with the provider.
1703 This is the place for network initialization or login
1704 operations.
1705
1706 NOTE:
1707 This is called automatically when entering the with
1708 statement
1709
1710 terminate()
1711 Terminate the provider.
1712
1713 Must be called when done with the provider. This is the
1714 place for network shutdown or logout operations.
1715
1716 NOTE:
1717 This is called automatically when exiting the with
1718 statement
1719
1720 query(languages, hash=None, size=None, imdb_id=None, query=None,
1721 season=None, episode=None, tag=None)
1722 Query the provider for subtitles.
1723
1724 Arguments should match as much as possible the actual
1725 parameters for querying the provider
1726
1727 Returns
1728 found subtitles.
1729
1730 Return type
1731 list of Subtitle
1732
1733 Raise ProviderError
1734
1735 list_subtitles(video, languages)
1736 List subtitles for the video with the given languages.
1737
1738 This will call the query() method internally. The parame‐
1739 ters passed to the query() method may vary depending on
1740 the amount of information available in the video.
1741
1742 Parameters
1743
1744 · video (Video) – video to list subtitles for.
1745
1746 · languages (set of Language) – languages to
1747 search for.
1748
1749 Returns
1750 found subtitles.
1751
1752 Return type
1753 list of Subtitle
1754
1755 Raise ProviderError
1756
1757 download_subtitle(subtitle)
1758 Download subtitle’s content.
1759
1760 Parameters
1761 subtitle (Subtitle) – subtitle to download.
1762
1763 Raise ProviderError
1764
1765 exception subliminal.providers.opensubtitles.OpenSubtitlesError
1766 Base class for non-generic OpenSubtitlesProvider exceptions.
1767
1768 exception subliminal.providers.opensubtitles.Unauthorized
1769 Exception raised when status is ‘401 Unauthorized’.
1770
1771 exception subliminal.providers.opensubtitles.NoSession
1772 Exception raised when status is ‘406 No session’.
1773
1774 exception subliminal.providers.opensubtitles.DownloadLimitReached
1775 Exception raised when status is ‘407 Download limit reached’.
1776
1777 exception subliminal.providers.opensubtitles.InvalidImdbid
1778 Exception raised when status is ‘413 Invalid ImdbID’.
1779
1780 exception subliminal.providers.opensubtitles.UnknownUserAgent
1781 Exception raised when status is ‘414 Unknown User Agent’.
1782
1783 exception subliminal.providers.opensubtitles.DisabledUserAgent
1784 Exception raised when status is ‘415 Disabled user agent’.
1785
1786 exception subliminal.providers.opensubtitles.ServiceUnavailable
1787 Exception raised when status is ‘503 Service Unavailable’.
1788
1789 subliminal.providers.opensubtitles.checked(response)
1790 Check a response status before returning it.
1791
1792 Parameters
1793 response – a response from a XMLRPC call to OpenSubti‐
1794 tles.
1795
1796 Returns
1797 the response.
1798
1799 Raise OpenSubtitlesError
1800
1801 Podnapisi
1802 class subliminal.providers.podnapisi.PodnapisiSubtitle(language, hear‐
1803 ing_impaired, page_link, pid, releases, title, season=None,
1804 episode=None, year=None)
1805 Podnapisi Subtitle.
1806
1807 property id
1808 Unique identifier of the subtitle
1809
1810 get_matches(video)
1811 Get the matches against the video.
1812
1813 Parameters
1814 video (Video) – the video to get the matches with.
1815
1816 Returns
1817 matches of the subtitle.
1818
1819 Return type
1820 set
1821
1822 class subliminal.providers.podnapisi.PodnapisiProvider
1823 Podnapisi Provider.
1824
1825 initialize()
1826 Initialize the provider.
1827
1828 Must be called when starting to work with the provider.
1829 This is the place for network initialization or login
1830 operations.
1831
1832 NOTE:
1833 This is called automatically when entering the with
1834 statement
1835
1836 terminate()
1837 Terminate the provider.
1838
1839 Must be called when done with the provider. This is the
1840 place for network shutdown or logout operations.
1841
1842 NOTE:
1843 This is called automatically when exiting the with
1844 statement
1845
1846 query(language, keyword, season=None, episode=None, year=None)
1847 Query the provider for subtitles.
1848
1849 Arguments should match as much as possible the actual
1850 parameters for querying the provider
1851
1852 Returns
1853 found subtitles.
1854
1855 Return type
1856 list of Subtitle
1857
1858 Raise ProviderError
1859
1860 list_subtitles(video, languages)
1861 List subtitles for the video with the given languages.
1862
1863 This will call the query() method internally. The parame‐
1864 ters passed to the query() method may vary depending on
1865 the amount of information available in the video.
1866
1867 Parameters
1868
1869 · video (Video) – video to list subtitles for.
1870
1871 · languages (set of Language) – languages to
1872 search for.
1873
1874 Returns
1875 found subtitles.
1876
1877 Return type
1878 list of Subtitle
1879
1880 Raise ProviderError
1881
1882 download_subtitle(subtitle)
1883 Download subtitle’s content.
1884
1885 Parameters
1886 subtitle (Subtitle) – subtitle to download.
1887
1888 Raise ProviderError
1889
1890 Shooter
1891 class subliminal.providers.shooter.ShooterSubtitle(language, hash,
1892 download_link)
1893 Shooter Subtitle.
1894
1895 property id
1896 Unique identifier of the subtitle
1897
1898 get_matches(video)
1899 Get the matches against the video.
1900
1901 Parameters
1902 video (Video) – the video to get the matches with.
1903
1904 Returns
1905 matches of the subtitle.
1906
1907 Return type
1908 set
1909
1910 class subliminal.providers.shooter.ShooterProvider
1911 Shooter Provider.
1912
1913 initialize()
1914 Initialize the provider.
1915
1916 Must be called when starting to work with the provider.
1917 This is the place for network initialization or login
1918 operations.
1919
1920 NOTE:
1921 This is called automatically when entering the with
1922 statement
1923
1924 terminate()
1925 Terminate the provider.
1926
1927 Must be called when done with the provider. This is the
1928 place for network shutdown or logout operations.
1929
1930 NOTE:
1931 This is called automatically when exiting the with
1932 statement
1933
1934 query(language, filename, hash=None)
1935 Query the provider for subtitles.
1936
1937 Arguments should match as much as possible the actual
1938 parameters for querying the provider
1939
1940 Returns
1941 found subtitles.
1942
1943 Return type
1944 list of Subtitle
1945
1946 Raise ProviderError
1947
1948 list_subtitles(video, languages)
1949 List subtitles for the video with the given languages.
1950
1951 This will call the query() method internally. The parame‐
1952 ters passed to the query() method may vary depending on
1953 the amount of information available in the video.
1954
1955 Parameters
1956
1957 · video (Video) – video to list subtitles for.
1958
1959 · languages (set of Language) – languages to
1960 search for.
1961
1962 Returns
1963 found subtitles.
1964
1965 Return type
1966 list of Subtitle
1967
1968 Raise ProviderError
1969
1970 download_subtitle(subtitle)
1971 Download subtitle’s content.
1972
1973 Parameters
1974 subtitle (Subtitle) – subtitle to download.
1975
1976 Raise ProviderError
1977
1978 SubsCenter
1979 class subliminal.providers.subscenter.SubsCenterSubtitle(language,
1980 hearing_impaired, page_link, series, season, episode, title, subti‐
1981 tle_id, subtitle_key, downloaded, releases)
1982 SubsCenter Subtitle.
1983
1984 property id
1985 Unique identifier of the subtitle
1986
1987 get_matches(video)
1988 Get the matches against the video.
1989
1990 Parameters
1991 video (Video) – the video to get the matches with.
1992
1993 Returns
1994 matches of the subtitle.
1995
1996 Return type
1997 set
1998
1999 class subliminal.providers.subscenter.SubsCenterProvider(username=None,
2000 password=None)
2001 SubsCenter Provider.
2002
2003 initialize()
2004 Initialize the provider.
2005
2006 Must be called when starting to work with the provider.
2007 This is the place for network initialization or login
2008 operations.
2009
2010 NOTE:
2011 This is called automatically when entering the with
2012 statement
2013
2014 terminate()
2015 Terminate the provider.
2016
2017 Must be called when done with the provider. This is the
2018 place for network shutdown or logout operations.
2019
2020 NOTE:
2021 This is called automatically when exiting the with
2022 statement
2023
2024 _search_url_titles(title)
2025 Search the URL titles by kind for the given title.
2026
2027 Parameters
2028 title (str) – title to search for.
2029
2030 Returns
2031 the URL titles by kind.
2032
2033 Return type
2034 collections.defaultdict
2035
2036 query(title, season=None, episode=None)
2037 Query the provider for subtitles.
2038
2039 Arguments should match as much as possible the actual
2040 parameters for querying the provider
2041
2042 Returns
2043 found subtitles.
2044
2045 Return type
2046 list of Subtitle
2047
2048 Raise ProviderError
2049
2050 list_subtitles(video, languages)
2051 List subtitles for the video with the given languages.
2052
2053 This will call the query() method internally. The parame‐
2054 ters passed to the query() method may vary depending on
2055 the amount of information available in the video.
2056
2057 Parameters
2058
2059 · video (Video) – video to list subtitles for.
2060
2061 · languages (set of Language) – languages to
2062 search for.
2063
2064 Returns
2065 found subtitles.
2066
2067 Return type
2068 list of Subtitle
2069
2070 Raise ProviderError
2071
2072 download_subtitle(subtitle)
2073 Download subtitle’s content.
2074
2075 Parameters
2076 subtitle (Subtitle) – subtitle to download.
2077
2078 Raise ProviderError
2079
2080 TheSubDB
2081 class subliminal.providers.thesubdb.TheSubDBSubtitle(language, hash)
2082 TheSubDB Subtitle.
2083
2084 property id
2085 Unique identifier of the subtitle
2086
2087 get_matches(video)
2088 Get the matches against the video.
2089
2090 Parameters
2091 video (Video) – the video to get the matches with.
2092
2093 Returns
2094 matches of the subtitle.
2095
2096 Return type
2097 set
2098
2099 class subliminal.providers.thesubdb.TheSubDBProvider
2100 TheSubDB Provider.
2101
2102 initialize()
2103 Initialize the provider.
2104
2105 Must be called when starting to work with the provider.
2106 This is the place for network initialization or login
2107 operations.
2108
2109 NOTE:
2110 This is called automatically when entering the with
2111 statement
2112
2113 terminate()
2114 Terminate the provider.
2115
2116 Must be called when done with the provider. This is the
2117 place for network shutdown or logout operations.
2118
2119 NOTE:
2120 This is called automatically when exiting the with
2121 statement
2122
2123 query(hash)
2124 Query the provider for subtitles.
2125
2126 Arguments should match as much as possible the actual
2127 parameters for querying the provider
2128
2129 Returns
2130 found subtitles.
2131
2132 Return type
2133 list of Subtitle
2134
2135 Raise ProviderError
2136
2137 list_subtitles(video, languages)
2138 List subtitles for the video with the given languages.
2139
2140 This will call the query() method internally. The parame‐
2141 ters passed to the query() method may vary depending on
2142 the amount of information available in the video.
2143
2144 Parameters
2145
2146 · video (Video) – video to list subtitles for.
2147
2148 · languages (set of Language) – languages to
2149 search for.
2150
2151 Returns
2152 found subtitles.
2153
2154 Return type
2155 list of Subtitle
2156
2157 Raise ProviderError
2158
2159 download_subtitle(subtitle)
2160 Download subtitle’s content.
2161
2162 Parameters
2163 subtitle (Subtitle) – subtitle to download.
2164
2165 Raise ProviderError
2166
2167 TVsubtitles
2168 class subliminal.providers.tvsubtitles.TVsubtitlesSubtitle(language,
2169 page_link, subtitle_id, series, season, episode, year, rip, release)
2170 TVsubtitles Subtitle.
2171
2172 property id
2173 Unique identifier of the subtitle
2174
2175 get_matches(video)
2176 Get the matches against the video.
2177
2178 Parameters
2179 video (Video) – the video to get the matches with.
2180
2181 Returns
2182 matches of the subtitle.
2183
2184 Return type
2185 set
2186
2187 class subliminal.providers.tvsubtitles.TVsubtitlesProvider
2188 TVsubtitles Provider.
2189
2190 initialize()
2191 Initialize the provider.
2192
2193 Must be called when starting to work with the provider.
2194 This is the place for network initialization or login
2195 operations.
2196
2197 NOTE:
2198 This is called automatically when entering the with
2199 statement
2200
2201 terminate()
2202 Terminate the provider.
2203
2204 Must be called when done with the provider. This is the
2205 place for network shutdown or logout operations.
2206
2207 NOTE:
2208 This is called automatically when exiting the with
2209 statement
2210
2211 search_show_id(series, year=None)
2212 Search the show id from the series and year.
2213
2214 Parameters
2215
2216 · series (str) – series of the episode.
2217
2218 · year (int) – year of the series, if any.
2219
2220 Returns
2221 the show id, if any.
2222
2223 Return type
2224 int
2225
2226 get_episode_ids(show_id, season)
2227 Get episode ids from the show id and the season.
2228
2229 Parameters
2230
2231 · show_id (int) – show id.
2232
2233 · season (int) – season of the episode.
2234
2235 Returns
2236 episode ids per episode number.
2237
2238 Return type
2239 dict
2240
2241 query(series, season, episode, year=None)
2242 Query the provider for subtitles.
2243
2244 Arguments should match as much as possible the actual
2245 parameters for querying the provider
2246
2247 Returns
2248 found subtitles.
2249
2250 Return type
2251 list of Subtitle
2252
2253 Raise ProviderError
2254
2255 list_subtitles(video, languages)
2256 List subtitles for the video with the given languages.
2257
2258 This will call the query() method internally. The parame‐
2259 ters passed to the query() method may vary depending on
2260 the amount of information available in the video.
2261
2262 Parameters
2263
2264 · video (Video) – video to list subtitles for.
2265
2266 · languages (set of Language) – languages to
2267 search for.
2268
2269 Returns
2270 found subtitles.
2271
2272 Return type
2273 list of Subtitle
2274
2275 Raise ProviderError
2276
2277 download_subtitle(subtitle)
2278 Download subtitle’s content.
2279
2280 Parameters
2281 subtitle (Subtitle) – subtitle to download.
2282
2283 Raise ProviderError
2284
2285 Refiners
2286 Refiners enrich a Video object by adding information to it.
2287
2288 A refiner is a simple function:
2289
2290 subliminal.refiners.refine(video, **kwargs)
2291
2292 Parameters
2293
2294 · video (Video) – the video to refine.
2295
2296 · **kwargs – additional parameters for refiners.
2297
2298 Metadata
2299 subliminal.refiners.metadata.refine(video, embedded_subtitles=True,
2300 **kwargs)
2301 Refine a video by searching its metadata.
2302
2303 Several Video attributes can be found:
2304
2305 · resolution
2306
2307 · video_codec
2308
2309 · audio_codec
2310
2311 · subtitle_languages
2312
2313 Parameters
2314 embedded_subtitles (bool) – search for embedded subti‐
2315 tles.
2316
2317 TVDB
2318 subliminal.refiners.tvdb.refine(video, **kwargs)
2319 Refine a video by searching TheTVDB.
2320
2321 NOTE:
2322 This refiner only work for instances of Episode.
2323
2324 Several attributes can be found:
2325
2326 · series
2327
2328 · year
2329
2330 · series_imdb_id
2331
2332 · series_tvdb_id
2333
2334 · title
2335
2336 · imdb_id
2337
2338 · tvdb_id
2339
2340 OMDb
2341 subliminal.refiners.omdb.refine(video, **kwargs)
2342 Refine a video by searching OMDb API.
2343
2344 Several Episode attributes can be found:
2345
2346 · series
2347
2348 · year
2349
2350 · series_imdb_id
2351
2352 Similarly, for a Movie:
2353
2354 · title
2355
2356 · year
2357
2358 · imdb_id
2359
2360 Extensions
2361 class subliminal.extensions.RegistrableExtensionManager(namespace,
2362 internal_extensions, **kwargs)
2363 :class:~stevedore.extensions.ExtensionManager` with support for
2364 registration.
2365
2366 It allows loading of internal extensions without setup and reg‐
2367 istering/unregistering additional extensions.
2368
2369 Loading is done in this order:
2370
2371 · Entry point extensions
2372
2373 · Internal extensions
2374
2375 · Registered extensions
2376
2377 Parameters
2378
2379 · namespace (str) – namespace argument for :class:~steve‐
2380 dore.extensions.ExtensionManager`.
2381
2382 · internal_extensions (list) – internal extensions to use
2383 with entry point syntax.
2384
2385 · **kwargs – additional parameters for the :class:~steve‐
2386 dore.extensions.ExtensionManager` constructor.
2387
2388 registered_extensions = None
2389 Registered extensions with entry point syntax
2390
2391 internal_extensions = None
2392 Internal extensions with entry point syntax
2393
2394 register(entry_point)
2395 Register an extension
2396
2397 Parameters
2398 entry_point (str) – extension to register (entry
2399 point syntax).
2400
2401 Raise ValueError if already registered.
2402
2403 unregister(entry_point)
2404 Unregister a provider
2405
2406 Parameters
2407 entry_point (str) – provider to unregister (entry
2408 point syntax).
2409
2410 subliminal.extensions.provider_manager = <subliminal.extensions.Regis‐
2411 trableExtensionManager object>
2412 Provider manager
2413
2414 subliminal.extensions.refiner_manager = <subliminal.extensions.Regis‐
2415 trableExtensionManager object>
2416 Refiner manager
2417
2418 Score
2419 This module provides the default implementation of the compute_score
2420 parameter in download_best_subtitles() and download_best_subtitles().
2421
2422 NOTE:
2423 To avoid unnecessary dependency on sympy and boost subliminal’s
2424 import time, the resulting scores are hardcoded here and manually
2425 updated when the set of equations change.
2426
2427 Available matches:
2428
2429 · hash
2430
2431 · title
2432
2433 · year
2434
2435 · series
2436
2437 · season
2438
2439 · episode
2440
2441 · release_group
2442
2443 · format
2444
2445 · audio_codec
2446
2447 · resolution
2448
2449 · hearing_impaired
2450
2451 · video_codec
2452
2453 · series_imdb_id
2454
2455 · imdb_id
2456
2457 · tvdb_id
2458
2459 subliminal.score.episode_scores = {'audio_codec': 3, 'episode': 30,
2460 'format': 7, 'hash': 359, 'hearing_impaired': 1, 'release_group': 15,
2461 'resolution': 2, 'season': 30, 'series': 180, 'video_codec': 2, 'year':
2462 90}
2463 Scores for episodes
2464
2465 subliminal.score.movie_scores = {'audio_codec': 3, 'format': 7, 'hash':
2466 119, 'hearing_impaired': 1, 'release_group': 15, 'resolution': 2,
2467 'title': 60, 'video_codec': 2, 'year': 30}
2468 Scores for movies
2469
2470 subliminal.score.equivalent_release_groups = ({'DIMENSION', 'LOL'},
2471 {'ASAP', 'IMMERSE', 'FLEET'})
2472 Equivalent release groups
2473
2474 subliminal.score.get_equivalent_release_groups(release_group)
2475 Get all the equivalents of the given release group.
2476
2477 Parameters
2478 release_group (str) – the release group to get the equiv‐
2479 alents of.
2480
2481 Returns
2482 the equivalent release groups.
2483
2484 Return type
2485 set
2486
2487 subliminal.score.get_scores(video)
2488 Get the scores dict for the given video.
2489
2490 This will return either episode_scores or movie_scores based on
2491 the type of the video.
2492
2493 Parameters
2494 video (Video) – the video to compute the score against.
2495
2496 Returns
2497 the scores dict.
2498
2499 Return type
2500 dict
2501
2502 subliminal.score.compute_score(subtitle, video, hearing_impaired=None)
2503 Compute the score of the subtitle against the video with hear‐
2504 ing_impaired preference.
2505
2506 compute_score() uses the Subtitle.get_matches method and applies
2507 the scores (either from episode_scores or movie_scores) after
2508 some processing.
2509
2510 Parameters
2511
2512 · subtitle (Subtitle) – the subtitle to compute the score
2513 of.
2514
2515 · video (Video) – the video to compute the score against.
2516
2517 · hearing_impaired (bool) – hearing impaired preference.
2518
2519 Returns
2520 score of the subtitle.
2521
2522 Return type
2523 int
2524
2525 Utils
2526 subliminal.utils.hash_opensubtitles(video_path)
2527 Compute a hash using OpenSubtitles’ algorithm.
2528
2529 Parameters
2530 video_path (str) – path of the video.
2531
2532 Returns
2533 the hash.
2534
2535 Return type
2536 str
2537
2538 subliminal.utils.hash_thesubdb(video_path)
2539 Compute a hash using TheSubDB’s algorithm.
2540
2541 Parameters
2542 video_path (str) – path of the video.
2543
2544 Returns
2545 the hash.
2546
2547 Return type
2548 str
2549
2550 subliminal.utils.hash_napiprojekt(video_path)
2551 Compute a hash using NapiProjekt’s algorithm.
2552
2553 Parameters
2554 video_path (str) – path of the video.
2555
2556 Returns
2557 the hash.
2558
2559 Return type
2560 str
2561
2562 subliminal.utils.hash_shooter(video_path)
2563 Compute a hash using Shooter’s algorithm
2564
2565 Parameters
2566 video_path (string) – path of the video
2567
2568 Returns
2569 the hash
2570
2571 Return type
2572 string
2573
2574 subliminal.utils.sanitize(string, ignore_characters=None)
2575 Sanitize a string to strip special characters.
2576
2577 Parameters
2578
2579 · string (str) – the string to sanitize.
2580
2581 · ignore_characters (set) – characters to ignore.
2582
2583 Returns
2584 the sanitized string.
2585
2586 Return type
2587 str
2588
2589 subliminal.utils.sanitize_release_group(string)
2590 Sanitize a release_group string to remove content in square
2591 brackets.
2592
2593 Parameters
2594 string (str) – the release group to sanitize.
2595
2596 Returns
2597 the sanitized release group.
2598
2599 Return type
2600 str
2601
2602 subliminal.utils.timestamp(date)
2603 Get the timestamp of the date, python2/3 compatible
2604
2605 Parameters
2606 date (datetime.datetime) – the utc date.
2607
2608 Returns
2609 the timestamp of the date.
2610
2611 Return type
2612 float
2613
2614 Cache
2615 subliminal.cache.SHOW_EXPIRATION_TIME
2616 Expiration time for show caching
2617
2618 subliminal.cache.EPISODE_EXPIRATION_TIME
2619 Expiration time for episode caching
2620
2621 subliminal.cache.REFINER_EXPIRATION_TIME
2622 Expiration time for scraper searches
2623
2624 subliminal.cache.region
2625 The CacheRegion
2626
2627 Refer to dogpile.cache’s region configuration documentation to see how
2628 to configure the region
2629
2630 CLI
2631 Subliminal uses click to provide a powerful CLI.
2632
2633 class subliminal.cli.MutexLock(filename)
2634 MutexLock is a thread-based rw lock based on dogpile.core.Read‐
2635 WriteMutex.
2636
2637 acquire_read_lock(wait)
2638 Acquire a ‘reader’ lock.
2639
2640 Raises NotImplementedError by default, must be imple‐
2641 mented by subclasses.
2642
2643 acquire_write_lock(wait)
2644 Acquire a ‘write’ lock.
2645
2646 Raises NotImplementedError by default, must be imple‐
2647 mented by subclasses.
2648
2649 release_read_lock()
2650 Release a ‘reader’ lock.
2651
2652 Raises NotImplementedError by default, must be imple‐
2653 mented by subclasses.
2654
2655 release_write_lock()
2656 Release a ‘writer’ lock.
2657
2658 Raises NotImplementedError by default, must be imple‐
2659 mented by subclasses.
2660
2661 class subliminal.cli.Config(path)
2662 A ConfigParser wrapper to store configuration.
2663
2664 Interaction with the configuration is done with the properties.
2665
2666 Parameters
2667 path (str) – path to the configuration file.
2668
2669 path = None
2670 Path to the configuration file
2671
2672 config = None
2673 The underlying configuration object
2674
2675 read() Read the configuration from path
2676
2677 write()
2678 Write the configuration to path
2679
2680 class subliminal.cli.LanguageParamType
2681 ParamType for languages that returns a Language
2682
2683 convert(value, param, ctx)
2684 Converts the value. This is not invoked for values that
2685 are None (the missing value).
2686
2687 class subliminal.cli.AgeParamType
2688 ParamType for age strings that returns a timedelta
2689
2690 An age string is in the form number + identifier with possible
2691 identifiers:
2692
2693 · w for weeks
2694
2695 · d for days
2696
2697 · h for hours
2698
2699 The form can be specified multiple times but only with that
2700 idenfier ordering. For example:
2701
2702 · 1w2d4h for 1 week, 2 days and 4 hours
2703
2704 · 2w for 2 weeks
2705
2706 · 3w6h for 3 weeks and 6 hours
2707
2708 convert(value, param, ctx)
2709 Converts the value. This is not invoked for values that
2710 are None (the missing value).
2711
2712 Exceptions
2713 exception subliminal.exceptions.Error
2714 Base class for exceptions in subliminal.
2715
2716 exception subliminal.exceptions.ProviderError
2717 Exception raised by providers.
2718
2719 exception subliminal.exceptions.ConfigurationError
2720 Exception raised by providers when badly configured.
2721
2722 exception subliminal.exceptions.AuthenticationError
2723 Exception raised by providers when authentication failed.
2724
2725 exception subliminal.exceptions.TooManyRequests
2726 Exception raised by providers when too many requests are made.
2727
2728 exception subliminal.exceptions.DownloadLimitExceeded
2729 Exception raised by providers when download limit is exceeded.
2730
2732 MIT
2733
2734 · genindex
2735
2736 · modindex
2737
2738 · search
2739
2741 Antoine Bertin
2742
2744 2019, Antoine Bertin
2745
2746
2747
2748
27492.0.5 Jul 26, 2019 SUBLIMINAL(1)