Kodi Community Forum

Full Version: Detect tmdb#id in filename
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi world,

I'm a kodi user since sooo long (a XBMC user on xbox1 to be precise !) ... and I'ml sooo grateful for the result now in 2022.

Since some years, I have more and more movies not found by scrapper, even when I copy-paste the exact title from TMDB ... annoying ...

So here is the idea : the scrapper could take the TMDB #id directly from filename when detected ... ie : "LotR - Two Towers (2002)(tmdb#122).mkv"

Something like that already exist during movie searching but it's not really easy to use imo.

Thanks for reading  Music

Z3b
(2022-05-30, 00:42)Z3b2G Wrote: [ -> ]Since some years, I have more and more movies not found by scrapper, even when I copy-paste the exact title from TMDB
Other options are...

1. Use a Parsing NFO file... https://kodi.wiki/view/NFO_files/Parsing
2. Use the Search in Kodi... https://kodi.wiki/view/Add-on:The_Movie_...hon#Search
(2022-05-30, 01:00)Karellen Wrote: [ -> ]
(2022-05-30, 00:42)Z3b2G Wrote: [ -> ]Since some years, I have more and more movies not found by scrapper, even when I copy-paste the exact title from TMDB
Other options are...

1. Use a Parsing NFO file... https://kodi.wiki/view/NFO_files/Parsing
2. Use the Search in Kodi... https://kodi.wiki/view/Add-on:The_Movie_...hon#Search
Yes, I know ... but this is not really nice imho.

Thanks  Angel
The funy part is that looks already here ... 

from https://github.com/xbmc/metadata.themovi...er/tmdb.py
Quote:def _parse_media_id(title):
if title.startswith('tt') and title[2:].isdigit():
return {'type': 'imdb', 'id':title} # IMDB ID works alone because it is clear
title = title.lower()
if title.startswith('tmdb/') and title[5:].isdigit(): # TMDB ID
return {'type': 'tmdb', 'id':title[5:]}
elif title.startswith('imdb/tt') and title[7:].isdigit(): # IMDB ID with prefix to match
return {'type': 'imdb', 'id':title[5:]}
return None

and if i rename my file "tt4574334.mkv" ... magic ... thie file is now a well known TV show ...

...work in progress ...
I'm not a dev python, but I think something like that could work :
python:

def _parse_media_id(title):
    if title.startswith('tt') and title[2:].isdigit():
        return {'type': 'imdb', 'id':title} # IMDB ID works alone because it is clear
    title = title.lower()
    if title.startswith('tmdb/') and title[5:].isdigit(): # TMDB ID
        return {'type': 'tmdb', 'id':title[5:]}
    elif title.startswith('imdb/tt') and title[7:].isdigit(): # IMDB ID with prefix to match
        return {'type': 'imdb', 'id':title[5:]}
    elif title.find("(tmdb#")!=-1    and title[title.find("(tmdb#")+6:-1].isdigit():
      return {'type': 'tmdb', 'id':title[title.find("(tmdb#")+6:-1]}
    return None
@Z3b2G

Someone has asked about this also a few days ago. See the reply by @rmrector ... https://forum.kodi.tv/showthread.php?tid...pid3098741
And code proposal a few posts further down.

If you make the change to the code in your local files, you could test and if it works submit a pull request. rmrector is pretty busy these days, so I am sure he will appreciate the help.
as i post 2 posts below, i hope  my code works with imdb number (with the restrictition of the date position)
if you want the tmbd number working the same way 
try to add in   addons\metadata.themoviedb.org.python\python\lib\tmdbscraper\tmdb.py  
python:
def _parse_media_id(title):
    m=re.search(r"(tt\d+)",title)
    if m: return {'type': 'imdb', 'id':m.group()}
   m=re.search(r"tmdb[\/#](\d+)",title)                 #work with tmdb/number and tmdb#number
    if m: return {'type': tmdb', 'id':m.group()}
368312 (thread)

this works (i hope) with tmdb python scraper and this code will be erase when this scaper will be update by kodi updater addon
soooo great ... I will test that asap.

if this works as I think it will, I will finally have THE ultimate solution for movie scrapping ! ... perfect, ty for the help.

Thanks to everyone  Cool
Z3b
python:
def _parse_media_id(title):
m=re.search(r"(tt\d+)",title)
if m: return {'type': 'imdb', 'id':m.group()}
m=re.search(r"tmdb[\/#](\d+)",title) #work with tmdb/number and tmdb#number
if m: return {'type': 'tmdb', 'id':m.group()[5:]}
return None

fix : with tmdb, 'id' should only contain the id ...
( am I wrong ? )
have you try ?
with m=re.search(r"tmdb[\/#](\d+)",title)     m.group() return the numbers only.
(2022-05-30, 11:59)michelb2 Wrote: [ -> ]have you try ?
with m=re.search(r"tmdb[\/#](\d+)",title)     m.group() return the numbers only.

I have just test it in python online sandbox and it return the whole pattern ... but you are right : it should not ... Huh

https://pythonsandbox.com/code/pythonsan...jRUM_v0.py
Dixit python doc :
.group()
returns the part of the string where there was a match

So ...
(Yes, i'm pure newbie to python ... 😁)
(2022-05-30, 14:03)Z3b2G Wrote: [ -> ](Yes, i'm pure newbie to python ... 😁)

I'm no developer either, but make sure you are using Python-3 compatible syntax. Python-2 is EOL.
ok i try inside kodi200 , i agree with you
m=re.search(r"tmdb[\/#](\d+)",title)
if m: return {'type': 'tmdb', 'id':m.group()[5:]}   is the good syntax

m=re.search(r"tmdb[\/#](\d+)",title)
if m: return {'type': 'tmdb', 'id':m.group(1)}  is a good synax also

(by i am not a python developper either)

m.group() return the whole match
m.group(1) return the first group match inside ()
Quote:Match.group([group1, ...])
Returns one or more subgroups of the match. If there is a single argument, the result is a single string; if there are multiple arguments, the result is a tuple with one item per argument. Without arguments, group1 defaults to zero (the whole match is returned). If a groupN argument is zero, the corresponding return value is the entire matching string; if it is in the inclusive range [1..99], it is the string matching the corresponding parenthesized group. If a group number is negative or larger than the number of groups defined in the pattern, an IndexError exception is raised. If a group is contained in a part of the pattern that did not match, the corresponding result is None. If a group is contained in a part of the pattern that matched multiple times, the last match is returned.
ok, so we are noobs ... but we done it !

python:
if m: return {'type': 'tmdb', 'id':m.group(1)}
is far better imo.

I will test that soon, you already test ?

bye.
Pages: 1 2