create IMDB link file in the media folder

If you need help on how to use the program
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

create IMDB link file in the media folder

Post by rs232 »

It appear like the trend is to put a link to the IMDB page within the same directory where the media file is located. I always appreciated this option as there are more and more movies out there and titles began to overlap!

I'm doing the media import of most of my videos and I'm script/importing one by one (to avid mistakes!) data from IMDB. BTW the IMDB script is excellent but it can not be left unattended!
So, cutting a long story short I was wondering how difficult would it be for AMC to get the value in the URL field (if any) and create a simple internet shortcut file (pretty much an http link) within the same directory.

Why?
1) As mentioned it appears to have become a standard to have this link

2) Software independent way to uniquely and precisely identify the movie

3) if I mess up my database I could ask the AMC/IMDB script to look for this http link. Querying IMDB by URL this doesn't involve any mistake nor input from the user and a full database re-import can be done automatically and totally painless

4) Simply copying the folder (e.g. to a friend USB pen drive ) will keep the unique reference.

Much appreciated!
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Hi,

I understand and it is a good idea.
For now, you can't create Windows link with scripts but you can create an html file that redirect to IMDB link.

EDIT : Now we create or recreate the link only if url is not empty.
If url is empty and html link exists, we remove it.

I give you the code bellow :

Code: Select all

program CreateHtmlLinkIntoMediaFolder;
uses
  FieldsUtils;
var
  outToFile: TStringList;
  data, ext, url, fullPathFile, fullPathLink: string;
  fieldIdxUrl, fieldIdxFullPath: Integer;
