meermanr / tvseriesrenamer Goto Github PK
View Code? Open in Web Editor NEWScript for renaming files in a digital video collection. Automatically fetches episode titles from the web.
Home Page: http://www.robmeerman.co.uk/coding/file_renamer
Script for renaming files in a digital video collection. Automatically fetches episode titles from the web.
Home Page: http://www.robmeerman.co.uk/coding/file_renamer
Seems that tv.com site has changed and the parser is now longer working.
The script keeps commas around, but Epguides strips them. Examples:
http://epguides.com/FirstLoveSecondChance/
http://epguides.com/GoDiegoGo/
http://epguides.com/LittlePeopleBigWorld/
The format of EpGuides seems to have changed. Special episodes are not listes as "S-xx" but often as "Sx", so the parser doesn't realize it.
Example: http://epguides.com/ITCrowd/
Other Episodes
Special S4 27/Sep/13 The Internet Is Coming (60 min)
Currently, AniDB instantly bans for usage of scripts that dump the data directly, including TVSeriesRenamer.
Moderator (worf) confirmed this.
Currently, only API access is supported: http://wiki.anidb.net/w/API
Epguides seems to have changed how years are represented.
TVRenamer:
Can't fetch "http://epguides.com/Flash2014/", please check this URL in a browser
Actual URL is http://epguides.com/Flash_2014/.
I can't believe I've been using this script for ten years :-D
Just a quick "issue" to ask if TheTVDB support is planned at all or not really.
Adding TheTVDB would open two additional options: Selecting ordering preference and selecting alternate languages.
http://thetvdb.com/?tab=seasonall&id=267440&lid=7
vs
STR:
[~]$ mkdir /tmp/foo
[~]$ cd /tmp/foo
[/tmp/foo]$ tvrenamer.pl
TV Series Renamer v2.56
Released 24 April 2012
Autodetecting season number failed
Detected series name 'foo' (Season 1 (assumed))
Reading input in AutoFetch mode from EpGuides.com
Fetching document ...
Can't fetch "http://epguides.com/foo/", please check this URL in a browser
Consider specifying an URL on the command-line. Error was:
No useable results. Trying: TV.com
Performing search...
Match = season-1/Found match!
Creating link file in current directory to avoid repeating search...
Unsupported input source: "season-1/"%
[/tmp/foo]$ ls -l
total 8
-rw-r--r-- 1 fred wheel 33 Jan 23 09:24 foo (Season 1) [TV.com].URL
[/tmp/foo]$
I use following scheme to clean up my files: tvrenamer.pl --scheme=SXXEYY --pad=2 --include-series --separator=" "
which ends up with file names like Series Title S00E00 A Title.suffix
. This works well.
To automatise this I created a ".tvrenamerrc":
$ cat ~/.tvrenamerrc
--scheme=SXXEYY
--pad=2
--include-series
--separator=" "
But now the file names end up like Series Title S00E00" "A Title.suffix
, which is not what I would expect to happen.
Changing ".tvrenamerrc" to:
$ cat ~/.tvrenamerrc
--scheme=SXXEYY
--pad=2
--include-series
--separator=
works around the problem. The line with --separator=
ends with a (invisible) space (which makes the file somewhat hard to maintain as one needs to be aware of the kludge.) I think the config file parser should ignore quotes in such cases for consistency with the command line handling.
Common episode titles only very rarely use UTF-8, but anyway: tvrenamer does not handle UTF-8 right. Instead of handling a multi-byte character as a single character, it interprets the string as ASCII and misnames the files.
Some test cases would be:
http://epguides.com/Stromberg/ -> season 1, episode 7 has an o-umlaut
http://epguides.com/City/ -> season 1, episode 22 has a utf-8 ellipsis
Considering epguides correctly identifies its pages as being utf-8, the script should probably handle them as such too.
Hope this isn't too hard to fix. (We both know in Python it wouldn't be ;) )
I usually fetch titles via "epguide.com". In some cases the resulting filenames contain superfluous extra junk that is not filtered properly (or could/should be filtered).
E.g. Episodes of season 1 and 2 of http://epguides.com/realhusbandsofhollywood/ have some "(60 min)" marker at the end which is not properly stripped and ends up as Series Title S00E00 Episode Title--a- (60 min).suffix
.
Another problem that I sometimes notice is that &
ends up as part of the episode title in the filenames rather than just &
, e.g. Series S00E00 Foo & Bar.suffix
.
Although it's just a flavor of AVI, .divx is also a valid video extension (that I've seen used before). Might make sense to add to the regex.
http://en.wikipedia.org/wiki/DivX#DivX_Media_Format_.28DMF.29
From #21:
Another problem that I sometimes notice is that & ends up as part of the episode title in the filenames rather than just &, e.g.
Series S00E00 Foo & Bar.suffix
.
Just for completeness an example for the&
issue: it would happen with episode 13 of season 26 of http://epguides.com/Simpsons/, the file name becomes likeThe Simpsons S26E14 Walking Big & Tall.mp4
.
tvrenamer.pl v2.53
perl v5.8.8
$ ~/tmp/tvrenamer.pl --help
Sequence (?P...) not recognized in regex; marked by <-- HERE in m/^(?P <-- HERE <prefix>.*)(?:season|series)\s*(?P<season>\d+)\s*$/ at /home/samba/tmp/tvrenamer.pl line 374.
Line 374,375 look like this:
if( $series =~ m{^(?P<prefix>.*)(?:season|series)\s*(?P<season>\d+)\s*$}i
or $series =~ m{^\s*(?P<season>\d+)\s*$}i ){
Can I clean up run.py and make it look pythonic? If so, I'll submit a pull request :)
I am quite impressed how well the script works so I am happy to help a bit keeping the test suite look nice and shiny.
Let me know!
is shortened to http://epguides.com/DoctorWho2005
should be http://epguides.com/DoctorWho_2005
Error: Modification of a read-only value attempted at tvrenamer.pl line 1750.
user@computer:/mnt/data/Series/ShowName$ perl -W ~/tvrenamer.pl
Illegal hexadecimal digit '|' ignored at /home/user/tvrenamer.pl line 519.
Illegal hexadecimal digit '|' ignored at /home/user/tvrenamer.pl line 519.
Illegal hexadecimal digit '|' ignored at /home/user/tvrenamer.pl line 530.
Illegal hexadecimal digit '|' ignored at /home/user/tvrenamer.pl line 530.
\1 better written as $1 at /home/user/tvrenamer.pl line 664.
\1 better written as $1 at /home/user/tvrenamer.pl line 665.
Illegal hexadecimal digit '|' ignored at /home/user/tvrenamer.pl line 751.
Illegal hexadecimal digit '|' ignored at /home/user/tvrenamer.pl line 751.
\1 better written as $1 at /home/user/tvrenamer.pl line 841.
"my" variable $i masks earlier declaration in same scope at /home/user/tvrenamer.pl line 1207.
"my" variable $i masks earlier declaration in same scope at /home/user/tvrenamer.pl line 1209.
Illegal hexadecimal digit '|' ignored at /home/user/tvrenamer.pl line 1461.
Illegal hexadecimal digit '|' ignored at /home/user/tvrenamer.pl line 1461.
Scalar value @first[...] better written as $first[...] at /home/user/tvrenamer.pl line 1397.
Scalar value @second[...] better written as $second[...] at /home/user/tvrenamer.pl line 1397.
Name "Encode::Locale::ENCODING_UTF-8" used only once: possible typo at /usr/share/perl5/Encode/Locale.pm line 106.
TV Series Renamer v2.56
Released 24 April 2012
Use of uninitialized value $ENV{"USERPROFILE"} in concatenation (.) or string at /home/user/tvrenamer.pl line 287.
Use of uninitialized value $ENV{"USERPROFILE"} in concatenation (.) or string at /home/user/tvrenamer.pl line 288.
Reading preferences from /home/user/.tvrenamerrc
Autodetecting season number failed
Use of uninitialized value $inputFile in string eq at /home/user/tvrenamer.pl line 601.
Detected series name 'ShowName' (Season 1 (assumed))
Reading input in AutoFetch mode from EpGuides.com
Input is URL: http://epguides.com/Dexter/
Checking freshness of .cache...
Cache is 0.0159490740740741 days old. (15min = 0.0104166666666667)
could be fresher
Fetching document http://epguides.com/ShowName/... [Done]
Use of uninitialized value $epTitle in substitution (s///) at /home/user/tvrenamer.pl line 1063.
Use of uninitialized value $data in substitution (s///) at /home/user/tvrenamer.pl line 1740.
Use of uninitialized value $data in substitution (s///) at /home/user/tvrenamer.pl line 1741.
Use of uninitialized value $epTitle in substitution (s///) at /home/user/tvrenamer.pl line 1063.
Use of uninitialized value $data in substitution (s///) at /home/user/tvrenamer.pl line 1740.
Use of uninitialized value $data in substitution (s///) at /home/user/tvrenamer.pl line 1741.
Modification of a read-only value attempted at /home/user/tvrenamer.pl line 1750.
* Name of show substituted to generic ShowName
nl -b a ~/tvrenamer.pl | sed -n 1746,1761p
1746 sub clean_up #{{{
1747 {
1748 # Prepare arguments for filesystem, and do some tidying
1749 foreach(@_){
1750 tr/\\/-/; # Replace invalid char \ with -
1751 tr/\//-/; # Replace invalid char / with -
1752 tr/\*/-/; # Replace invalid char * with -
1753 tr/\</-/; # Replace invalid char < with (
1754 tr/\>/-/; # Replace invalid char > with )
1755 tr/\:/-/; # Replace invalid char : with -
1756 tr/\x60/\x27/; # Replace ` with ' (Using ANSI char vals in _hex_)
1757 tr/\x22/\x27/; # Replace " with '
1758 tr/\x3F//d; # Delete invalid char '?'
1759 }
1760 return @_;
1761 } #}}} End sub
perl --version
This is perl 5, version 20, subversion 1 (v5.20.1) built for i686-linux-gnu-thread-multi-64int
http://www.perlmonks.org/?node_id=570712#param_lvalue
Common Causes for "Modification of a read-only value attempted"
Modifying elements of @_ directly
http://perldoc.perl.org/perlvar.html#General-Variables
@_
Within a subroutine the array @_ contains the parameters passed to that subroutine. Inside a subroutine, @_ is the default array for the array operators push, pop, shift, and unshift.
See perlsub.
http://perldoc.perl.org/perlsub.html
Because the assignment copies the values, this also has the effect of turning call-by-reference into call-by-value. Otherwise a function is free to do in-place modifications of @_ and change its caller's values.
upcase_in($v1, $v2); # this changes $v1 and $v2 sub upcase_in { for (@_) { tr/a-z/A-Z/ } }You aren't allowed to modify constants in this way, of course. If an argument were actually literal and you tried to change it, you'd take a (presumably fatal) exception. For example, this won't work:
Search for "not renmaing either!" (sic) in the .pl file.
TV Series Renamer v2.56
Released 24 April 2012
Detected series name 'Homeland' (Season 7)
Reading input in AutoFetch mode from EpGuides.com
Input is URL: http://epguides.com/Homeland/
Will not look for cache file
Fetching document http://epguides.com/Homeland/... [Done]
No useable results. Trying: TV.com
Search URL: http://www.tv.com/index.php?type=Search&stype=ajax_search&qs=Homelan
d&search_type=program&pg_results=0&sort=
Performing search...
Problem with server (received 0 bytes)...
Performing search...
Problem with server (received 0 bytes)...
Performing search...
Problem with server (received 0 bytes)...
Unable to perform search on TV.com! (Fetched bytes of data) Please try the foll
owing in a browser:
http://www.tv.com/index.php?type=Search&stype=ajax_search&qs=Homeland&search_t
ype=program&pg_results=0&sort=
at /cygdrive/c/bin/tvrenamer.pl line 693.
(Originally reported by KlfJoat in his comment on commit 22f4cf7)
The change on line 668 is bad. This breaks such things as "Thundercats 2011". The URL on epguides.com is "Thundercats_2011". So if I specify --series="Thundercats_2011", this regex changes the underscore to a space, making the episode names unfindable on epguides.com. (it's also unfindable on tv.com, which this fix is supposed to help with)
Regardless of how they get there (I am looking at you, OS X), the script should probably ignore dotfiles.
I have these files, for example:
._12 - Awesome Episode.mp4
12 - Awesome Episode.mp4
The former is OS X's doing.
Epguides auto-generates its URLs by removing "The" from the beginning, but also "A". The script does the former but not the latter.
Examples of such show names are rare, but:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.