begin
  {field where the URL is stored (as IMDB link)}
  fieldIdxUrl := fieldUrl;
  //fieldIdxUrl := GetFieldOrCustomFieldIdx('AFieldTagOrACustomFieldTag');

  {field where the full path of video file is stored}
  fieldIdxFullPath := fieldSource;
  //fieldIdxFullPath := GetFieldOrCustomFieldIdx('AFieldTagOrACustomFieldTag');

  {extension of html link}
  ext := '.html';

  fullPathFile := GetFieldOrCustomField(fieldIdxFullPath);
  if FileExists(fullPathFile) then
  begin
    fullPathLink := ChangeFileExt(fullPathFile, ext);
    // check to not delete video file in case of fullPathLink = fullPathFile !
    if fullPathLink <> fullPathFile then
    begin
      url := GetFieldOrCustomField(fieldIdxUrl);
      if (url <> '') then // we create or recreate html link
      begin
        data := '';
        data := data + '<html>' + #13#10;
        data := data + '  <head>' + #13#10;
        data := data + '    <meta http-equiv="Refresh" content="0;URL=''';
        data := data + GetFieldOrCustomField(fieldIdxURL);
        data := data + '''">' + #13#10;
        data := data + '  <body></body>' + #13#10;
        data := data + '</html>';

        outToFile := TStringList.Create;
        outToFile.Append(UTF8Encode(data));
        outToFile.SaveToFile(fullPathLink);
        outToFile.Free;
      end
      else // we delete html link
      begin
        if FileExists(fullPathLink) then
          DeleteFile(fullPathLink);
      end;
    end;
  end;
end.
Soulsnake.
Last edited by soulsnake on 2012-08-10 07:47:23, edited 2 times in total.
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

It would be as easy to create a web link since a .url file shortcut to a website is just a text file:

Code: Select all

[InternetShortcut]
URL=http://...
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Yes you are right !

EDIT : Now we create or recreate the link only if url is not empty.
If url is empty and url link exists, we remove it.

I give the new code bellow :

Code: Select all

program CreateUrlLinkIntoMediaFolder;
uses
  FieldsUtils;
var
  outToFile: TStringList;
  data, ext, url, fullPathFile, fullPathLink: string;
  fieldIdxUrl, fieldIdxFullPath: Integer;
begin
  {field where the URL is stored (as IMDB link)}
  fieldIdxUrl := fieldUrl;
  //fieldIdxUrl := GetFieldOrCustomFieldIdx('AFieldTagOrACustomFieldTag');

  {field where the full path of video file is stored}
  fieldIdxFullPath := fieldSource;
  //fieldIdxFullPath := GetFieldOrCustomFieldIdx('AFieldTagOrACustomFieldTag');

  {extension of url link}
  ext := '.url';

  fullPathFile := GetFieldOrCustomField(fieldIdxFullPath);
  if FileExists(fullPathFile) then
  begin
    fullPathLink := ChangeFileExt(fullPathFile, ext);
    // check to not delete video file in case of fullPathLink = fullPathFile !
    if fullPathLink <> fullPathFile then
    begin
      url := GetFieldOrCustomField(fieldIdxUrl);
      if (url <> '') then // we create or recreate url link
      begin
        data := '[InternetShortcut] ' + #13#10;
        data := data + 'URL=' + url;

        outToFile := TStringList.Create;
        outToFile.Append(UTF8Encode(data));
        outToFile.SaveToFile(fullPathLink);
        outToFile.Free;
      end
      else // we delete url link
      begin
        if FileExists(fullPathLink) then
          DeleteFile(fullPathLink);
      end;
    end;
  end;
end.
Last edited by soulsnake on 2012-08-09 10:29:39, edited 2 times in total.
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

Brilliant! before I try it though:
I can see that you get the URL and refer to the fiedSource

In my column definition source holds the fullpath of the media file + filename
I think I'll import the path into the Borrower field for the time being and see how it goes.

#########

If you think this is the way to go (having a URL file in the dir and a custom script that generates it) I think we should have FieldFilename and FieldPath as standard fields.

I know I can do this with custom fields, but I'm just thinking about other users, and what it sounds like a common topic. This open up a "politic" point of view:

At the end of the day it seems to me that this software is so powerful and flexible that adding functionality is actually a lower priority compared to the need to standardise (among users) the way data is organised. Not sure everybody here agrees with me but I strongly believe in this point.

I'm going through all this because I've found my personal way to sort things out, and I'm for the freedom of choice! However in this specific case I really wouldn't mind somebody (the software) somehow imposing a "best practice" of the "do & don't" when it comes to organise stuff, and related to this specific post the schema to be used.
Then if somebody has special needs can destroy and create their own schema of course.

If you're still awake :hihi: I'm just suggesting to have filename and path field in the default schema

#########

My brain naturally points to future topics/problems and if we relay on the Source/path absolute information, we will need a function to batch modify these fields it in case the media is moved to a different storage/path. Very low priority but I'm sure we'll run into this issue at some point.

#########

my 2 cents

Many thanks again for the excellent support!
:)
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

In my column definition source holds the fullpath of the media file + filename
I think I'll import the path into the Borrower field for the time being and see how it goes.
I don't know if you understand well but when I say fullpath for me is path + filename ;).

I know we should add a new field for file location (path + filename) as field URL.
This will be added in next major release (4.2.x) ;).

Soulsnake.
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

I can confirm that it's working very well using the source (path+filename) field!

:)
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

Actually just two thing:
1) if the URL field is empty the script should not create the link...
2) he file must be recreated every time the script is run

Think about this scenario: I run the script and some of the movies don't have the URL field. Right now the internetlink file is still created with an empty reference. If I then add a URL the script seems to recognise an existing link and just skip the record.

Thanks!
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Hi,

I change the original code above !

Now we create or recreate the link only if url is not empty.
If url is empty and url link exists, we remove it.

Soulsnake.
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

Cool, I'm testing it.

I definitely can see the modification date of the file changing when I run the script! But I've found a rather odd problem...

I'm on windows7 and data is stored in a SMB share pointing to a NAS.

Basically what's happening now is: all the files created have extension .url, but some... have for some strange reason a different icon. They contain exactly the same thing:

[InternetShortcut]
URL=http://imdb.com/title/whatevernumber

BUT looking into the file properties some have the "web document" tab, others now. The one that have the web document when double clicked open the webpage with the IMDB reference, the ones without web document tab respond with a warning pop up saying:

Code: Select all

The target "" of this Internet Shortcut is not valid. Go to the Internet Shortcut property sheet and make sure the target is correct.
Also, if I delete the url file they are recreated exactly as they were before, the ones with web document tab will still have it, the one without web document tab still without.

NOTE: directory names and charset here have no implication here as they are plain ASCII withour dodgy characters.

I'm really puzzled about this :/
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

still investigating...

In the filetype not working if I manually add .url at the end of the file it then works (web documents) property available and double click opens the page.

This is very odd as if I check the file extension on the NAS (using linux bash) the file is indeed created with extension .url, however windows sees only the filename.

NOTE: I do display file extensions in windows e.g. the media file is called mymovie.avi
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Do you see this thread ?

http://support.microsoft.com/kb/936881

Maybe this fix the problem ?

Soulsnake.
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

That is for vista and IE 7 I'm on win7 with IE9 (not that I'm using it).
But I think you got the point, this appears to be an OS problem and not related to AMC at all.


thanks!
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Maybe more data are needed.
In Vista a shortcut gets this contents:

Code: Select all

[InternetShortcut]
URL=http://...
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
I thought that only URL was useful, maybe it needs the other stuff too
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

I'm not sure but to me one movie has a perfectly working link, where another movie in the very same share (different subfolder) has the wring url file.

Also I've tried to opening the very same share/folder from another computer and there it works instead.
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Maybe this work better.
Now we create a .tmp file, we add the content to this file and we rename it to .url.

I give the code bellow :

Code: Select all

program CreateUrlLinkIntoMediaFolder;
uses
  FieldsUtils;
var
  outToFile: TStringList;
  data, url, ext, extTmp, fullPathFile, fullPathLink, fullPathTmp: string;
  fieldIdxUrl, fieldIdxFullPath: Integer;
begin
  {field where the URL is stored (as IMDB link)}
  fieldIdxUrl := fieldUrl;
  //fieldIdxUrl := GetFieldOrCustomFieldIdx('AFieldTagOrACustomFieldTag');

  {field where the full path of video file is stored}
  fieldIdxFullPath := fieldSource;
  //fieldIdxFullPath := GetFieldOrCustomFieldIdx('AFieldTagOrACustomFieldTag');

  {extension of url link}
  ext := '.url';
  extTmp := '.tmp';

  fullPathFile := GetFieldOrCustomField(fieldIdxFullPath);
  if FileExists(fullPathFile) then
  begin
    fullPathLink := ChangeFileExt(fullPathFile, ext);
    fullPathTmp := ChangeFileExt(fullPathFile, extTmp);
    // check to not delete video file in case of fullPathLink = fullPathFile !
    if (fullPathLink <> fullPathFile) and (fullPathTmp <> fullPathFile) then
    begin
      url := GetFieldOrCustomField(fieldIdxUrl);
      if FileExists(fullPathLink) then // we delete url link
        DeleteFile(fullPathLink);
      if (url <> '') then // we create url link
      begin
        data := '[InternetShortcut] ' + #13#10;
        data := data + 'URL=' + url;

        outToFile := TStringList.Create;
        outToFile.Append(UTF8Encode(data));
        outToFile.SaveToFile(fullPathTmp);
        outToFile.Free;
        
        MoveFile(fullPathTmp, fullPathLink);
      end;
    end;
  end;
end.
EDIT: Windows seems to not refresh Web Document Tab even when you delete the link and you recreate it. It is always the old link...
You have to change yourself the link in properties... Not good ! :/
Finally create a .html link it is easier and it works better.
I have updated the script on the first post (html link version).

Soulsnake.
Last edited by soulsnake on 2012-08-10 11:59:26, edited 1 time in total.
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

may be it's me but this latest version doesn't seem to create the file
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

For me it works even if "Web Document" tab is never updated and I don't know why !?

Soulsnake.
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

Just re-tried and now it works, i guess i wasn't doing things properly myself.

I've noticed that the file is now .html.

Don't get me wrong it works double clicking on it! However if my memory serves me well what I have seen around (still referring to standards) it's a .url file as per initial script.

I believe that initial script actually worked fine and it's just a Windows thing to interpret it or not. So if you ask me I would just revert it to the .url version.

I mean, having the link in the directory is the highest priority, then if double clicking works better, if not... never mind as long as we can get data out of it.

Finally a routine to get the file URL content (if any) during the import process and put in in the URL field would be the perfect closure of a circle :-)
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

One torrent I found today had the .url file insider (as per first attempt).

Code: Select all

[InternetShortcut]
URL=http://www.imdb.com/title/tt1XXXXXX/
I'm pretty sure this is irrelevant but the extension is uppercase and my windows 7 sees the link of this downloaded file properly.

We all know windows is not case sensitive, but at this point I would try anything...

I would personally stick to .url (second version of the script posted)

Many thanks!!!
Last edited by rs232 on 2012-08-11 08:11:12, edited 1 time in total.
Post Reply